Skip to content

Commit 11dc9b9

Browse files
committed
readme examples update
also finalized Facades and fixed bugs
1 parent 36aef40 commit 11dc9b9

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,42 @@ Quick Examples
3232
1) Sending an SMS
3333

3434
$sms = new Artistan\Nexmo\Service\Message\Sms;
35+
OR
3536
$sms = \App::make('nexmosmsmessage');
37+
AND
3638
$result = $sms->sendText('15005554320','15555633637','dude, this is from a laravel package');
3739

40+
OR
41+
42+
$sms = NexmoSmsMessage::sendText('15005554320','15555633637','dude, this is from a laravel package');
43+
3844
2) Recieving SMS
3945

4046
// TODO:: setup default routing for this...
4147
$sms = new Artistan\Nexmo\Service\Message\Sms;
48+
OR
4249
$sms = \App::make('nexmosmsmessage');
50+
AND
4351
if ($sms->inboundText()) {
4452
$sms->reply('You said: ' . $sms->text);
4553
}
4654

55+
OR
56+
57+
if(NexmoAccount::inboundText()){
58+
NexmoAccount::reply('You said: ' . $sms->text);
59+
}
60+
61+
4762

4863

4964
3) Receiving a message receipt
5065

5166
// TODO:: setup default routing for this...
5267
$receipt = new Artistan\Nexmo\Service\Receipt;
68+
OR
5369
$receipt = \App::make('nexmoreceipt');
70+
AND
5471
if ($receipt->exists()) {
5572
switch ($receipt->status) {
5673
case $receipt::STATUS_DELIVERED:
@@ -69,9 +86,15 @@ Quick Examples
6986
4) List purchased numbers on your account
7087

7188
$account = new Artistan\Nexmo\Service\Account;
89+
OR
7290
$account = \App::make('nexmoaccount');
91+
AND
7392
$numbers = $account->numbersList();
7493

94+
OR
95+
96+
$numbers = NexmoAccount::numbersList();
97+
7598

7699

77100

src/Artistan/Nexmo/Service/Message/Sms.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ private function sendRequest ( $data ) {
187187
);
188188
$context = stream_context_create($opts);
189189
$from_nexmo = file_get_contents($this->nx_uri, false, $context);
190+
// TODO: data for test cast.
191+
// $from_nexmo = '{"message-count":"1","messages":[{"to":"15079934320","message-id":"030000004090C3EF","status":"0","remaining-balance":"1.97600000","message-price":"0.00480000","network":"310004"}]}';
190192
} else {
191193
// No way of sending a HTTP post :(
192194
return false;
@@ -231,22 +233,23 @@ private function normaliseKeys ($obj) {
231233
*/
232234
private function nexmoParse ( $from_nexmo ) {
233235
$response = json_decode($from_nexmo);
234-
235236
// Copy the response data into an object, removing any '-' characters from the key
236237
$response_obj = $this->normaliseKeys($response);
237238

238239
if ($response_obj) {
239-
$this->nexmo_response = $response_obj;
240+
$this->nexmo_response = (array) $response_obj;
240241

241242
// Find the total cost of this message
242-
$response_obj->cost = $total_cost = 0;
243-
if (is_array($response_obj->messages)) {
244-
foreach ($response_obj->messages as $msg) {
243+
$response_obj['cost'] = $total_cost = 0;
244+
if (is_array($response_obj['messages'])) {
245+
foreach ($response_obj['messages'] as $msg) {
245246
if (property_exists($msg, "messageprice")) {
246247
$total_cost = $total_cost + (float)$msg->messageprice;
248+
} elseif(array_key_exists('messageprice',$msg)) {
249+
$total_cost = $total_cost + (float)$response_obj['messageprice'];
247250
}
248251
}
249-
$response_obj->cost = $total_cost;
252+
$response_obj['cost'] = $total_cost;
250253
}
251254
return $response_obj;
252255

0 commit comments

Comments
 (0)