Skip to content

Commit

Permalink
Only use secure channel
Browse files Browse the repository at this point in the history
  • Loading branch information
markitosgv committed Dec 7, 2016
1 parent 5a56bc5 commit 225011f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 30 deletions.
2 changes: 1 addition & 1 deletion examples/Sms/send-sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//require_once(__DIR__ . '/../../src/Instasent/SmsClient.php');

$instasentClient = new Instasent\SmsClient("my-token");
$response = $instasentClient->sendSms("test", "+34647000000", "test message");
$response = $instasentClient->sendSms("test", "+34647188472", "test message");

echo $response["response_code"];
echo $response["response_body"];
18 changes: 2 additions & 16 deletions src/Instasent/Abstracts/InstasentClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,13 @@

abstract class InstasentClient
{
/**
* Endpoint URL
*
* @var string
*/
protected $rootEndpoint = 'http://api.instasent.com';

/**
* Secure Channel URL
*
* @var string
*/
protected $secureChannel = 'http://api.instasent.com';
protected $secureChannel = 'https://api.instasent.com';

/**
* Api Token
Expand All @@ -34,23 +28,15 @@ abstract class InstasentClient
*/
protected $token;

/**
* Use secure channel flag
*
* @var boolean
*/
protected $useSecureChannel = true;

/**
* InstasentClient constructor.
*
* @param $token
* @param bool $useSecureChannel
*/
public function __construct($token, $useSecureChannel = true)
public function __construct($token)
{
$this->token = $token;
$this->useSecureChannel = $useSecureChannel;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Instasent/AccountClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AccountClient extends InstasentClient
*/
public function getAccountBalance()
{
$url = ($this->useSecureChannel) ? $this->secureChannel.'/organization/account/' : $this->rootEndpoint.'/organization/account/';
$url = $this->secureChannel.'/organization/account/';
$httpMethod = 'GET';
return $this->execRequest($url, $httpMethod, array());
}
Expand Down
6 changes: 3 additions & 3 deletions src/Instasent/LookupClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class LookupClient extends InstasentClient
*/
public function doLookup($to)
{
$url = ($this->useSecureChannel) ? $this->secureChannel.'/lookup/' : $this->rootEndpoint.'/lookup/';
$url = $this->secureChannel.'/lookup/';
$httpMethod = 'POST';
$data = array('to' => $to);

Expand All @@ -39,7 +39,7 @@ public function doLookup($to)
*/
public function getLookupById($id)
{
$url = ($this->useSecureChannel) ? $this->secureChannel.'/lookup/'.$id : $this->rootEndpoint.'/lookup/'.$id;
$url = $this->secureChannel.'/lookup/'.$id;
$httpMethod = 'GET';
return $this->execRequest($url, $httpMethod, array());
}
Expand All @@ -54,7 +54,7 @@ public function getLookupById($id)
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;
$url = $this->secureChannel.'/lookup/?'.$query;
$httpMethod = 'GET';
return $this->execRequest($url, $httpMethod, array());
}
Expand Down
10 changes: 5 additions & 5 deletions src/Instasent/SmsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SmsClient extends InstasentClient
*/
public function sendSms($from, $to, $text, $clientId = null)
{
$url = ($this->useSecureChannel) ? $this->secureChannel.'/sms/' : $this->rootEndpoint.'/sms/';
$url = $this->secureChannel.'/sms/';
$httpMethod = 'POST';
$data = array('from' => $from, 'to' => $to, 'text' => $text);
if ($clientId) {
Expand All @@ -47,7 +47,7 @@ public function sendSms($from, $to, $text, $clientId = null)
*/
public function sendUnicodeSms($from, $to, $text, $clientId = null)
{
$url = ($this->useSecureChannel) ? $this->secureChannel.'/sms/' : $this->rootEndpoint.'/sms/';
$url = $this->secureChannel.'/sms/';
$httpMethod = 'POST';
$data = array('allowUnicode' => true, 'from' => $from, 'to' => $to, 'text' => $text);
if ($clientId) {
Expand All @@ -67,7 +67,7 @@ public function sendUnicodeSms($from, $to, $text, $clientId = null)
*/
public function sendBulkSms($messages, $clientId = null)
{
$url = ($this->useSecureChannel) ? $this->secureChannel.'/sms/bulk/' : $this->rootEndpoint.'/sms/bulk/';
$url = $this->secureChannel.'/sms/bulk/';
$httpMethod = 'POST';

if ($clientId) {
Expand All @@ -84,7 +84,7 @@ public function sendBulkSms($messages, $clientId = null)
*/
public function getSmsById($id)
{
$url = ($this->useSecureChannel) ? $this->secureChannel.'/sms/'.$id : $this->rootEndpoint.'/sms/'.$id;
$url = $this->secureChannel.'/sms/'.$id;
$httpMethod = 'GET';
return $this->execRequest($url, $httpMethod, array());
}
Expand All @@ -99,7 +99,7 @@ public function getSmsById($id)
public function getSms($page = 1, $perPage = 10)
{
$query = http_build_query(array('page' => $page, 'per_page' => $perPage));
$url = ($this->useSecureChannel) ? $this->secureChannel.'/sms/?'.$query : $this->rootEndpoint.'/sms/?'.$query;
$url = $this->secureChannel.'/sms/?'.$query;
$httpMethod = 'GET';
return $this->execRequest($url, $httpMethod, array());
}
Expand Down
8 changes: 4 additions & 4 deletions src/Instasent/VerifyClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class VerifyClient extends InstasentClient
*/
public function requestVerify($from, $to, $text, $tokenLength = null, $timeout = null, $clientId = null)
{
$url = ($this->useSecureChannel) ? $this->secureChannel.'/verify/' : $this->rootEndpoint.'/verify/';
$url = $this->secureChannel.'/verify/';
$httpMethod = 'POST';
$data = array('sms' => array('from' => $from, 'to' => $to, 'text' => $text));

Expand Down Expand Up @@ -58,7 +58,7 @@ public function requestVerify($from, $to, $text, $tokenLength = null, $timeout =
*/
public function checkVerify($id, $token)
{
$url = ($this->useSecureChannel) ? $this->secureChannel.'/verify/'.$id : $this->rootEndpoint.'/verify/'.$id;
$url = $this->secureChannel.'/verify/'.$id;
$url .= '?token='.$token;
$httpMethod = 'GET';
return $this->execRequest($url, $httpMethod, array());
Expand All @@ -72,7 +72,7 @@ public function checkVerify($id, $token)
*/
public function getVerifyById($id)
{
$url = ($this->useSecureChannel) ? $this->secureChannel.'/verify/'.$id : $this->rootEndpoint.'/verify/'.$id;
$url = $this->secureChannel.'/verify/'.$id;
$httpMethod = 'GET';
return $this->execRequest($url, $httpMethod, array());
}
Expand All @@ -87,7 +87,7 @@ public function getVerifyById($id)
public function getVerify($page = 1, $perPage = 10)
{
$query = http_build_query(array('page' => $page, 'per_page' => $perPage));
$url = ($this->useSecureChannel) ? $this->secureChannel.'/verify/?'.$query : $this->rootEndpoint.'/verify/?'.$query;
$url = $this->secureChannel.'/verify/?'.$query;
$httpMethod = 'GET';
return $this->execRequest($url, $httpMethod, array());
}
Expand Down

0 comments on commit 225011f

Please sign in to comment.