Skip to content

Commit

Permalink
readme examples update
Browse files Browse the repository at this point in the history
also finalized Facades and fixed bugs
  • Loading branch information
Artistan committed May 22, 2014
1 parent 36aef40 commit 11dc9b9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,42 @@ Quick Examples
1) Sending an SMS

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

OR

$sms = NexmoSmsMessage::sendText('15005554320','15555633637','dude, this is from a laravel package');

2) Recieving SMS

// TODO:: setup default routing for this...
$sms = new Artistan\Nexmo\Service\Message\Sms;
OR
$sms = \App::make('nexmosmsmessage');
AND
if ($sms->inboundText()) {
$sms->reply('You said: ' . $sms->text);
}

OR

if(NexmoAccount::inboundText()){
NexmoAccount::reply('You said: ' . $sms->text);
}




3) Receiving a message receipt

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

$account = new Artistan\Nexmo\Service\Account;
OR
$account = \App::make('nexmoaccount');
AND
$numbers = $account->numbersList();

OR

$numbers = NexmoAccount::numbersList();




Expand Down
15 changes: 9 additions & 6 deletions src/Artistan/Nexmo/Service/Message/Sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ private function sendRequest ( $data ) {
);
$context = stream_context_create($opts);
$from_nexmo = file_get_contents($this->nx_uri, false, $context);
// TODO: data for test cast.
// $from_nexmo = '{"message-count":"1","messages":[{"to":"15079934320","message-id":"030000004090C3EF","status":"0","remaining-balance":"1.97600000","message-price":"0.00480000","network":"310004"}]}';
} else {
// No way of sending a HTTP post :(
return false;
Expand Down Expand Up @@ -231,22 +233,23 @@ private function normaliseKeys ($obj) {
*/
private function nexmoParse ( $from_nexmo ) {
$response = json_decode($from_nexmo);

// Copy the response data into an object, removing any '-' characters from the key
$response_obj = $this->normaliseKeys($response);

if ($response_obj) {
$this->nexmo_response = $response_obj;
$this->nexmo_response = (array) $response_obj;

// Find the total cost of this message
$response_obj->cost = $total_cost = 0;
if (is_array($response_obj->messages)) {
foreach ($response_obj->messages as $msg) {
$response_obj['cost'] = $total_cost = 0;
if (is_array($response_obj['messages'])) {
foreach ($response_obj['messages'] as $msg) {
if (property_exists($msg, "messageprice")) {
$total_cost = $total_cost + (float)$msg->messageprice;
} elseif(array_key_exists('messageprice',$msg)) {
$total_cost = $total_cost + (float)$response_obj['messageprice'];
}
}
$response_obj->cost = $total_cost;
$response_obj['cost'] = $total_cost;
}
return $response_obj;

Expand Down

0 comments on commit 11dc9b9

Please sign in to comment.