Skip to content

Commit 042088d

Browse files
committed
Updated examples to use 'use' statements
1 parent 053b0e5 commit 042088d

File tree

8 files changed

+51
-29
lines changed

8 files changed

+51
-29
lines changed

examples/create-application.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<?php
22

3+
use Nexmo\Client;
4+
use Nexmo\Application\Application;
5+
36
require_once '../vendor/autoload.php';
47

5-
$client = new Nexmo\Client(new Nexmo\Client\Credentials\Basic(API_KEY, API_SECRET));
8+
$client = new Client(new Nexmo\Client\Credentials\Basic(API_KEY, API_SECRET));
69

7-
$a = new Nexmo\Application\Application;
10+
$a = new Application();
811

912
$a->setName('PHP Client Example');
1013
$a->getVoiceConfig()->setWebhook('answer_url', 'https://example.com/answer', 'GET');

examples/delete-application.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
<?php
22

3+
use Nexmo\Client;
4+
35
require_once '../vendor/autoload.php';
46

5-
$client = new Nexmo\Client(new Nexmo\Client\Credentials\Basic(API_KEY, API_SECRET));
7+
$client = new Client(new Nexmo\Client\Credentials\Basic(API_KEY, API_SECRET));
68

79
try {
8-
$isDeleted = $client->applications()->delete(MESSAGES_APPLICATION_ID);
9-
10-
if ($isDeleted) {
11-
echo "Deleted application " . MESSAGES_APPLICATION_ID . PHP_EOL;
12-
} else {
13-
echo "Could not delete application " . MESSAGES_APPLICATION_ID . PHP_EOL;
14-
}
10+
$client->applications()->delete(MESSAGES_APPLICATION_ID);
11+
echo "Deleted application " . MESSAGES_APPLICATION_ID . PHP_EOL;
1512
} catch (\Nexmo\Client\Exception\Request $e) {
1613
echo "There was a problem with the request: " . $e->getMessage() . PHP_EOL;
1714
} catch (\Nexmo\Client\Exception\Server $e) {
1815
echo "The server encounted an error: " . $e->getMessage() . PHP_EOL;
1916
}
20-

examples/fetch_recording.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<?php
22

3+
use Nexmo\Client;
4+
use Nexmo\Client\Credentials\Keypair;
5+
36
require_once "vendor/autoload.php";
47

58
$recordingId = 'RECORDING_ID';
69

7-
$keypair = new \Nexmo\Client\Credentials\Keypair(file_get_contents(__DIR__ . '/private.key'), 'APPLICATION_ID');
8-
$client = new \Nexmo\Client($keypair);
10+
$keypair = new Keypair(file_get_contents(__DIR__ . '/private.key'), 'APPLICATION_ID');
11+
$client = new Client($keypair);
912
$recording = 'https://api.nexmo.com/v1/files/'.$recordingId;
1013
$data = $client->get($recording);
1114

examples/get-application.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<?php
2+
3+
use Nexmo\Client;
4+
25
require_once '../vendor/autoload.php';
36

4-
$client = new Nexmo\Client(new Nexmo\Client\Credentials\Basic(API_KEY, API_SECRET));
7+
$client = new Client(new Nexmo\Client\Credentials\Basic(API_KEY, API_SECRET));
58

69
$a = $client->applications()->get(APPLICATION_ID);
710
echo $a->getName().PHP_EOL;

examples/list-applications.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<?php
2+
3+
use Nexmo\Client;
4+
25
require_once '../vendor/autoload.php';
36

4-
$client = new Nexmo\Client(new Nexmo\Client\Credentials\Basic(API_KEY, API_SECRET));
7+
$client = new Client(new Nexmo\Client\Credentials\Basic(API_KEY, API_SECRET));
58

