Skip to content

Commit

Permalink
after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
jper92 committed Mar 13, 2015
1 parent 9d986b5 commit ba1b822
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 11 deletions.
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,77 @@ Para hacer llamadas al API pueden utilizarse los métodos `contacts()`, `groups(
data => (array/StdObj)[/*the data*/]
];

// ejemplos

// object(stdClass) (5) {
// ["code"]=>
// int(500)
// ["status"]=>
// string(5) "Error"
// ["ok"]=>
// bool(false)
// ["response_headers"]=>
// array(4) {
// [0]=>
// string(34) "HTTP/1.1 500 Internal Server Error"
// [1]=>
// string(30) "Content-Type: application/json"
// [2]=>
// string(42) "Server: ContactoSMS API/3.0 (Simple 5.1.4)"
// [3]=>
// string(17) "Connection: close"
// }
// ["data"]=>
// object(stdClass)#5 (2) {
// ["code"]=>
// int(503)
// ["error"]=>
// string(25) "Error interno. Reintentar"
// }
// }

// array(5) {
// ["code"]=>
// int(200)
// ["status"]=>
// string(2) "OK"
// ["ok"]=>
// bool(true)
// ["response_headers"]=>
// array(4) {
// [0]=>
// string(15) "HTTP/1.1 200 OK"
// [1]=>
// string(30) "Content-Type: application/json"
// [2]=>
// string(42) "Server: ContactoSMS API/3.0 (Simple 5.1.4)"
// [3]=>
// string(17) "Connection: close"
// }
// ["data"]=>
// array(1) {
// [0]=>
// array(7) {
// ["msisdn"]=>
// string(11) "50212345678"
// ["status"]=>
// string(9) "SUSCRIBED"
// ["phone_number"]=>
// string(8) "12345678"
// ["country_code"]=>
// string(3) "502"
// ["first_name"]=>
// string(7) "Alberto"
// ["full_name"]=>
// string(7) "Alberto"
// ["added_from"]=>
// string(8) "WEB_FORM"
// }
// }
// }



```
Ejemplos de llamadas al API:

Expand Down
19 changes: 13 additions & 6 deletions examples/contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

include("../src/SmsApi.php");

define('API_KEY', 'Your api key');
define('API_SECRET', 'Your api secret');
define('API_URL', 'Your api url');

$api = new SmsApi(API_KEY, API_SECRET, API_URL, true); // hey you'll have your responses in arrays, did you want StdObject? change last parameter to false

// Response format:
Expand All @@ -14,12 +18,6 @@
// ];


/// Deleting a contact....
echo ("Deleting contact...");
$response = $api->contacts()->deleteContact("50212345678");
if ($response['ok']) echo "Contact deleted\n";
else echo "Something went wrong here is the data";
var_dump($response);

/// Creating a contact......
echo ("Creating contact...");
Expand Down Expand Up @@ -54,3 +52,12 @@
if ($response['ok']) foreach ($response['data'] as $group){
echo $group['name']."\n";
}

/// Deleting a contact....
echo ("Deleting contact...");
$response = $api->contacts()->deleteContact("50212345678");
if ($response['ok']) echo "Contact deleted\n";
else {
echo "Something went wrong here is the data";
var_dump($response);
}
5 changes: 5 additions & 0 deletions examples/groups.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?php
include("../src/SmsApi.php");

define('API_KEY', 'Your api key');
define('API_SECRET', 'Your api secret');
define('API_URL', 'Your api url');


$api = new SmsApi(API_KEY, API_SECRET, API_URL, false /* Now I want objects... did you want array? change last parameter to true */);

// Response format:
Expand Down
4 changes: 4 additions & 0 deletions examples/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
date_default_timezone_set("America/Guatemala");
include("../src/SmsApi.php");

define('API_KEY', 'Your api key');
define('API_SECRET', 'Your api secret');
define('API_URL', 'Your api url');

$api = new SmsApi(API_KEY, API_SECRET, API_URL, false);


Expand Down
6 changes: 1 addition & 5 deletions src/libs/ApiWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,15 @@ public function delete($endpoint, $params=null){
public function send($url, $params, $method, $body){
if ($params) $url = $url."?".$params;
$datetime = gmdate("D, d M Y H:i:s T");
// print($datetime."\n");
$authentication = $this->apiKey.$datetime.$params.$body;
// print($authentication."|\n");
// print($this->apiSecret."|\n");
$hash = hash_hmac("sha1",$authentication, $this->apiSecret,true);
// print($hash."\n");
$hash = base64_encode($hash);
$headers = array(
"Content-type: application/json",
"Date: $datetime",
"Authorization: IM $this->apiKey:$hash",
"X-IM-ORIGIN: IM_SDK_PHP",
);
// print($hash."\n");

$options = array(
'http' => array(
Expand All @@ -132,6 +127,7 @@ public function send($url, $params, $method, $body){
'response_headers' => $http_response_header,
'data' => $json,
);
var_dump($data);
return $this->assoc?$data:(object)$data;
}
}

0 comments on commit ba1b822

Please # to comment.