|
1 | 1 | <?php |
| 2 | + |
| 3 | +use Nexmo\Client; |
| 4 | +use Nexmo\SMS\Message\SMS; |
| 5 | +use Nexmo\Client\Exception\Request; |
| 6 | + |
2 | 7 | //example of sending an sms using an API key / secret |
3 | 8 | require_once '../vendor/autoload.php'; |
4 | 9 |
|
|
8 | 13 | define('NEXMO_FROM', getenv('NEXMO_FROM')); |
9 | 14 |
|
10 | 15 | //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)); |
12 | 17 |
|
13 | 18 | //send message using simple api params |
14 | 19 | $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') |
16 | 21 | ); |
17 | 22 |
|
18 | 23 | //array access provides response data |
|
30 | 35 | That thou, her maid, art far more fair than she. |
31 | 36 | EOF; |
32 | 37 |
|
33 | | -$text = new \Nexmo\SMS\Message\SMS(NEXMO_TO, NEXMO_FROM, $longwinded); |
| 38 | +$text = new SMS(NEXMO_TO, NEXMO_FROM, $longwinded); |
34 | 39 | $response = $client->sms()->send($text); |
35 | 40 | $data = $response->current(); |
36 | 41 |
|
|
42 | 47 |
|
43 | 48 | //an invalid request |
44 | 49 | try { |
45 | | - $text = new \Nexmo\SMS\Message\SMS('not valid', NEXMO_FROM, $longwinded); |
| 50 | + $text = new SMS('not valid', NEXMO_FROM, $longwinded); |
46 | 51 | $client->sms()->send($text); |
47 | | -} catch (Nexmo\Client\Exception\Request $e) { |
| 52 | +} catch (Request $e) { |
48 | 53 | //can still get the API response |
49 | 54 | $data = $e->getEntity(); // The parsed response as an array |
50 | 55 | $request = $client->sms()->getAPIResource()->getLastRequest(); //PSR-7 Request Object |
|
0 commit comments