Modified and renamed HTTPBroker to RestClient.

This commit is contained in:
Travis Swientek 2013-08-07 16:22:19 -07:00
parent ae1b570040
commit 1ff4357810
18 changed files with 265 additions and 173 deletions

View File

@ -7,19 +7,19 @@ namespace Mailgun\Address;
class Address{
private $httpBroker;
private $restClient;
private $workingDomain;
private $endpointUrl;
public function __construct($httpBroker){
$this->httpBroker = $httpBroker;
public function __construct($restClient){
$this->restClient = $restClient;
$this->endpointUrl = "address";
}
public function validateAddress($address){
public function getValidate($address){
$updatedUrl = $this->endpointUrl . "/validate";
$getData = array('address' => $address);
$response = $this->httpBroker->getRequest($updatedUrl, $getData);
$response = $this->restClient->getRequest($updatedUrl, $getData);
return $response;
}
}

View File

@ -17,13 +17,13 @@ $mgClient = new MailgunClient("pubkey-5ogiflzbnjrljiky49qxsiozqef5jxp7", "sample
$address = $mgClient->Address();
# Now, validate the address and store the result in $result.
$result = $address->validateAddress("me@samples.mailgun.org");
$result = $address->getValidate("me@samples.mailgun.org");
```
Available Functions
-------------------
`validateAddress(string $address);`
`getValidate(string $address);`
More Documentation
------------------

View File

@ -7,13 +7,13 @@ namespace Mailgun\Bounces;
class Bounces{
private $httpBroker;
private $restClient;
private $workingDomain;
private $endpointUrl;
public function __construct($httpBroker){
$this->httpBroker = $httpBroker;
$this->endpointUrl = $this->httpBroker->returnWorkingDomain() . "/bounces";
public function __construct($restClient){
$this->restClient = $restClient;
$this->endpointUrl = $this->restClient->returnWorkingDomain() . "/bounces";
}
public function addAddress($bounceAddress, $bounceCode, $bounceError = null){
@ -23,23 +23,23 @@ class Bounces{
else{
$postData = array("address" => $bounceAddress, "code" => $bounceCode);
}
$response = $this->httpBroker->postRequest($this->endpointUrl, $postData);
$response = $this->restClient->postRequest($this->endpointUrl, $postData);
return $response;
}
public function deleteAddress($bounceAddress){
$requestUrl = $this->endpointUrl . "/" . urlencode($bounceAddress);
$response = $this->httpBroker->deleteRequest($requestUrl);
$response = $this->restClient->deleteRequest($requestUrl);
return $response;
}
public function getBounce($bounceAddress){
$requestUrl = $this->endpointUrl . "/" . urlencode($bounceAddress);
$response = $this->httpBroker->getRequest($requestUrl);
$response = $this->restClient->getRequest($requestUrl);
return $response;
}
public function getBounces($limit, $skip){
$response = $this->httpBroker->getRequest($this->endpointUrl, array($limit, $skip));
$response = $this->restClient->getRequest($this->endpointUrl, array($limit, $skip));
return $response;
}

View File

@ -7,24 +7,24 @@ namespace Mailgun\Campaigns;
class Campaigns{
private $httpBroker;
private $restClient;
private $workingDomain;
private $endpointUrl;
public function __construct($httpBroker){
$this->httpBroker = $httpBroker;
$this->endpointUrl = $this->httpBroker->returnWorkingDomain() . "/campaigns";
public function __construct($restClient){
$this->restClient = $restClient;
$this->endpointUrl = $this->restClient->returnWorkingDomain() . "/campaigns";
}
public function getCampaigns($limit, $skip){
$response = $this->httpBroker->getRequest($this->endpointUrl, array($limit, $skip));
$response = $this->restClient->getRequest($this->endpointUrl, array($limit, $skip));
return $response;
}
public function getCampaign($campaignId){
$updatedUrl = $this->endpointUrl . "/" . $campaignId;
$response = $this->httpBroker->getRequest($updatedUrl);
$response = $this->restClient->getRequest($updatedUrl);
return $response;
}
@ -33,7 +33,7 @@ class Campaigns{
throw new InvalidParameter("The message ID is too long. Limit is 64 characters.");
}
$postData = array('name' => $name, 'id' => $id);
$response = $this->httpBroker->postRequest($this->endpointUrl, $postData);
$response = $this->restClient->postRequest($this->endpointUrl, $postData);
return $response;
}
@ -43,49 +43,49 @@ class Campaigns{
}
$updatedUrl = $this->endpointUrl . "/" . $campaignId;
$postData = array('name' => $name, 'id' => $id);
$response = $this->httpBroker->putRequest($updatedUrl, $postData);
$response = $this->restClient->putRequest($updatedUrl, $postData);
return $response;
}
public function deleteCampaign($campaignId){
$updatedUrl = $this->endpointUrl . "/" . $campaignId;
$response = $this->httpBroker->deleteRequest($updatedUrl);
$response = $this->restClient->deleteRequest($updatedUrl);
return $response;
}
public function getCampaignEvents($campaignId, $filterParams = array()){
$updatedUrl = $this->endpointUrl . "/" . $campaignId . "/events";
$response = $this->httpBroker->getRequest($updatedUrl, $filterParams);
$response = $this->restClient->getRequest($updatedUrl, $filterParams);
return $response;
}
public function getCampaignStats($campaignId, $filterParams = array()){
$updatedUrl = $this->endpointUrl . "/" . $campaignId . "/stats";
$response = $this->httpBroker->getRequest($updatedUrl, $filterParams);
$response = $this->restClient->getRequest($updatedUrl, $filterParams);
return $response;
}
public function getCampaignClicks($campaignId, $filterParams = array()){
$updatedUrl = $this->endpointUrl . "/" . $campaignId . "/clicks";
$response = $this->httpBroker->getRequest($updatedUrl, $filterParams);
$response = $this->restClient->getRequest($updatedUrl, $filterParams);
return $response;
}
public function getCampaignOpens($campaignId, $filterParams = array()){
$updatedUrl = $this->endpointUrl . "/" . $campaignId . "/opens";
$response = $this->httpBroker->getRequest($updatedUrl, $filterParams);
$response = $this->restClient->getRequest($updatedUrl, $filterParams);
return $response;
}
public function getCampaignUnsubscribes($campaignId, $filterParams = array()){
$updatedUrl = $this->endpointUrl . "/" . $campaignId . "/unsubscribes";
$response = $this->httpBroker->getRequest($updatedUrl, $filterParams);
$response = $this->restClient->getRequest($updatedUrl, $filterParams);
return $response;
}
public function getCampaignComplaints($campaignId, $filterParams = array()){
$updatedUrl = $this->endpointUrl . "/" . $campaignId . "/clicks";
$response = $this->httpBroker->getRequest($updatedUrl, $filterParams);
$response = $this->restClient->getRequest($updatedUrl, $filterParams);
return $response;
}
}

View File

@ -7,34 +7,34 @@ namespace Mailgun\Complaints;
class Complaints{
private $httpBroker;
private $restClient;
private $workingDomain;
private $endpointUrl;
public function __construct($httpBroker){
$this->httpBroker = $httpBroker;
$this->endpointUrl = $this->httpBroker->returnWorkingDomain() . "/complaints";
public function __construct($restClient){
$this->restClient = $restClient;
$this->endpointUrl = $this->restClient->returnWorkingDomain() . "/complaints";
}
public function addAddress($spamAddress){
$postData = array("address" => $spamAddress);
$response = $this->httpBroker->postRequest($this->endpointUrl, $postData);
$response = $this->restClient->postRequest($this->endpointUrl, $postData);
return $response;
}
public function deleteAddress($spamAddress){
$requestUrl = $this->endpointUrl . "/" . urlencode($spamAddress);
$response = $this->httpBroker->deleteRequest($requestUrl);
$response = $this->restClient->deleteRequest($requestUrl);
return $response;
}
public function getComplaint($spamAddress){
$requestUrl = $this->endpointUrl . "/" . urlencode($spamAddress);
$response = $this->httpBroker->getRequest($requestUrl);
$response = $this->restClient->getRequest($requestUrl);
return $response;
}
public function getComplaints($limit, $skip){
$response = $this->httpBroker->getRequest($this->endpointUrl, array($limit, $skip));
$response = $this->restClient->getRequest($this->endpointUrl, array($limit, $skip));
return $response;
}

View File

@ -13,7 +13,7 @@ use Mailgun\Connection\Exceptions\NoDomainsConfigured;
use Mailgun\Connection\Exceptions\MissingRequiredMIMEParameters;
use Mailgun\Connection\Exceptions\MissingEndpoint;
class HttpBroker{
class RestClient{
private $apiKey;
protected $workingDomain;

View File

@ -7,72 +7,72 @@ namespace Mailgun\Lists;
class Lists{
private $httpBroker;
private $restClient;
private $workingDomain;
private $endpointUrl;
public function __construct($httpBroker){
$this->httpBroker = $httpBroker;
public function __construct($restClient){
$this->restClient = $restClient;
$this->endpointUrl = "lists";
}
public function getLists($limit, $skip){
$response = $this->httpBroker->getRequest($this->endpointUrl, array($limit, $skip));
$response = $this->restClient->getRequest($this->endpointUrl, array($limit, $skip));
return $response;
}
public function getList($listAddress){
$updatedUrl = $this->endpointUrl . "/" . $listAddress;
$response = $this->httpBroker->getRequest($updatedUrl);
$response = $this->restClient->getRequest($updatedUrl);
return $response;
}
public function addList($listAddress, $name, $description, $access_level){
$postData = array('address' => $listAddress, 'name' => $name, 'description' => $description, 'access_level' => $access_level);
$response = $this->httpBroker->postRequest($this->endpointUrl, $postData);
$response = $this->restClient->postRequest($this->endpointUrl, $postData);
return $response;
}
public function updateList($listAddress, $name, $description, $access_level){
$updatedUrl = $this->endpointUrl . "/" . $listAddress;
$postData = array('address' => $listAddress, 'name' => $name, 'description' => $description, 'access_level' => $access_level);
$response = $this->httpBroker->putRequest($updatedUrl, $postData);
$response = $this->restClient->putRequest($updatedUrl, $postData);
return $response;
}
public function deleteList($listAddress){
$updatedUrl = $this->endpointUrl . "/" . $listAddress;
$response = $this->httpBroker->deleteRequest($updatedUrl);
$response = $this->restClient->deleteRequest($updatedUrl);
return $response;
}
public function getListMembers($listAddress, $filterParams = array()){
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/members";
$response = $this->httpBroker->getRequest($updatedUrl, $filterParams);
$response = $this->restClient->getRequest($updatedUrl, $filterParams);
return $response;
}
public function getListMember($listAddress, $memberAddress){
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/members/" . $memberAddress;
$response = $this->httpBroker->getRequest($updatedUrl);
$response = $this->restClient->getRequest($updatedUrl);
return $response;
}
public function addListMember($listAddress, $memberAddress, $name, $vars, $subscribed = true, $upsert = true){
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/members";
$postData = array('address' => $memberAddress, 'name' => $name, 'vars' => $vars, 'subscribed' => $subscribed, 'upsert' => $upsert);
$response = $this->httpBroker->postRequest($updatedUrl, $postData);
$response = $this->restClient->postRequest($updatedUrl, $postData);
return $response;
}
public function updateListMember($listAddress, $memberAddress, $name, $vars, $subscribed = true){
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/members/" . $memberAddress;
$postData = array('address' => $memberAddress, 'name' => $name, 'vars' => $vars, 'subscribed' => $subscribed);
$response = $this->httpBroker->putRequest($updatedUrl, $postData);
$response = $this->restClient->putRequest($updatedUrl, $postData);
return $response;
}
public function deleteListMember($listAddress, $memberAddress){
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/members/" . $memberAddress;
$response = $this->httpBroker->deleteRequest($updatedUrl);
$response = $this->restClient->deleteRequest($updatedUrl);
return $response;
}
public function getListStats($listAddress){
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/stats";
$response = $this->httpBroker->getRequest($updatedUrl);
$response = $this->restClient->getRequest($updatedUrl);
return $response;
}
}

View File

@ -7,18 +7,18 @@ namespace Mailgun\Logs;
class Logs{
private $httpBroker;
private $restClient;
private $workingDomain;
private $endpointUrl;
public function __construct($httpBroker){
$this->httpBroker = $httpBroker;
$this->endpointUrl = $this->httpBroker->returnWorkingDomain() . "/log";
public function __construct($restClient){
$this->restClient = $restClient;
$this->endpointUrl = $this->restClient->returnWorkingDomain() . "/log";
}
public function getLogs($limit, $skip){
$response = $this->httpBroker->getRequest($this->endpointUrl, array($limit, $skip));
$response = $this->restClient->getRequest($this->endpointUrl, array($limit, $skip));
return $response;
}
}

165
src/Mailgun/Mailgun.php Normal file
View File

@ -0,0 +1,165 @@
<?PHP
namespace Mailgun;
use Mailgun\Logs\Logs;
use Mailgun\Stats\Stats;
use Mailgun\Lists\Lists;
use Mailgun\Routes\Routes;
use Mailgun\Bounces\Bounces;
use Mailgun\Address\Address;
use Mailgun\Messages\Messages;
use Mailgun\Campaigns\Campaigns;
use Mailgun\Complaints\Complaints;
use Mailgun\Connection\RestClient;
use Mailgun\Unsubscribes\Unsubscribes;
class Mailgun{
/*
* Instantiate the RestClient to make it available to all
* classes created from here.
*/
private $apiKey;
protected $workingDomain;
protected $restClient;
protected $debugMode;
public function __construct($apiKey = null, $workingDomain = null, $debugMode = false){
if(isset($apiKey) && isset($workingDomain)){
$this->restClient = new RestClient($apiKey, $workingDomain, $debugMode);
}
else{
$this->apiKey = $apiKey;
$this->workingDomain = $workingDomain;
}
}
private function InstantiateNewClient($workingDomain, $apiKey){
if(isset($workingDomain) || isset($apiKey)){
if(isset($workingDomain)){
$this->workingDomain = $workingDomain;
}
if(isset($apiKey)){
$this->apiKey = $apiKey;
}
return true;
}
if(isset($this->restClient)){
return false;
}
else{
throw new Exception("A valid set of credentials is required to work with this endpoint.");
}
}
/*
* Factory methods for instantiating each endpoint class.
* If a new endpoint is added, create a factory method here.
* Each endpoint can accept a new domain and API key if you want to
* switch accounts or domains after instantiating the MailgunClient.
* This is for future support of RBAC.
*/
public function Messages($workingDomain = null, $apiKey = null){
if($this->InstantiateNewClient($workingDomain, $apiKey)){
$newClient = new RestClient($this->apiKey, $this->workingDomain, $this->debugMode);
return new Messages($newClient);
}
else{
return new Messages($this->restClient);
}
}
public function Unsubscribes($workingDomain = null, $apiKey = null){
if($this->InstantiateNewClient($workingDomain, $apiKey)){
$newClient = new RestClient($this->apiKey, $this->workingDomain, $this->debugMode);
return new Unsubscribes($newClient);
}
else{
return new Unsubscribes($this->restClient);
}
}
public function Complaints($workingDomain = null, $apiKey = null){
if($this->InstantiateNewClient($workingDomain, $apiKey)){
$newClient = new RestClient($this->apiKey, $this->workingDomain, $this->debugMode);
return new Complaints($newClient);
}
else{
return new Complaints($this->restClient);
}
}
public function Bounces($workingDomain = null, $apiKey = null){
if($this->InstantiateNewClient($workingDomain, $apiKey)){
$newClient = new RestClient($this->apiKey, $this->workingDomain, $this->debugMode);
return new Bounces($newClient);
}
else{
return new Bounces($this->restClient);
}
}
public function Stats($workingDomain = null, $apiKey = null){
if($this->InstantiateNewClient($workingDomain, $apiKey)){
$newClient = new RestClient($this->apiKey, $this->workingDomain, $this->debugMode);
return new Stats($newClient);
}
else{
return new Stats($this->restClient);
}
}
public function Logs($workingDomain = null, $apiKey = null){
if($this->InstantiateNewClient($workingDomain, $apiKey)){
$newClient = new RestClient($this->apiKey, $this->workingDomain, $this->debugMode);
return new Logs($newClient);
}
else{
return new Logs($this->restClient);
}
}
public function Routes($workingDomain = null, $apiKey = null){
if($this->InstantiateNewClient($workingDomain, $apiKey)){
$newClient = new RestClient($this->apiKey, $this->workingDomain, $this->debugMode);
return new Routes($newClient);
}
else{
return new Routes($this->restClient);
}
}
public function Campaigns($workingDomain = null, $apiKey = null){
if($this->InstantiateNewClient($workingDomain, $apiKey)){
$newClient = new RestClient($this->apiKey, $this->workingDomain, $this->debugMode);
return new Campaigns($newClient);
}
else{
return new Campaigns($this->restClient);
}
}
public function Lists($workingDomain = null, $apiKey = null){
if($this->InstantiateNewClient($workingDomain, $apiKey)){
$newClient = new RestClient($this->apiKey, $this->workingDomain, $this->debugMode);
return new Lists($newClient);
}
else{
return new Lists($this->restClient);
}
}
public function Address($workingDomain = null, $apiKey = null){
if($this->InstantiateNewClient($workingDomain, $apiKey)){
$newClient = new RestClient($this->apiKey, $this->workingDomain, $this->debugMode);
return new Address($newClient);
}
else{
return new Address($this->restClient);
}
}
}
?>

View File

@ -1,73 +0,0 @@
<?PHP
namespace Mailgun;
use Mailgun\Logs\Logs;
use Mailgun\Stats\Stats;
use Mailgun\Lists\Lists;
use Mailgun\Routes\Routes;
use Mailgun\Bounces\Bounces;
use Mailgun\Address\Address;
use Mailgun\Messages\Messages;
use Mailgun\Campaigns\Campaigns;
use Mailgun\Complaints\Complaints;
use Mailgun\Connection\HttpBroker;
use Mailgun\Unsubscribes\Unsubscribes;
class MailgunClient{
/*
* Instantiate the HttpBroker to make it available to all
* classes created from here.
*/
public function __construct($apiKey, $workingDomain, $debugMode = false){
$this->httpBroker = new HttpBroker($apiKey, $workingDomain, $debugMode);
}
/*
* Factory methods for instantiating each endpoint class.
* If a new endpoint is added, create a factory method here.
*/
public function Messages(){
return new Messages($this->httpBroker);
}
public function Unsubscribes(){
return new Unsubscribes($this->httpBroker);
}
public function Complaints(){
return new Complaints($this->httpBroker);
}
public function Bounces(){
return new Bounces($this->httpBroker);
}
public function Stats(){
return new Stats($this->httpBroker);
}
public function Logs(){
return new Logs($this->httpBroker);
}
public function Routes(){
return new Routes($this->httpBroker);
}
public function Campaigns(){
return new Campaigns($this->httpBroker);
}
public function Lists(){
return new Lists($this->httpBroker);
}
public function Address(){
return new Address($this->httpBroker);
}
}
?>

View File

@ -11,8 +11,8 @@ class BatchMessage extends MessageBuilder{
protected $batchRecipientAttributes;
protected $autoSend;
public function __construct($httpBroker, $autoSend){
parent::__construct($httpBroker);
public function __construct($restClient, $autoSend){
parent::__construct($restClient);
$this->batchRecipientAttributes = array();
$this->autoSend = $autoSend;
}
@ -68,7 +68,7 @@ class BatchMessage extends MessageBuilder{
}
else{
$this->message["recipient-variables"] = json_encode($this->batchRecipientAttributes);
$response = $this->httpBroker->postRequest($this->endpointUrl, $message, $files);
$response = $this->restClient->postRequest($this->endpointUrl, $message, $files);
$this->batchRecipientAttributes = array();
$this->toRecipientCount = 0;
unset($this->message["to"]);

View File

@ -18,11 +18,11 @@ class MessageBuilder extends Messages{
protected $campaignIdCount = 0;
protected $customOptionCount = 0;
protected $tagCount = 0;
protected $httpBroker;
protected $restClient;
public function __construct($httpBroker){
parent::__construct($httpBroker);
$this->httpBroker = $httpBroker;
public function __construct($restClient){
parent::__construct($restClient);
$this->restClient = $restClient;
}
public function addToRecipient($address, $attributes){

View File

@ -9,17 +9,17 @@ use Mailgun\Messages\Exceptions\MissingRequiredMIMEParameters;
class Messages{
protected $httpBroker;
protected $restClient;
protected $workingDomain;
protected $endpointUrl;
public function __construct($httpBroker){
$this->httpBroker = $httpBroker;
$this->workingDomain = $this->httpBroker->returnWorkingDomain();
public function __construct($restClient){
$this->restClient = $restClient;
$this->workingDomain = $this->restClient->returnWorkingDomain();
$this->endpointUrl = $this->workingDomain . "/messages";
}
public function sendMessage($message = array(), $files = array()){
public function send($message = array(), $files = array()){
if(count($message) < 1){
$message = $this->message;
$files = $this->files;
@ -37,7 +37,7 @@ class Messages{
throw new MissingRequiredMIMEParameters("You are missing the body of the message.");
}
else{
$response = $this->httpBroker->postRequest($this->endpointUrl, $message, $files);
$response = $this->restClient->postRequest($this->endpointUrl, $message, $files);
return $response;
}
}
@ -48,11 +48,11 @@ class Messages{
}
public function MessageBuilder(){
return new MessageBuilder($this->httpBroker);
return new MessageBuilder($this->restClient);
}
public function BatchMessage($autoSend = true){
return new BatchMessage($this->httpBroker, $autoSend);
return new BatchMessage($this->restClient, $autoSend);
}
}
?>

View File

@ -9,23 +9,23 @@ use Mailgun\Routes\Exceptions\InvalidParameter;
class Routes{
private $httpBroker;
private $restClient;
private $workingDomain;
private $endpointUrl;
public function __construct($httpBroker){
$this->httpBroker = $httpBroker;
public function __construct($restClient){
$this->restClient = $restClient;
$this->endpointUrl = "routes";
}
public function getRoutes($limit, $skip){
$response = $this->httpBroker->getRequest($this->endpointUrl, array($limit, $skip));
$response = $this->restClient->getRequest($this->endpointUrl, array($limit, $skip));
return $response;
}
public function getRoute($routeId){
$updatedUrl = $this->endpointUrl . "/" . $routeId;
$response = $this->httpBroker->getRequest($updatedUrl);
$response = $this->restClient->getRequest($updatedUrl);
return $response;
}
@ -48,7 +48,7 @@ class Routes{
$postData = array('priority' => $priority, 'description' => $description, 'expression' => $expression, 'action' => $action);
$response = $this->httpBroker->postRequest($this->endpointUrl, $postData);
$response = $this->restClient->postRequest($this->endpointUrl, $postData);
return $response;
}
@ -72,13 +72,13 @@ class Routes{
$updatedUrl = $this->endpointUrl . "/" . $routeId;
$response = $this->httpBroker->putRequest($updatedUrl, $postData);
$response = $this->restClient->putRequest($updatedUrl, $postData);
return $response;
}
public function deleteRoute($routeId){
$updatedUrl = $this->endpointUrl . "/" . $routeId;
$response = $this->httpBroker->deleteRequest($updatedUrl);
$response = $this->restClient->deleteRequest($updatedUrl);
return $response;
}
}

View File

@ -7,26 +7,26 @@ namespace Mailgun\Stats;
class Stats{
private $httpBroker;
private $restClient;
private $workingDomain;
private $endpointUrl;
private $statsEndpointUrl;
private $tagEndpointUrl;
public function __construct($httpBroker){
$this->httpBroker = $httpBroker;
$this->statsEndpointUrl = $this->httpBroker->returnWorkingDomain() . "/stats";
$this->tagEndpointUrl = $this->httpBroker->returnWorkingDomain() . "/tags";
public function __construct($restClient){
$this->restClient = $restClient;
$this->statsEndpointUrl = $this->restClient->returnWorkingDomain() . "/stats";
$this->tagEndpointUrl = $this->restClient->returnWorkingDomain() . "/tags";
}
public function deleteTag($tag){
$requestUrl = $this->tagEndpointUrl . "/" . urlencode($tag);
$response = $this->httpBroker->deleteRequest($requestUrl);
$response = $this->restClient->deleteRequest($requestUrl);
return $response;
}
public function getStats($filterParams = array()){
$response = $this->httpBroker->getRequest($this->statsEndpointUrl, $filterParams);
$response = $this->restClient->getRequest($this->statsEndpointUrl, $filterParams);
return $response;
}
}

View File

@ -7,13 +7,13 @@ namespace Mailgun\Unsubscribes;
class Unsubscribes{
private $httpBroker;
private $restClient;
private $workingDomain;
private $endpointUrl;
public function __construct($httpBroker){
$this->httpBroker = $httpBroker;
$this->endpointUrl = $this->httpBroker->returnWorkingDomain() . "/unsubscribes";
public function __construct($restClient){
$this->restClient = $restClient;
$this->endpointUrl = $this->restClient->returnWorkingDomain() . "/unsubscribes";
}
public function addAddress($unsubAddress, $unsubTag = NULL){
@ -23,23 +23,23 @@ class Unsubscribes{
else{
$postData = array("address" => $unsubAddress, "tag" => "*");
}
$response = $this->httpBroker->postRequest($this->endpointUrl, $postData);
$response = $this->restClient->postRequest($this->endpointUrl, $postData);
return $response;
}
public function deleteAddress($unsubAddress){
$requestUrl = $this->endpointUrl . "/" . urlencode($unsubAddress);
$response = $this->httpBroker->deleteRequest($requestUrl);
$response = $this->restClient->deleteRequest($requestUrl);
return $response;
}
public function getUnsubscribe($unsubAddress){
$requestUrl = $this->endpointUrl . "/" . urlencode($unsubAddress);
$response = $this->httpBroker->getRequest($requestUrl);
$response = $this->restClient->getRequest($requestUrl);
return $response;
}
public function getUnsubscribes($limit, $skip){
$response = $this->httpBroker->getRequest($this->endpointUrl, array($limit, $skip));
$response = $this->restClient->getRequest($this->endpointUrl, array($limit, $skip));
return $response;
}

View File

@ -1,9 +1,9 @@
<?php
namespace Mailgun\Tests\Connection;
use Mailgun\Connection\HttpBroker;
use Mailgun\Connection\RestClient;
class TestBroker extends HttpBroker{
class TestBroker extends RestClient{
private $apiKey;
protected $domain;
protected $debug;

View File

@ -8,10 +8,10 @@ use Mailgun\Tests\Connection\TestBroker;
class MailgunClientTest extends MailgunClient
{
protected $debug;
protected $httpBroker;
protected $restClient;
public function __construct($apiKey, $domain, $debug = false){
$this->httpBroker = new TestBroker($apiKey, $domain, $debug);
$this->restClient = new TestBroker($apiKey, $domain, $debug);
return true;
}
}