Created
August 14, 2016 13:59
-
-
Save opensussex/d374f05120841b0f5e7e1d209907b5cf to your computer and use it in GitHub Desktop.
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
<?php | |
use GuzzleHttp\Client; | |
class TextMarketer | |
{ | |
private $username; | |
private $password; | |
private $orig; | |
/** | |
* Constructor | |
* @param string $username | |
* @param string $password | |
* @param string $orig | |
*/ | |
public function __construct($username, $password, $orig) | |
{ | |
$this->username = $username; | |
$this->password = $password; | |
$this->orig = $orig; | |
} | |
/** | |
* Send a text message using textMarketer | |
* @param string $message | |
* @param string $to | |
* @return boolean | |
* @throws Exception | |
*/ | |
public function sendText($message, $to) | |
{ | |
$query = [ | |
'username' =>$this->username, | |
'password' =>$this->password, | |
'message' =>$message, | |
'orig' => $this->orig, | |
'number' => $to | |
]; | |
try { | |
$response = $this->request('GET', $query); | |
} catch (\Exception $e) { | |
throw new \Exception('Something went wrong sending the text'); | |
} | |
if ($response->getStatusCode() == '200') { | |
if (strpos((string)$response->getBody(), 'SUCCESS') !== false) { | |
return true; | |
} else { | |
throw new \Exception((string)$response->getBody()); | |
} | |
} else { | |
throw new \Exception('Something went wrong sending the text'); | |
} | |
} | |
/** | |
* do the request | |
* @param string $verb | |
* @param array $verb | |
* @param string $endPoint | |
* @return Guzzle responseObject | |
*/ | |
private function request($verb, $query, $endPoint = '') | |
{ | |
$client = new Client(['base_uri' => 'https://www.textmarketer.biz/gateway/']); | |
$response = $client->request( | |
$verb, | |
$endPoint, | |
[ 'query' => $query] | |
); | |
return $response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment