Skip to content

Instantly share code, notes, and snippets.

@opensussex
Created August 14, 2016 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save opensussex/d374f05120841b0f5e7e1d209907b5cf to your computer and use it in GitHub Desktop.
Save opensussex/d374f05120841b0f5e7e1d209907b5cf to your computer and use it in GitHub Desktop.
<?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