mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-26 06:46:08 +03:00
Modified and renamed HTTPBroker to RestClient.
This commit is contained in:
parent
ae1b570040
commit
1ff4357810
@ -7,19 +7,19 @@ namespace Mailgun\Address;
|
|||||||
|
|
||||||
class Address{
|
class Address{
|
||||||
|
|
||||||
private $httpBroker;
|
private $restClient;
|
||||||
private $workingDomain;
|
private $workingDomain;
|
||||||
private $endpointUrl;
|
private $endpointUrl;
|
||||||
|
|
||||||
public function __construct($httpBroker){
|
public function __construct($restClient){
|
||||||
$this->httpBroker = $httpBroker;
|
$this->restClient = $restClient;
|
||||||
$this->endpointUrl = "address";
|
$this->endpointUrl = "address";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateAddress($address){
|
public function getValidate($address){
|
||||||
$updatedUrl = $this->endpointUrl . "/validate";
|
$updatedUrl = $this->endpointUrl . "/validate";
|
||||||
$getData = array('address' => $address);
|
$getData = array('address' => $address);
|
||||||
$response = $this->httpBroker->getRequest($updatedUrl, $getData);
|
$response = $this->restClient->getRequest($updatedUrl, $getData);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,13 @@ $mgClient = new MailgunClient("pubkey-5ogiflzbnjrljiky49qxsiozqef5jxp7", "sample
|
|||||||
$address = $mgClient->Address();
|
$address = $mgClient->Address();
|
||||||
|
|
||||||
# Now, validate the address and store the result in $result.
|
# 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
|
Available Functions
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
`validateAddress(string $address);`
|
`getValidate(string $address);`
|
||||||
|
|
||||||
More Documentation
|
More Documentation
|
||||||
------------------
|
------------------
|
||||||
|
@ -7,13 +7,13 @@ namespace Mailgun\Bounces;
|
|||||||
|
|
||||||
class Bounces{
|
class Bounces{
|
||||||
|
|
||||||
private $httpBroker;
|
private $restClient;
|
||||||
private $workingDomain;
|
private $workingDomain;
|
||||||
private $endpointUrl;
|
private $endpointUrl;
|
||||||
|
|
||||||
public function __construct($httpBroker){
|
public function __construct($restClient){
|
||||||
$this->httpBroker = $httpBroker;
|
$this->restClient = $restClient;
|
||||||
$this->endpointUrl = $this->httpBroker->returnWorkingDomain() . "/bounces";
|
$this->endpointUrl = $this->restClient->returnWorkingDomain() . "/bounces";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addAddress($bounceAddress, $bounceCode, $bounceError = null){
|
public function addAddress($bounceAddress, $bounceCode, $bounceError = null){
|
||||||
@ -23,23 +23,23 @@ class Bounces{
|
|||||||
else{
|
else{
|
||||||
$postData = array("address" => $bounceAddress, "code" => $bounceCode);
|
$postData = array("address" => $bounceAddress, "code" => $bounceCode);
|
||||||
}
|
}
|
||||||
$response = $this->httpBroker->postRequest($this->endpointUrl, $postData);
|
$response = $this->restClient->postRequest($this->endpointUrl, $postData);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteAddress($bounceAddress){
|
public function deleteAddress($bounceAddress){
|
||||||
$requestUrl = $this->endpointUrl . "/" . urlencode($bounceAddress);
|
$requestUrl = $this->endpointUrl . "/" . urlencode($bounceAddress);
|
||||||
$response = $this->httpBroker->deleteRequest($requestUrl);
|
$response = $this->restClient->deleteRequest($requestUrl);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBounce($bounceAddress){
|
public function getBounce($bounceAddress){
|
||||||
$requestUrl = $this->endpointUrl . "/" . urlencode($bounceAddress);
|
$requestUrl = $this->endpointUrl . "/" . urlencode($bounceAddress);
|
||||||
$response = $this->httpBroker->getRequest($requestUrl);
|
$response = $this->restClient->getRequest($requestUrl);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
public function getBounces($limit, $skip){
|
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;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,24 +7,24 @@ namespace Mailgun\Campaigns;
|
|||||||
|
|
||||||
class Campaigns{
|
class Campaigns{
|
||||||
|
|
||||||
private $httpBroker;
|
private $restClient;
|
||||||
private $workingDomain;
|
private $workingDomain;
|
||||||
private $endpointUrl;
|
private $endpointUrl;
|
||||||
|
|
||||||
|
|
||||||
public function __construct($httpBroker){
|
public function __construct($restClient){
|
||||||
$this->httpBroker = $httpBroker;
|
$this->restClient = $restClient;
|
||||||
$this->endpointUrl = $this->httpBroker->returnWorkingDomain() . "/campaigns";
|
$this->endpointUrl = $this->restClient->returnWorkingDomain() . "/campaigns";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCampaigns($limit, $skip){
|
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;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCampaign($campaignId){
|
public function getCampaign($campaignId){
|
||||||
$updatedUrl = $this->endpointUrl . "/" . $campaignId;
|
$updatedUrl = $this->endpointUrl . "/" . $campaignId;
|
||||||
$response = $this->httpBroker->getRequest($updatedUrl);
|
$response = $this->restClient->getRequest($updatedUrl);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ class Campaigns{
|
|||||||
throw new InvalidParameter("The message ID is too long. Limit is 64 characters.");
|
throw new InvalidParameter("The message ID is too long. Limit is 64 characters.");
|
||||||
}
|
}
|
||||||
$postData = array('name' => $name, 'id' => $id);
|
$postData = array('name' => $name, 'id' => $id);
|
||||||
$response = $this->httpBroker->postRequest($this->endpointUrl, $postData);
|
$response = $this->restClient->postRequest($this->endpointUrl, $postData);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,49 +43,49 @@ class Campaigns{
|
|||||||
}
|
}
|
||||||
$updatedUrl = $this->endpointUrl . "/" . $campaignId;
|
$updatedUrl = $this->endpointUrl . "/" . $campaignId;
|
||||||
$postData = array('name' => $name, 'id' => $id);
|
$postData = array('name' => $name, 'id' => $id);
|
||||||
$response = $this->httpBroker->putRequest($updatedUrl, $postData);
|
$response = $this->restClient->putRequest($updatedUrl, $postData);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteCampaign($campaignId){
|
public function deleteCampaign($campaignId){
|
||||||
$updatedUrl = $this->endpointUrl . "/" . $campaignId;
|
$updatedUrl = $this->endpointUrl . "/" . $campaignId;
|
||||||
$response = $this->httpBroker->deleteRequest($updatedUrl);
|
$response = $this->restClient->deleteRequest($updatedUrl);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCampaignEvents($campaignId, $filterParams = array()){
|
public function getCampaignEvents($campaignId, $filterParams = array()){
|
||||||
$updatedUrl = $this->endpointUrl . "/" . $campaignId . "/events";
|
$updatedUrl = $this->endpointUrl . "/" . $campaignId . "/events";
|
||||||
$response = $this->httpBroker->getRequest($updatedUrl, $filterParams);
|
$response = $this->restClient->getRequest($updatedUrl, $filterParams);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCampaignStats($campaignId, $filterParams = array()){
|
public function getCampaignStats($campaignId, $filterParams = array()){
|
||||||
$updatedUrl = $this->endpointUrl . "/" . $campaignId . "/stats";
|
$updatedUrl = $this->endpointUrl . "/" . $campaignId . "/stats";
|
||||||
$response = $this->httpBroker->getRequest($updatedUrl, $filterParams);
|
$response = $this->restClient->getRequest($updatedUrl, $filterParams);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCampaignClicks($campaignId, $filterParams = array()){
|
public function getCampaignClicks($campaignId, $filterParams = array()){
|
||||||
$updatedUrl = $this->endpointUrl . "/" . $campaignId . "/clicks";
|
$updatedUrl = $this->endpointUrl . "/" . $campaignId . "/clicks";
|
||||||
$response = $this->httpBroker->getRequest($updatedUrl, $filterParams);
|
$response = $this->restClient->getRequest($updatedUrl, $filterParams);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCampaignOpens($campaignId, $filterParams = array()){
|
public function getCampaignOpens($campaignId, $filterParams = array()){
|
||||||
$updatedUrl = $this->endpointUrl . "/" . $campaignId . "/opens";
|
$updatedUrl = $this->endpointUrl . "/" . $campaignId . "/opens";
|
||||||
$response = $this->httpBroker->getRequest($updatedUrl, $filterParams);
|
$response = $this->restClient->getRequest($updatedUrl, $filterParams);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCampaignUnsubscribes($campaignId, $filterParams = array()){
|
public function getCampaignUnsubscribes($campaignId, $filterParams = array()){
|
||||||
$updatedUrl = $this->endpointUrl . "/" . $campaignId . "/unsubscribes";
|
$updatedUrl = $this->endpointUrl . "/" . $campaignId . "/unsubscribes";
|
||||||
$response = $this->httpBroker->getRequest($updatedUrl, $filterParams);
|
$response = $this->restClient->getRequest($updatedUrl, $filterParams);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCampaignComplaints($campaignId, $filterParams = array()){
|
public function getCampaignComplaints($campaignId, $filterParams = array()){
|
||||||
$updatedUrl = $this->endpointUrl . "/" . $campaignId . "/clicks";
|
$updatedUrl = $this->endpointUrl . "/" . $campaignId . "/clicks";
|
||||||
$response = $this->httpBroker->getRequest($updatedUrl, $filterParams);
|
$response = $this->restClient->getRequest($updatedUrl, $filterParams);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,34 +7,34 @@ namespace Mailgun\Complaints;
|
|||||||
|
|
||||||
class Complaints{
|
class Complaints{
|
||||||
|
|
||||||
private $httpBroker;
|
private $restClient;
|
||||||
private $workingDomain;
|
private $workingDomain;
|
||||||
private $endpointUrl;
|
private $endpointUrl;
|
||||||
|
|
||||||
public function __construct($httpBroker){
|
public function __construct($restClient){
|
||||||
$this->httpBroker = $httpBroker;
|
$this->restClient = $restClient;
|
||||||
$this->endpointUrl = $this->httpBroker->returnWorkingDomain() . "/complaints";
|
$this->endpointUrl = $this->restClient->returnWorkingDomain() . "/complaints";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addAddress($spamAddress){
|
public function addAddress($spamAddress){
|
||||||
$postData = array("address" => $spamAddress);
|
$postData = array("address" => $spamAddress);
|
||||||
$response = $this->httpBroker->postRequest($this->endpointUrl, $postData);
|
$response = $this->restClient->postRequest($this->endpointUrl, $postData);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteAddress($spamAddress){
|
public function deleteAddress($spamAddress){
|
||||||
$requestUrl = $this->endpointUrl . "/" . urlencode($spamAddress);
|
$requestUrl = $this->endpointUrl . "/" . urlencode($spamAddress);
|
||||||
$response = $this->httpBroker->deleteRequest($requestUrl);
|
$response = $this->restClient->deleteRequest($requestUrl);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getComplaint($spamAddress){
|
public function getComplaint($spamAddress){
|
||||||
$requestUrl = $this->endpointUrl . "/" . urlencode($spamAddress);
|
$requestUrl = $this->endpointUrl . "/" . urlencode($spamAddress);
|
||||||
$response = $this->httpBroker->getRequest($requestUrl);
|
$response = $this->restClient->getRequest($requestUrl);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
public function getComplaints($limit, $skip){
|
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;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ use Mailgun\Connection\Exceptions\NoDomainsConfigured;
|
|||||||
use Mailgun\Connection\Exceptions\MissingRequiredMIMEParameters;
|
use Mailgun\Connection\Exceptions\MissingRequiredMIMEParameters;
|
||||||
use Mailgun\Connection\Exceptions\MissingEndpoint;
|
use Mailgun\Connection\Exceptions\MissingEndpoint;
|
||||||
|
|
||||||
class HttpBroker{
|
class RestClient{
|
||||||
|
|
||||||
private $apiKey;
|
private $apiKey;
|
||||||
protected $workingDomain;
|
protected $workingDomain;
|
@ -7,72 +7,72 @@ namespace Mailgun\Lists;
|
|||||||
|
|
||||||
class Lists{
|
class Lists{
|
||||||
|
|
||||||
private $httpBroker;
|
private $restClient;
|
||||||
private $workingDomain;
|
private $workingDomain;
|
||||||
private $endpointUrl;
|
private $endpointUrl;
|
||||||
|
|
||||||
|
|
||||||
public function __construct($httpBroker){
|
public function __construct($restClient){
|
||||||
$this->httpBroker = $httpBroker;
|
$this->restClient = $restClient;
|
||||||
$this->endpointUrl = "lists";
|
$this->endpointUrl = "lists";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLists($limit, $skip){
|
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;
|
return $response;
|
||||||
}
|
}
|
||||||
public function getList($listAddress){
|
public function getList($listAddress){
|
||||||
$updatedUrl = $this->endpointUrl . "/" . $listAddress;
|
$updatedUrl = $this->endpointUrl . "/" . $listAddress;
|
||||||
$response = $this->httpBroker->getRequest($updatedUrl);
|
$response = $this->restClient->getRequest($updatedUrl);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
public function addList($listAddress, $name, $description, $access_level){
|
public function addList($listAddress, $name, $description, $access_level){
|
||||||
$postData = array('address' => $listAddress, 'name' => $name, 'description' => $description, 'access_level' => $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;
|
return $response;
|
||||||
}
|
}
|
||||||
public function updateList($listAddress, $name, $description, $access_level){
|
public function updateList($listAddress, $name, $description, $access_level){
|
||||||
$updatedUrl = $this->endpointUrl . "/" . $listAddress;
|
$updatedUrl = $this->endpointUrl . "/" . $listAddress;
|
||||||
$postData = array('address' => $listAddress, 'name' => $name, 'description' => $description, 'access_level' => $access_level);
|
$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;
|
return $response;
|
||||||
}
|
}
|
||||||
public function deleteList($listAddress){
|
public function deleteList($listAddress){
|
||||||
$updatedUrl = $this->endpointUrl . "/" . $listAddress;
|
$updatedUrl = $this->endpointUrl . "/" . $listAddress;
|
||||||
$response = $this->httpBroker->deleteRequest($updatedUrl);
|
$response = $this->restClient->deleteRequest($updatedUrl);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
public function getListMembers($listAddress, $filterParams = array()){
|
public function getListMembers($listAddress, $filterParams = array()){
|
||||||
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/members";
|
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/members";
|
||||||
$response = $this->httpBroker->getRequest($updatedUrl, $filterParams);
|
$response = $this->restClient->getRequest($updatedUrl, $filterParams);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
public function getListMember($listAddress, $memberAddress){
|
public function getListMember($listAddress, $memberAddress){
|
||||||
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/members/" . $memberAddress;
|
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/members/" . $memberAddress;
|
||||||
$response = $this->httpBroker->getRequest($updatedUrl);
|
$response = $this->restClient->getRequest($updatedUrl);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
public function addListMember($listAddress, $memberAddress, $name, $vars, $subscribed = true, $upsert = true){
|
public function addListMember($listAddress, $memberAddress, $name, $vars, $subscribed = true, $upsert = true){
|
||||||
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/members";
|
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/members";
|
||||||
$postData = array('address' => $memberAddress, 'name' => $name, 'vars' => $vars, 'subscribed' => $subscribed, 'upsert' => $upsert);
|
$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;
|
return $response;
|
||||||
}
|
}
|
||||||
public function updateListMember($listAddress, $memberAddress, $name, $vars, $subscribed = true){
|
public function updateListMember($listAddress, $memberAddress, $name, $vars, $subscribed = true){
|
||||||
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/members/" . $memberAddress;
|
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/members/" . $memberAddress;
|
||||||
$postData = array('address' => $memberAddress, 'name' => $name, 'vars' => $vars, 'subscribed' => $subscribed);
|
$postData = array('address' => $memberAddress, 'name' => $name, 'vars' => $vars, 'subscribed' => $subscribed);
|
||||||
$response = $this->httpBroker->putRequest($updatedUrl, $postData);
|
$response = $this->restClient->putRequest($updatedUrl, $postData);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
public function deleteListMember($listAddress, $memberAddress){
|
public function deleteListMember($listAddress, $memberAddress){
|
||||||
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/members/" . $memberAddress;
|
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/members/" . $memberAddress;
|
||||||
$response = $this->httpBroker->deleteRequest($updatedUrl);
|
$response = $this->restClient->deleteRequest($updatedUrl);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
public function getListStats($listAddress){
|
public function getListStats($listAddress){
|
||||||
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/stats";
|
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/stats";
|
||||||
$response = $this->httpBroker->getRequest($updatedUrl);
|
$response = $this->restClient->getRequest($updatedUrl);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,18 +7,18 @@ namespace Mailgun\Logs;
|
|||||||
|
|
||||||
class Logs{
|
class Logs{
|
||||||
|
|
||||||
private $httpBroker;
|
private $restClient;
|
||||||
private $workingDomain;
|
private $workingDomain;
|
||||||
private $endpointUrl;
|
private $endpointUrl;
|
||||||
|
|
||||||
|
|
||||||
public function __construct($httpBroker){
|
public function __construct($restClient){
|
||||||
$this->httpBroker = $httpBroker;
|
$this->restClient = $restClient;
|
||||||
$this->endpointUrl = $this->httpBroker->returnWorkingDomain() . "/log";
|
$this->endpointUrl = $this->restClient->returnWorkingDomain() . "/log";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLogs($limit, $skip){
|
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;
|
return $response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
165
src/Mailgun/Mailgun.php
Normal file
165
src/Mailgun/Mailgun.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
@ -11,8 +11,8 @@ class BatchMessage extends MessageBuilder{
|
|||||||
protected $batchRecipientAttributes;
|
protected $batchRecipientAttributes;
|
||||||
protected $autoSend;
|
protected $autoSend;
|
||||||
|
|
||||||
public function __construct($httpBroker, $autoSend){
|
public function __construct($restClient, $autoSend){
|
||||||
parent::__construct($httpBroker);
|
parent::__construct($restClient);
|
||||||
$this->batchRecipientAttributes = array();
|
$this->batchRecipientAttributes = array();
|
||||||
$this->autoSend = $autoSend;
|
$this->autoSend = $autoSend;
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ class BatchMessage extends MessageBuilder{
|
|||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$this->message["recipient-variables"] = json_encode($this->batchRecipientAttributes);
|
$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->batchRecipientAttributes = array();
|
||||||
$this->toRecipientCount = 0;
|
$this->toRecipientCount = 0;
|
||||||
unset($this->message["to"]);
|
unset($this->message["to"]);
|
||||||
|
@ -18,11 +18,11 @@ class MessageBuilder extends Messages{
|
|||||||
protected $campaignIdCount = 0;
|
protected $campaignIdCount = 0;
|
||||||
protected $customOptionCount = 0;
|
protected $customOptionCount = 0;
|
||||||
protected $tagCount = 0;
|
protected $tagCount = 0;
|
||||||
protected $httpBroker;
|
protected $restClient;
|
||||||
|
|
||||||
public function __construct($httpBroker){
|
public function __construct($restClient){
|
||||||
parent::__construct($httpBroker);
|
parent::__construct($restClient);
|
||||||
$this->httpBroker = $httpBroker;
|
$this->restClient = $restClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addToRecipient($address, $attributes){
|
public function addToRecipient($address, $attributes){
|
||||||
|
@ -9,17 +9,17 @@ use Mailgun\Messages\Exceptions\MissingRequiredMIMEParameters;
|
|||||||
|
|
||||||
class Messages{
|
class Messages{
|
||||||
|
|
||||||
protected $httpBroker;
|
protected $restClient;
|
||||||
protected $workingDomain;
|
protected $workingDomain;
|
||||||
protected $endpointUrl;
|
protected $endpointUrl;
|
||||||
|
|
||||||
public function __construct($httpBroker){
|
public function __construct($restClient){
|
||||||
$this->httpBroker = $httpBroker;
|
$this->restClient = $restClient;
|
||||||
$this->workingDomain = $this->httpBroker->returnWorkingDomain();
|
$this->workingDomain = $this->restClient->returnWorkingDomain();
|
||||||
$this->endpointUrl = $this->workingDomain . "/messages";
|
$this->endpointUrl = $this->workingDomain . "/messages";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sendMessage($message = array(), $files = array()){
|
public function send($message = array(), $files = array()){
|
||||||
if(count($message) < 1){
|
if(count($message) < 1){
|
||||||
$message = $this->message;
|
$message = $this->message;
|
||||||
$files = $this->files;
|
$files = $this->files;
|
||||||
@ -37,7 +37,7 @@ class Messages{
|
|||||||
throw new MissingRequiredMIMEParameters("You are missing the body of the message.");
|
throw new MissingRequiredMIMEParameters("You are missing the body of the message.");
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$response = $this->httpBroker->postRequest($this->endpointUrl, $message, $files);
|
$response = $this->restClient->postRequest($this->endpointUrl, $message, $files);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -48,11 +48,11 @@ class Messages{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function MessageBuilder(){
|
public function MessageBuilder(){
|
||||||
return new MessageBuilder($this->httpBroker);
|
return new MessageBuilder($this->restClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function BatchMessage($autoSend = true){
|
public function BatchMessage($autoSend = true){
|
||||||
return new BatchMessage($this->httpBroker, $autoSend);
|
return new BatchMessage($this->restClient, $autoSend);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
@ -9,23 +9,23 @@ use Mailgun\Routes\Exceptions\InvalidParameter;
|
|||||||
|
|
||||||
class Routes{
|
class Routes{
|
||||||
|
|
||||||
private $httpBroker;
|
private $restClient;
|
||||||
private $workingDomain;
|
private $workingDomain;
|
||||||
private $endpointUrl;
|
private $endpointUrl;
|
||||||
|
|
||||||
public function __construct($httpBroker){
|
public function __construct($restClient){
|
||||||
$this->httpBroker = $httpBroker;
|
$this->restClient = $restClient;
|
||||||
$this->endpointUrl = "routes";
|
$this->endpointUrl = "routes";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRoutes($limit, $skip){
|
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;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRoute($routeId){
|
public function getRoute($routeId){
|
||||||
$updatedUrl = $this->endpointUrl . "/" . $routeId;
|
$updatedUrl = $this->endpointUrl . "/" . $routeId;
|
||||||
$response = $this->httpBroker->getRequest($updatedUrl);
|
$response = $this->restClient->getRequest($updatedUrl);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ class Routes{
|
|||||||
|
|
||||||
$postData = array('priority' => $priority, 'description' => $description, 'expression' => $expression, 'action' => $action);
|
$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;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,13 +72,13 @@ class Routes{
|
|||||||
|
|
||||||
$updatedUrl = $this->endpointUrl . "/" . $routeId;
|
$updatedUrl = $this->endpointUrl . "/" . $routeId;
|
||||||
|
|
||||||
$response = $this->httpBroker->putRequest($updatedUrl, $postData);
|
$response = $this->restClient->putRequest($updatedUrl, $postData);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteRoute($routeId){
|
public function deleteRoute($routeId){
|
||||||
$updatedUrl = $this->endpointUrl . "/" . $routeId;
|
$updatedUrl = $this->endpointUrl . "/" . $routeId;
|
||||||
$response = $this->httpBroker->deleteRequest($updatedUrl);
|
$response = $this->restClient->deleteRequest($updatedUrl);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,26 +7,26 @@ namespace Mailgun\Stats;
|
|||||||
|
|
||||||
class Stats{
|
class Stats{
|
||||||
|
|
||||||
private $httpBroker;
|
private $restClient;
|
||||||
private $workingDomain;
|
private $workingDomain;
|
||||||
private $endpointUrl;
|
private $endpointUrl;
|
||||||
private $statsEndpointUrl;
|
private $statsEndpointUrl;
|
||||||
private $tagEndpointUrl;
|
private $tagEndpointUrl;
|
||||||
|
|
||||||
public function __construct($httpBroker){
|
public function __construct($restClient){
|
||||||
$this->httpBroker = $httpBroker;
|
$this->restClient = $restClient;
|
||||||
$this->statsEndpointUrl = $this->httpBroker->returnWorkingDomain() . "/stats";
|
$this->statsEndpointUrl = $this->restClient->returnWorkingDomain() . "/stats";
|
||||||
$this->tagEndpointUrl = $this->httpBroker->returnWorkingDomain() . "/tags";
|
$this->tagEndpointUrl = $this->restClient->returnWorkingDomain() . "/tags";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteTag($tag){
|
public function deleteTag($tag){
|
||||||
$requestUrl = $this->tagEndpointUrl . "/" . urlencode($tag);
|
$requestUrl = $this->tagEndpointUrl . "/" . urlencode($tag);
|
||||||
$response = $this->httpBroker->deleteRequest($requestUrl);
|
$response = $this->restClient->deleteRequest($requestUrl);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getStats($filterParams = array()){
|
public function getStats($filterParams = array()){
|
||||||
$response = $this->httpBroker->getRequest($this->statsEndpointUrl, $filterParams);
|
$response = $this->restClient->getRequest($this->statsEndpointUrl, $filterParams);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,13 +7,13 @@ namespace Mailgun\Unsubscribes;
|
|||||||
|
|
||||||
class Unsubscribes{
|
class Unsubscribes{
|
||||||
|
|
||||||
private $httpBroker;
|
private $restClient;
|
||||||
private $workingDomain;
|
private $workingDomain;
|
||||||
private $endpointUrl;
|
private $endpointUrl;
|
||||||
|
|
||||||
public function __construct($httpBroker){
|
public function __construct($restClient){
|
||||||
$this->httpBroker = $httpBroker;
|
$this->restClient = $restClient;
|
||||||
$this->endpointUrl = $this->httpBroker->returnWorkingDomain() . "/unsubscribes";
|
$this->endpointUrl = $this->restClient->returnWorkingDomain() . "/unsubscribes";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addAddress($unsubAddress, $unsubTag = NULL){
|
public function addAddress($unsubAddress, $unsubTag = NULL){
|
||||||
@ -23,23 +23,23 @@ class Unsubscribes{
|
|||||||
else{
|
else{
|
||||||
$postData = array("address" => $unsubAddress, "tag" => "*");
|
$postData = array("address" => $unsubAddress, "tag" => "*");
|
||||||
}
|
}
|
||||||
$response = $this->httpBroker->postRequest($this->endpointUrl, $postData);
|
$response = $this->restClient->postRequest($this->endpointUrl, $postData);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteAddress($unsubAddress){
|
public function deleteAddress($unsubAddress){
|
||||||
$requestUrl = $this->endpointUrl . "/" . urlencode($unsubAddress);
|
$requestUrl = $this->endpointUrl . "/" . urlencode($unsubAddress);
|
||||||
$response = $this->httpBroker->deleteRequest($requestUrl);
|
$response = $this->restClient->deleteRequest($requestUrl);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUnsubscribe($unsubAddress){
|
public function getUnsubscribe($unsubAddress){
|
||||||
$requestUrl = $this->endpointUrl . "/" . urlencode($unsubAddress);
|
$requestUrl = $this->endpointUrl . "/" . urlencode($unsubAddress);
|
||||||
$response = $this->httpBroker->getRequest($requestUrl);
|
$response = $this->restClient->getRequest($requestUrl);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
public function getUnsubscribes($limit, $skip){
|
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;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Mailgun\Tests\Connection;
|
namespace Mailgun\Tests\Connection;
|
||||||
|
|
||||||
use Mailgun\Connection\HttpBroker;
|
use Mailgun\Connection\RestClient;
|
||||||
|
|
||||||
class TestBroker extends HttpBroker{
|
class TestBroker extends RestClient{
|
||||||
private $apiKey;
|
private $apiKey;
|
||||||
protected $domain;
|
protected $domain;
|
||||||
protected $debug;
|
protected $debug;
|
||||||
|
@ -8,10 +8,10 @@ use Mailgun\Tests\Connection\TestBroker;
|
|||||||
class MailgunClientTest extends MailgunClient
|
class MailgunClientTest extends MailgunClient
|
||||||
{
|
{
|
||||||
protected $debug;
|
protected $debug;
|
||||||
protected $httpBroker;
|
protected $restClient;
|
||||||
|
|
||||||
public function __construct($apiKey, $domain, $debug = false){
|
public function __construct($apiKey, $domain, $debug = false){
|
||||||
$this->httpBroker = new TestBroker($apiKey, $domain, $debug);
|
$this->restClient = new TestBroker($apiKey, $domain, $debug);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user