@@ -18,23 +18,31 @@ To use the client library you'll need to have [created a Nexmo account][signup].
1818
1919To install the PHP client library using Composer:
2020
21- composer require nexmo/client
21+ ``` bash
22+ composer require nexmo/client
23+ ```
2224
2325Alternatively you can clone the repository, however, you'll need to ensure the library is autoloaded by a PSR-0 or PSR-4
2426compatible autoloader.
2527
26- git clone [email protected] :Nexmo/nexmo-php.git 28+ ``` bash
29+ git clone
[email protected] :Nexmo/nexmo-php.git
30+ ```
2731
2832Usage
2933-----
3034
3135If you're using composer, make sure the autoloader is included in your project's bootstrap file:
3236
33- require_once "vendor/autoload.php";
37+ ``` php
38+ require_once "vendor/autoload.php";
39+ ```
3440
3541Create a client with your API key and secret:
3642
37- $client = new Nexmo\Client(new Nexmo\Credentials\Basic(API_KEY, API_SECRET));
43+ ``` php
44+ $client = new Nexmo\Client(new Nexmo\Credentials\Basic(API_KEY, API_SECRET));
45+ ```
3846
3947Examples
4048--------
@@ -45,43 +53,57 @@ To use [Nexmo's SMS API][doc_sms] to send an SMS message, call the `$client->mes
4553
4654The API can be called directly, using a simple array of parameters, the keys match the [ parameters of the API] [ doc_sms ] .
4755
48- $message = $client->message()->send([
49- 'to' => NEXMO_TO,
50- 'from' => NEXMO_FROM,
51- 'text' => 'Test message from the Nexmo PHP Client'
52- ]);
56+ ``` php
57+ $message = $client->message()->send([
58+ 'to' => NEXMO_TO,
59+ 'from' => NEXMO_FROM,
60+ 'text' => 'Test message from the Nexmo PHP Client'
61+ ]);
62+ ```
5363
5464The API response data can be accessed as array properties of the message.
5565
56- echo "Sent message to " . $message['to'] . ". Balance is now " . $message['remaining-balance'] . PHP_EOL;
66+ ``` php
67+ echo "Sent message to " . $message['to'] . ". Balance is now " . $message['remaining-balance'] . PHP_EOL;
68+ ```
5769
5870** A message object** is a more expressive way to create and send messages. Each message type can be constructed with the
5971required parameters, and a fluent interface provides access to optional parameters.
6072
61- $text = new \Nexmo\Message\Text(NEXMO_TO, NEXMO_FROM, 'Test message using PHP client library');
62- $text->setClientRef('test-message')
63- ->setClass(\Nexmo\Message\Text::CLASS_FLASH);
73+ ``` php
74+ $text = new \Nexmo\Message\Text(NEXMO_TO, NEXMO_FROM, 'Test message using PHP client library');
75+ $text->setClientRef('test-message')
76+ ->setClass(\Nexmo\Message\Text::CLASS_FLASH);
77+ ```
6478
6579The message object is passed to the same ` send ` method:
6680
67- $client->message()->send($text);
81+ ``` php
82+ $client->message()->send($text);
83+ ```
6884
6985Once sent, the message object can be used to access the response data.
7086
71- echo "Sent message to " . $text->getTo() . ". Balance is now " . $text->getRemainingBalance() . PHP_EOL;
87+ ``` php
88+ echo "Sent message to " . $text->getTo() . ". Balance is now " . $text->getRemainingBalance() . PHP_EOL;
89+ ```
7290
7391Array access can still be used:
7492
75- echo "Sent message to " . $text['to'] . ". Balance is now " . $text['remaining-balance'] . PHP_EOL;
93+ ``` php
94+ echo "Sent message to " . $text['to'] . ". Balance is now " . $text['remaining-balance'] . PHP_EOL;
95+ ```
7696
7797If the message text had to be sent as multiple messages, by default, the data of the last message is returned. However,
7898specific message data can be accessed using array notation, passing an index to a getter, or iterating over the object.
7999
80- $text[0]['remaining-balance']
81- $text->getRemainingBalance(0);
82- foreach($text as $index => $data){
83- $data['remaining-balance'];
84- }
100+ ``` php
101+ $text[0]['remaining-balance']
102+ $text->getRemainingBalance(0);
103+ foreach($text as $index => $data){
104+ $data['remaining-balance'];
105+ }
106+ ```
85107
86108The [ send example] [ send_example ] also has full working examples.
87109
@@ -90,32 +112,40 @@ The [send example][send_example] also has full working examples.
90112Inbound messages are [ sent to your application as a webhook] [ doc_inbound ] , and the client library provides a way to
91113create an inbound message object from a webhook:
92114
93- $inbound = \Nexmo\Message\InboundMessage::createFromGlobals();
94- if($inbound->isValid()){
95- error_log($inbound->getBody());
96- } else {
97- error_log('invalid message');
98- }
115+ ``` php
116+ $inbound = \Nexmo\Message\InboundMessage::createFromGlobals();
117+ if($inbound->isValid()){
118+ error_log($inbound->getBody());
119+ } else {
120+ error_log('invalid message');
121+ }
122+ ```
99123
100124You can also access the webhook data as an arry:
101125
102- $inbound = \Nexmo\Message\InboundMessage::createFromGlobals();
103- error_log($inbound['to']);
126+ ``` php
127+ $inbound = \Nexmo\Message\InboundMessage::createFromGlobals();
128+ error_log($inbound['to']);
129+ ```
104130
105131### Fetching A Message
106132
107133You can retrieve a message log from the API using the ID of the message:
108134
109- $message = $client->message()->search('02000000DA7C52E7');
110- echo "The body of the message was: " . $message->getBody();
135+ ``` php
136+ $message = $client->message()->search('02000000DA7C52E7');
137+ echo "The body of the message was: " . $message->getBody();
138+ ```
111139
112140If the message was sent to a Nexmo virtual number, the object will be an instance of ` Nexmo\Message\InboundMessage ` , if
113141the message was sent from your account, it will be an instance of ` Nexmo\Message\Message ` . You can also pass a message
114142object to the client:
115143
116- $message = new \Nexmo\Message\InboundMessage('02000000DA7C52E7');
117- $client->message()->search($message);
118- echo "The body of the message was: " . $message->getBody();
144+ ``` php
145+ $message = new \Nexmo\Message\InboundMessage('02000000DA7C52E7');
146+ $client->message()->search($message);
147+ echo "The body of the message was: " . $message->getBody();
148+ ```
119149
120150### Starting a Verification
121151
@@ -124,57 +154,71 @@ or implement second factor authentication during signin.
124154
125155You can start a verification process using a simple array:
126156
127- $verification = $client->verify()->start([
128- 'number' => '14845551212',
129- 'brand' => 'My App'
130- ]);
131- echo "Started verification with an id of: " . $verification->getRequestId();
157+ ``` php
158+ $verification = $client->verify()->start([
159+ 'number' => '14845551212',
160+ 'brand' => 'My App'
161+ ]);
162+ echo "Started verification with an id of: " . $verification->getRequestId();
163+ ```
132164
133165Or you can pass the client a verification object:
134166
135- $verification = new \Nexmo\Verify\Verification('14845551212', 'My App');
136- $client->verify()->start($verification);
137- echo "Started verification with an id of: " . $verification->getRequestId();
167+ ``` php
168+ $verification = new \Nexmo\Verify\Verification('14845551212', 'My App');
169+ $client->verify()->start($verification);
170+ echo "Started verification with an id of: " . $verification->getRequestId();
171+ ```
138172
139173### Controlling a Verification
140174
141175To cancel an in-progress verification, or to trigger the next attempt to send the confirmation code, you can pass
142176either an exsisting verification object to the client library, or simply use a request ID:
143177
144- $client->verify()->trigger('00e6c3377e5348cdaf567e1417c707a5');
145-
146- $verification = new \Nexmo\Verify\Verification('00e6c3377e5348cdaf567e1417c707a5');
147- $client->verify()->cancel($verification);
178+ ``` php
179+ $client->verify()->trigger('00e6c3377e5348cdaf567e1417c707a5');
180+
181+ $verification = new \Nexmo\Verify\Verification('00e6c3377e5348cdaf567e1417c707a5');
182+ $client->verify()->cancel($verification);
183+ ```
148184
149185### Checking A Verification
150186
151187In the same way, checking a verification requires the code the user provided, and an exiting verification object:
152188
153- $verification = new \Nexmo\Verify\Verification('00e6c3377e5348cdaf567e1417c707a5');
154- $client->verify()->check($verification, '1234');
189+ ``` php
190+ $verification = new \Nexmo\Verify\Verification('00e6c3377e5348cdaf567e1417c707a5');
191+ $client->verify()->check($verification, '1234');
192+ ```
155193
156194Or a request ID:
157195
158- $client->verify()->check('00e6c3377e5348cdaf567e1417c707a5', '1234');
196+ ``` php
197+ $client->verify()->check('00e6c3377e5348cdaf567e1417c707a5', '1234');
198+ ```
159199
160200### Searching For A Verification
161201
162202You can check the status of a verification, or access the results of past verifications using either an exsisting
163203verification object, or a request ID. The verification object will then provide a rich interface:
164204
165- $verification = new \Nexmo\Verify\Verification('00e6c3377e5348cdaf567e1417c707a5');
166- $client->verify()->search($verification);
167-
168- echo "Codes checked for verification: " . $verification->getRequestId() . PHP_EOL;
169- foreach($verification->getChecks() as $check){
170- echo $check->getDate()->format('d-m-y') . ' ' . $check->getStatus() . PHP_EOL;
171- }
205+ ``` php
206+ $verification = new \Nexmo\Verify\Verification('00e6c3377e5348cdaf567e1417c707a5');
207+ $client->verify()->search($verification);
208+
209+ echo "Codes checked for verification: " . $verification->getRequestId() . PHP_EOL;
210+ foreach($verification->getChecks() as $check){
211+ echo $check->getDate()->format('d-m-y') . ' ' . $check->getStatus() . PHP_EOL;
212+ }
213+ ```
172214
173215You can also access the raw API response here using array access:
174216
175- $verification = new \Nexmo\Verify\Verification('00e6c3377e5348cdaf567e1417c707a5');
176- $client->verify()->search($verification);
177- echo "Verification cost was: " . $verification['price'] . PHP_EOL;
217+ ``` php
218+ $verification = new \Nexmo\Verify\Verification('00e6c3377e5348cdaf567e1417c707a5');
219+ $client->verify()->search($verification);
220+ echo "Verification cost was: " . $verification['price'] . PHP_EOL;
221+ ```
178222
179223API Coverage
180224------------
0 commit comments