Skip to content

Commit

Permalink
Added and corrected docs in websms provider class.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaskonrad-sba committed Oct 20, 2014
1 parent 2cd148d commit 9548f47
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/SmsSender/Provider/WebsmsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class WebsmsProvider extends AbstractProvider
*/
protected $accessToken;

/**
* @var string
*/
protected $internationalPrefix;

/**
Expand Down Expand Up @@ -76,13 +79,23 @@ public function send($recipient, $body, $originator = '')
));
}

/**
* Issues the actual HTTP query.
*
* @param $url
* @param array $data
* @param array $extra_result_data
* @return array
*/
protected function executeQuery($url, array $data = array(), array $extra_result_data = array())
{
$headers = array(
sprintf('Authorization: Bearer %s', $this->accessToken),
'Content-Type: application/json',
'Accept: application/json'
);

// Issue the request
$content = $this->getAdapter()->getContent($url, 'POST', $headers, json_encode($data));

if (null === $content) {
Expand All @@ -93,7 +106,7 @@ protected function executeQuery($url, array $data = array(), array $extra_result
}

/**
* Parse the data returned by the API.
* Parses the data returned by the API.
*
* @param string $result The raw result string.
* @return array
Expand All @@ -103,7 +116,7 @@ protected function parseResults($result, array $extra_result_data = array())
$data = json_decode($result, true);
$smsData = array();

// there was an error
// There was an error
if (empty($data['transferId']) || empty($data['statusCode'])) {
return array_merge($this->getDefaults(), $extra_result_data, array(
'status' => ResultInterface::STATUS_FAILED,
Expand All @@ -114,7 +127,7 @@ protected function parseResults($result, array $extra_result_data = array())
// Get the transfer id
$smsData['id'] = $data['transferId'];

// get the status
// Get the status
switch ($data['statusCode']) {
case 2000:
$smsData['status'] = ResultInterface::STATUS_SENT;
Expand All @@ -130,6 +143,12 @@ protected function parseResults($result, array $extra_result_data = array())
return array_merge($this->getDefaults(), $extra_result_data, $smsData);
}

/**
* Removes the leading plus sign from the international phone number as websms requires it that way.
*
* @param string $number The number to strip the plus sign from
* @return string
*/
protected function removeLeadingPlusIfPresent($number)
{
if ($number[0] !== '+') {
Expand Down

0 comments on commit 9548f47

Please sign in to comment.