Skip to content

Commit e867cc3

Browse files
committed
Updated README
- With Call Examples - With Application Examples
1 parent e5b3b41 commit e867cc3

File tree

1 file changed

+124
-4
lines changed

1 file changed

+124
-4
lines changed

README.md

Lines changed: 124 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,126 @@ $verification = new \Nexmo\Verify\Verification('00e6c3377e5348cdaf567e1417c707a5
219219
$client->verify()->search($verification);
220220
echo "Verification cost was: " . $verification['price'] . PHP_EOL;
221221
```
222+
223+
### Making A Call
224+
225+
All `$client->calls()` methods require the client to be constructed with a `Nexmo\Client\Credentials\Keypair`, or a
226+
`Nexmo\Client\Credentials\Container` that includes the `Keypair` credentials:
227+
228+
```php
229+
$basic = new \Nexmo\Client\Credentials\Basic('key', 'secret');
230+
$keypair = new \Nexmo\Client\Credentials\Keypair(file_get_contents(__DIR__ . '/application.key'), 'application_id');
231+
232+
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic, $keypair));
233+
```
234+
235+
You can start a call using an array as the structure:
236+
237+
```php
238+
$client->calls()->create([
239+
'to' => [[
240+
'type' => 'phone',
241+
'number' => '14843331234'
242+
]],
243+
'from' => [
244+
'type' => 'phone',
245+
'number' => '14843335555'
246+
],
247+
'answer_url' => ['https://example.com/answer'],
248+
'event_url' => ['https://example.com/event'],
249+
]);
250+
```
251+
252+
Or you can create a `Nexmo\Calls\Call` object, and use that:
253+
254+
```php
255+
use Nexmo\Calls\Call;
256+
$call = new Call();
257+
$call->setTo('14843331234')
258+
->setFrom('14843335555')
259+
->setWebhook(Call::WEBHOOK_ANSWER, 'https://example.com/answer')
260+
->setWebhook(Call::WEBHOOK_EVENT, 'https://example.com/event');
261+
262+
$client->calls()->create($call);
263+
```
264+
265+
### Fetching A Call
266+
267+
You can fetch a call using a `Nexmo\Calls\Call` object, or the call's UUID as a string:
268+
269+
```php
270+
$call = $client->calls()->get('3fd4d839-493e-4485-b2a5-ace527aacff3');
271+
272+
$call = new Nexmo\Calls\Call('3fd4d839-493e-4485-b2a5-ace527aacff3');
273+
$client->calls()->get($call);
274+
275+
echo $call->getDirection();
276+
```
277+
278+
### Creating An Application
279+
280+
Application are configuration containers, and you can create one using a simple array structure:
281+
282+
```php
283+
$application = $client->applications()->create([
284+
'name' => 'My Application',
285+
'answer_url' => 'https://example.com/answer',
286+
'event_url' => 'https://example.com/event'
287+
])
288+
```
289+
290+
You can also pass the client an application object:
291+
292+
```php
293+
$application = new Nexmo\Application\Application();
294+
$application->setName('My Application');
295+
$application->getVoiceConfig()->setWebhook(VoiceConfig::ANSWER, 'https://example.com/answer');
296+
$application->getVoiceConfig()->setWebhook(VoiceConfig::EVENT, 'https://example.com/event');
297+
298+
$client->appliations()->create($application);
299+
```
300+
301+
### Fetching Applications
302+
303+
You can iterate over all your applications:
304+
305+
```php
306+
foreach($client->applications() as $application){
307+
echo $application->getName() . PHP_EOL;
308+
}
309+
```
310+
311+
Or you can fetch an application using a string UUID, or an application object.
312+
313+
```php
314+
$application = $client->applications()->get('1a20a124-1775-412b-b623-e6985f4aace0');
315+
316+
$application = new Application('1a20a124-1775-412b-b623-e6985f4aace0');
317+
$client->applications()->get($application);
318+
```
319+
320+
### Updating an Application
321+
322+
Once you have an application object, you can modify and save it.
323+
324+
```php
325+
$application = $client->applications()->get('1a20a124-1775-412b-b623-e6985f4aace0');
326+
327+
$application->setName('Updated Application');
328+
$client->applications()->update($application);
329+
```
330+
331+
You can also pass an array and the application UUID to the client:
332+
333+
```php
334+
$application = $client->applications()->update([
335+
'name' => 'Updated Application',
336+
'answer_url' => 'https://example.com/v2/answer',
337+
'event_url' => 'https://example.com/v2/event'
338+
], '1a20a124-1775-412b-b623-e6985f4aace0');
339+
```
340+
341+
222342

223343
API Coverage
224344
------------
@@ -228,11 +348,11 @@ API Coverage
228348
* [ ] Pricing
229349
* [ ] Settings
230350
* [ ] Top Up
231-
* [ ] Numbers
232-
* [ ] Search
351+
* [X] Numbers
352+
* [X] Search
233353
* [ ] Buy
234354
* [ ] Cancel
235-
* [ ] Update
355+
* [X] Update
236356
* Number Insight
237357
* [ ] Basic
238358
* [ ] Standard
@@ -257,7 +377,7 @@ API Coverage
257377
* [ ] Sending Alerts
258378
* [ ] Campaign Subscription Management
259379
* Voice
260-
* [ ] Outbound Calls
380+
* [X] Outbound Calls
261381
* [ ] Inbound Call
262382
* [ ] Text-To-Speech Call
263383
* [ ] Text-To-Speech Prompt

0 commit comments

Comments
 (0)