diff options
author | mattab <matthieu.aubry@gmail.com> | 2013-03-28 03:42:39 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2013-03-28 03:42:40 +0400 |
commit | ae4b03163792f0b6e933933e5d37df87dc3fd566 (patch) | |
tree | d1d7510a9728f587d3d63ebd03e4ecf3d904838b /plugins/MobileMessaging/SMSProvider/Clockwork.php | |
parent | 158c2150f5f2e13ece459b8d131244c11b763997 (diff) |
Mass conversion of all files to the newly agreed coding standard: PSR 1/2
Converting Piwik core source files, PHP, JS, TPL, CSS
More info: http://piwik.org/participate/coding-standards/
Diffstat (limited to 'plugins/MobileMessaging/SMSProvider/Clockwork.php')
-rw-r--r-- | plugins/MobileMessaging/SMSProvider/Clockwork.php | 163 |
1 files changed, 81 insertions, 82 deletions
diff --git a/plugins/MobileMessaging/SMSProvider/Clockwork.php b/plugins/MobileMessaging/SMSProvider/Clockwork.php index dfb7854fd3..b7a50dfe02 100644 --- a/plugins/MobileMessaging/SMSProvider/Clockwork.php +++ b/plugins/MobileMessaging/SMSProvider/Clockwork.php @@ -16,86 +16,85 @@ require_once PIWIK_INCLUDE_PATH . "/plugins/MobileMessaging/APIException.php"; */ class Piwik_MobileMessaging_SMSProvider_Clockwork extends Piwik_MobileMessaging_SMSProvider { - const SOCKET_TIMEOUT = 15; - - const BASE_API_URL = 'https://api.mediaburst.co.uk/http'; - const CHECK_CREDIT_RESOURCE = '/credit.aspx'; - const SEND_SMS_RESOURCE = '/send.aspx'; - - const ERROR_STRING = 'Error'; - - const MAXIMUM_FROM_LENGTH = 11; - const MAXIMUM_CONCATENATED_SMS = 3; - - public function verifyCredential($apiKey) - { - $this->getCreditLeft($apiKey); - - return true; - } - - public function sendSMS($apiKey, $smsText, $phoneNumber, $from) - { - $from = substr($from, 0, self::MAXIMUM_FROM_LENGTH); - - $smsText = self::truncate($smsText, self::MAXIMUM_CONCATENATED_SMS); - - $additionalParameters = array( - 'To' => str_replace('+','', $phoneNumber), - 'Content' => $smsText, - 'From' => $from, - 'Long' => 1, - 'MsgType' => self::containsUCS2Characters($smsText) ? 'UCS2' : 'TEXT', - ); - - $this->issueApiCall( - $apiKey, - self::SEND_SMS_RESOURCE, - $additionalParameters - ); - } - - private function issueApiCall($apiKey, $resource, $additionalParameters = array()) - { - $accountParameters = array( - 'Key' => $apiKey, - ); - - $parameters = array_merge($accountParameters, $additionalParameters); - - $url = self::BASE_API_URL - . $resource - . '?' . http_build_query($parameters, '', '&'); - - $timeout = self::SOCKET_TIMEOUT; - - $result = Piwik_Http::sendHttpRequestBy( - Piwik_Http::getTransportMethod(), - $url, - $timeout, - $userAgent = null, - $destinationPath = null, - $file = null, - $followDepth = 0, - $acceptLanguage = false, - $acceptInvalidSslCertificate = true - ); - - if(strpos($result, self::ERROR_STRING) !== false) - { - throw new Piwik_MobileMessaging_APIException( - 'Clockwork API returned the following error message : ' . $result - ); - } - - return $result; - } - - public function getCreditLeft($apiKey) - { - return $this->issueApiCall( - $apiKey, - self::CHECK_CREDIT_RESOURCE - ); - } + const SOCKET_TIMEOUT = 15; + + const BASE_API_URL = 'https://api.mediaburst.co.uk/http'; + const CHECK_CREDIT_RESOURCE = '/credit.aspx'; + const SEND_SMS_RESOURCE = '/send.aspx'; + + const ERROR_STRING = 'Error'; + + const MAXIMUM_FROM_LENGTH = 11; + const MAXIMUM_CONCATENATED_SMS = 3; + + public function verifyCredential($apiKey) + { + $this->getCreditLeft($apiKey); + + return true; + } + + public function sendSMS($apiKey, $smsText, $phoneNumber, $from) + { + $from = substr($from, 0, self::MAXIMUM_FROM_LENGTH); + + $smsText = self::truncate($smsText, self::MAXIMUM_CONCATENATED_SMS); + + $additionalParameters = array( + 'To' => str_replace('+', '', $phoneNumber), + 'Content' => $smsText, + 'From' => $from, + 'Long' => 1, + 'MsgType' => self::containsUCS2Characters($smsText) ? 'UCS2' : 'TEXT', + ); + + $this->issueApiCall( + $apiKey, + self::SEND_SMS_RESOURCE, + $additionalParameters + ); + } + + private function issueApiCall($apiKey, $resource, $additionalParameters = array()) + { + $accountParameters = array( + 'Key' => $apiKey, + ); + + $parameters = array_merge($accountParameters, $additionalParameters); + + $url = self::BASE_API_URL + . $resource + . '?' . http_build_query($parameters, '', '&'); + + $timeout = self::SOCKET_TIMEOUT; + + $result = Piwik_Http::sendHttpRequestBy( + Piwik_Http::getTransportMethod(), + $url, + $timeout, + $userAgent = null, + $destinationPath = null, + $file = null, + $followDepth = 0, + $acceptLanguage = false, + $acceptInvalidSslCertificate = true + ); + + if (strpos($result, self::ERROR_STRING) !== false) { + throw new Piwik_MobileMessaging_APIException( + 'Clockwork API returned the following error message : ' . $result + ); + } + + return $result; + } + + public function getCreditLeft($apiKey) + { + return $this->issueApiCall( + $apiKey, + self::CHECK_CREDIT_RESOURCE + ); + } } |