-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a2f99a
commit 78af72c
Showing
12 changed files
with
263 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
// Used for composer based installation | ||
require __DIR__ . '/../../vendor/autoload.php'; | ||
|
||
// Use below for direct download installation | ||
//require_once(__DIR__ . '/../../src/Instasent/Abstracts/InstasentClient.php'); | ||
//require_once(__DIR__ . '/../../src/Instasent/AccountClient.php'); | ||
|
||
$instasentClient = new Instasent\AccountClient("my-token"); | ||
|
||
$response = $instasentClient->getAccountBalance(); | ||
|
||
//echo $response["response_code"]; | ||
//echo $response["response_body"]; | ||
|
||
$response_body = json_decode($response["response_body"]); | ||
$available = $response_body->entity->available; | ||
$currency = $response_body->entity->currency; | ||
|
||
echo sprintf("You have a balance of %s %s ", $available, $currency); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
// Used for composer based installation | ||
require __DIR__ . '/../../vendor/autoload.php'; | ||
|
||
// Use below for direct download installation | ||
//require_once(__DIR__ . '/../../src/Instasent/Abstracts/InstasentClient.php'); | ||
//require_once(__DIR__ . '/../../src/Instasent/LookupClient.php'); | ||
|
||
$instasentClient = new Instasent\LookupClient("my-token"); | ||
$response = $instasentClient->doLookup("+34666000000"); | ||
|
||
echo $response["response_code"]; | ||
echo $response["response_body"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Instasent PHP Library. | ||
* | ||
* (c) Instasent <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Instasent\Abstracts; | ||
|
||
abstract class InstasentClient | ||
{ | ||
/** | ||
* Endpoint URL | ||
* | ||
* @var string | ||
*/ | ||
protected $rootEndpoint = 'http://api.instasent.com'; | ||
|
||
/** | ||
* Secure Channel URL | ||
* | ||
* @var string | ||
*/ | ||
protected $secureChannel = 'https://api.instasent.com'; | ||
|
||
/** | ||
* Api Token | ||
* | ||
* @var string | ||
*/ | ||
protected $token; | ||
|
||
/** | ||
* Use secure channel flag | ||
* | ||
* @var boolean | ||
*/ | ||
protected $useSecureChannel = true; | ||
|
||
/** | ||
* InstasentClient constructor. | ||
* | ||
* @param $token | ||
* @param bool $useSecureChannel | ||
*/ | ||
public function __construct($token, $useSecureChannel = true) | ||
{ | ||
$this->token = $token; | ||
$this->useSecureChannel = $useSecureChannel; | ||
} | ||
|
||
/** | ||
* Execute the request using curl | ||
* | ||
* @param string $url | ||
* @param string $httpMethod | ||
* @param string $data | ||
* | ||
* @return array | ||
*/ | ||
protected function execRequest($url, $httpMethod, $data) | ||
{ | ||
$curl = curl_init(); | ||
$headers = array( | ||
'Authorization: Bearer '.$this->token, | ||
); | ||
|
||
curl_setopt($curl,CURLOPT_URL, $url); | ||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); | ||
|
||
if ($httpMethod == 'POST') { | ||
curl_setopt($curl, CURLOPT_POST, true); | ||
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); | ||
} | ||
$body = curl_exec($curl); | ||
$info = curl_getinfo($curl); | ||
|
||
return array( | ||
"response_code" => $info['http_code'], | ||
"response_body" => $body, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Instasent PHP Library. | ||
* | ||
* (c) Instasent <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Instasent; | ||
|
||
use Instasent\Abstracts\InstasentClient; | ||
|
||
class AccountClient extends InstasentClient | ||
{ | ||
|
||
/** | ||
* Get Account Balance | ||
* | ||
* @return array | ||
*/ | ||
public function getAccountBalance() | ||
{ | ||
$url = ($this->useSecureChannel) ? $this->secureChannel.'/organization/account/' : $this->rootEndpoint.'/organization/account/'; | ||
$httpMethod = 'GET'; | ||
return $this->execRequest($url, $httpMethod, array()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Instasent PHP Library. | ||
* | ||
* (c) Instasent <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Instasent; | ||
|
||
use Instasent\Abstracts\InstasentClient; | ||
|
||
class LookupClient extends InstasentClient | ||
{ | ||
|
||
/** | ||
* Do a lookup to get number info | ||
* @param string $to Recipient where lookup is requested | ||
* | ||
* @return array | ||
*/ | ||
public function doLookup($to) | ||
{ | ||
$url = ($this->useSecureChannel) ? $this->secureChannel.'/lookup/' : $this->rootEndpoint.'/lookup/'; | ||
$httpMethod = 'POST'; | ||
$data = array('to' => $to); | ||
|
||
return $this->execRequest($url, $httpMethod, $data); | ||
} | ||
|
||
/** | ||
* Get a lookup by id | ||
* @param string $id | ||
* | ||
* @return array | ||
*/ | ||
public function getLookupById($id) | ||
{ | ||
$url = ($this->useSecureChannel) ? $this->secureChannel.'/lookup/'.$id : $this->rootEndpoint.'/lookup/'.$id; | ||
$httpMethod = 'GET'; | ||
return $this->execRequest($url, $httpMethod, array()); | ||
} | ||
|
||
/** | ||
* Get all lookups. Filter by page and resultes per page. | ||
* @param integer $page | ||
* @param integer $perPage | ||
* | ||
* @return array | ||
*/ | ||
public function getLookups($page = 1, $perPage = 10) | ||
{ | ||
$query = http_build_query(array('page' => $page, 'per_page' => $perPage)); | ||
$url = ($this->useSecureChannel) ? $this->secureChannel.'/lookup/?'.$query : $this->rootEndpoint.'/lookup/?'.$query; | ||
$httpMethod = 'GET'; | ||
return $this->execRequest($url, $httpMethod, array()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.