69
foreach ($client->applications() as $application) {
710
echo sprintf("%s: %s\n", $application->getId(), $application->getName());

examples/make-call-ncco.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
<?php
2+
3+
use Nexmo\Client;
4+
use Nexmo\Voice\Webhook;
5+
use Nexmo\Voice\OutboundCall;
6+
use Nexmo\Voice\Endpoint\Phone;
7+
use Nexmo\Client\Credentials\Keypair;
8+
29
require_once '../vendor/autoload.php';
310

4-
$keypair = new \Nexmo\Client\Credentials\Keypair(
11+
$keypair = new Keypair(
512
file_get_contents(NEXMO_APPLICATION_PRIVATE_KEY_PATH),
613
NEXMO_APPLICATION_ID
714
);
8-
$client = new \Nexmo\Client($keypair);
15+
$client = new Client($keypair);
916

10-
$outboundCall = new \Nexmo\Voice\OutboundCall(
11-
new \Nexmo\Voice\Endpoint\Phone(TO_NUMBER),
12-
new \Nexmo\Voice\Endpoint\Phone(NEXMO_NUMBER)
17+
$outboundCall = new OutboundCall(
18+
new Phone(TO_NUMBER),
19+
new Phone(NEXMO_NUMBER)
1320
);
1421
$outboundCall->setAnswerWebhook(
15-
new \Nexmo\Voice\Webhook(
22+
new Webhook(
1623
'https://developer.nexmo.com/ncco/tts.json',
17-
\Nexmo\Voice\Webhook::METHOD_GET
24+
Webhook::METHOD_GET
1825
)
1926
);
2027
$response = $client->voice()->createOutboundCall($outboundCall);

examples/send.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<?php
2+
3+
use Nexmo\Client;
4+
use Nexmo\SMS\Message\SMS;
5+
use Nexmo\Client\Exception\Request;
6+
27
//example of sending an sms using an API key / secret
38
require_once '../vendor/autoload.php';
49

@@ -8,11 +13,11 @@
813
define('NEXMO_FROM', getenv('NEXMO_FROM'));
914

1015
//create client with api key and secret
11-
$client = new \Nexmo\Client(new Nexmo\Client\Credentials\Basic(API_KEY, API_SECRET));
16+
$client = new Client(new Nexmo\Client\Credentials\Basic(API_KEY, API_SECRET));
1217

1318
//send message using simple api params
1419
$response = $client->sms()->send(
15-
new \Nexmo\SMS\Message\SMS(NEXMO_TO, NEXMO_FROM, 'Test message from the Nexmo PHP Client')
20+
new SMS(NEXMO_TO, NEXMO_FROM, 'Test message from the Nexmo PHP Client')
1621
);
1722

1823
//array access provides response data
@@ -30,7 +35,7 @@
3035
That thou, her maid, art far more fair than she.
3136
EOF;
3237

33-
$text = new \Nexmo\SMS\Message\SMS(NEXMO_TO, NEXMO_FROM, $longwinded);
38+
$text = new SMS(NEXMO_TO, NEXMO_FROM, $longwinded);
3439
$response = $client->sms()->send($text);
3540
$data = $response->current();
3641

@@ -42,9 +47,9 @@
4247

4348
//an invalid request
4449
try {
45-
$text = new \Nexmo\SMS\Message\SMS('not valid', NEXMO_FROM, $longwinded);
50+
$text = new SMS('not valid', NEXMO_FROM, $longwinded);
4651
$client->sms()->send($text);
47-
} catch (Nexmo\Client\Exception\Request $e) {
52+
} catch (Request $e) {
4853
//can still get the API response
4954
$data = $e->getEntity(); // The parsed response as an array
5055
$request = $client->sms()->getAPIResource()->getLastRequest(); //PSR-7 Request Object

examples/update-application.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
22

3+
use Nexmo\Client;
4+
35
require_once '../vendor/autoload.php';
46

5-
$client = new Nexmo\Client(new Nexmo\Client\Credentials\Basic('7c9738e6', 'n3w-Api-key!'));
7+
$client = new Client(new Nexmo\Client\Credentials\Basic(API_KEY, API_SECRET));
68

7-
$a = $client->applications()->get('a8f93ca3-2a6f-4722-a53e-b7cccabc0bb9');
9+
$a = $client->applications()->get(APPLICATION_ID);
810

911
$a->getVoiceConfig()->setWebhook('answer_url', 'https://example.com/answer', 'GET');
1012
$a->getVoiceConfig()->setWebhook('event_url', 'https://example.com/event', 'POST');

0 commit comments

Comments
 (0)