mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2025-02-06 08:19:25 +03:00
Added multiple new endpoints and their respective tests!
This commit is contained in:
parent
8bd66e1d39
commit
762bfde571
46
src/Mailgun/Bounces/Bounces.php
Normal file
46
src/Mailgun/Bounces/Bounces.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?PHP
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Bounces.php - Processing Bounces.
|
||||||
|
*/
|
||||||
|
namespace Mailgun\Bounces;
|
||||||
|
|
||||||
|
class Bounces{
|
||||||
|
|
||||||
|
private $httpBroker;
|
||||||
|
private $workingDomain;
|
||||||
|
private $endpointUrl;
|
||||||
|
|
||||||
|
public function __construct($httpBroker){
|
||||||
|
$this->httpBroker = $httpBroker;
|
||||||
|
$this->endpointUrl = $this->httpBroker->returnWorkingDomain() . "/bounces";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addAddress($bounceAddress, $bounceCode, $bounceError = null){
|
||||||
|
if(isset($bounceError)){
|
||||||
|
$postData = array("address" => $bounceAddress, "code" => $bounceCode, "error" => $bounceError);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$postData = array("address" => $bounceAddress, "code" => $bounceCode);
|
||||||
|
}
|
||||||
|
$response = $this->httpBroker->postRequest($this->endpointUrl, $postData);
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteAddress($bounceAddress){
|
||||||
|
$requestUrl = $this->endpointUrl . "/" . urlencode($bounceAddress);
|
||||||
|
$response = $this->httpBroker->deleteRequest($requestUrl);
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBounce($bounceAddress){
|
||||||
|
$requestUrl = $this->endpointUrl . "/" . urlencode($bounceAddress);
|
||||||
|
$response = $this->httpBroker->getRequest($requestUrl);
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
public function getBounces($limit, $skip){
|
||||||
|
$response = $this->httpBroker->getRequest($this->endpointUrl, array($limit, $skip));
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
41
src/Mailgun/Complaints/Complaints.php
Normal file
41
src/Mailgun/Complaints/Complaints.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?PHP
|
||||||
|
|
||||||
|
/*
|
||||||
|
* SpamComplaints.php - Processing Spam Complaints.
|
||||||
|
*/
|
||||||
|
namespace Mailgun\Complaints;
|
||||||
|
|
||||||
|
class Complaints{
|
||||||
|
|
||||||
|
private $httpBroker;
|
||||||
|
private $workingDomain;
|
||||||
|
private $endpointUrl;
|
||||||
|
|
||||||
|
public function __construct($httpBroker){
|
||||||
|
$this->httpBroker = $httpBroker;
|
||||||
|
$this->endpointUrl = $this->httpBroker->returnWorkingDomain() . "/complaints";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addAddress($spamAddress){
|
||||||
|
$postData = array("address" => $spamAddress);
|
||||||
|
$response = $this->httpBroker->postRequest($this->endpointUrl, $postData);
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteAddress($spamAddress){
|
||||||
|
$requestUrl = $this->endpointUrl . "/" . urlencode($spamAddress);
|
||||||
|
$response = $this->httpBroker->deleteRequest($requestUrl);
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getComplaint($spamAddress){
|
||||||
|
$requestUrl = $this->endpointUrl . "/" . urlencode($spamAddress);
|
||||||
|
$response = $this->httpBroker->getRequest($requestUrl);
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
public function getComplaints($limit, $skip){
|
||||||
|
$response = $this->httpBroker->getRequest($this->endpointUrl, array($limit, $skip));
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -33,16 +33,15 @@ class HttpBroker{
|
|||||||
public function postRequest($endpointUrl, $postData = array(), $files = array()){
|
public function postRequest($endpointUrl, $postData = array(), $files = array()){
|
||||||
if($this->debug){
|
if($this->debug){
|
||||||
$this->client = new Guzzle('https://api.ninomail.com/' . $this->apiVersion . '/', array('ssl.certificate_authority' => false));
|
$this->client = new Guzzle('https://api.ninomail.com/' . $this->apiVersion . '/', array('ssl.certificate_authority' => false));
|
||||||
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
|
|
||||||
$this->client->setDefaultOption('exceptions', true);
|
|
||||||
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$this->client = new Guzzle('https://' . $this->apiEndpoint . '/' . $this->apiVersion . '/');
|
$this->client = new Guzzle('https://' . $this->apiEndpoint . '/' . $this->apiVersion . '/');
|
||||||
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
|
|
||||||
$this->client->setDefaultOption('exceptions', false);
|
|
||||||
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
|
||||||
|
$this->client->setDefaultOption('exceptions', true);
|
||||||
|
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
|
||||||
|
|
||||||
$request = $this->client->post($endpointUrl, array(), $postData);
|
$request = $this->client->post($endpointUrl, array(), $postData);
|
||||||
|
|
||||||
if(isset($files["attachment"])){
|
if(isset($files["attachment"])){
|
||||||
@ -63,6 +62,13 @@ class HttpBroker{
|
|||||||
$result->$key = $value;
|
$result->$key = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elseif($httpStatusCode == 401){
|
||||||
|
throw new InvalidCredentials("Your credentials are incorrect.");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
throw new GenericHTTPError("A generic HTTP Error has occurred! Check your network connection and try again.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$result->http_response_code = $httpResponeCode;
|
$result->http_response_code = $httpResponeCode;
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
@ -70,16 +76,15 @@ class HttpBroker{
|
|||||||
public function getRequest($endpointUrl, $queryString = array()){
|
public function getRequest($endpointUrl, $queryString = array()){
|
||||||
if($this->debug){
|
if($this->debug){
|
||||||
$this->client = new Guzzle('https://api.ninomail.com/' . $this->apiVersion . '/', array('ssl.certificate_authority' => false));
|
$this->client = new Guzzle('https://api.ninomail.com/' . $this->apiVersion . '/', array('ssl.certificate_authority' => false));
|
||||||
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
|
|
||||||
$this->client->setDefaultOption('exceptions', false);
|
|
||||||
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$this->client = new Guzzle('https://' . $this->apiEndpoint . '/' . $this->apiVersion . '/');
|
$this->client = new Guzzle('https://' . $this->apiEndpoint . '/' . $this->apiVersion . '/');
|
||||||
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
|
|
||||||
$this->client->setDefaultOption('exceptions', false);
|
|
||||||
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
|
||||||
|
$this->client->setDefaultOption('exceptions', true);
|
||||||
|
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
|
||||||
|
|
||||||
$request = $this->client->get($endpointUrl, $queryString);
|
$request = $this->client->get($endpointUrl, $queryString);
|
||||||
$response = $request->send();
|
$response = $request->send();
|
||||||
$httpResponeCode = $response->getStatusCode();
|
$httpResponeCode = $response->getStatusCode();
|
||||||
@ -89,6 +94,13 @@ class HttpBroker{
|
|||||||
$result->$key = $value;
|
$result->$key = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elseif($httpStatusCode == 401){
|
||||||
|
throw new InvalidCredentials("Your credentials are incorrect.");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
throw new GenericHTTPError("A generic HTTP Error has occurred! Check your network connection and try again.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$result->http_response_code = $httpResponeCode;
|
$result->http_response_code = $httpResponeCode;
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
@ -96,16 +108,15 @@ class HttpBroker{
|
|||||||
public function deleteRequest($endpointUrl){
|
public function deleteRequest($endpointUrl){
|
||||||
if($this->debug){
|
if($this->debug){
|
||||||
$this->client = new Guzzle('https://api.ninomail.com/' . $this->apiVersion . '/', array('ssl.certificate_authority' => false));
|
$this->client = new Guzzle('https://api.ninomail.com/' . $this->apiVersion . '/', array('ssl.certificate_authority' => false));
|
||||||
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
|
|
||||||
$this->client->setDefaultOption('exceptions', false);
|
|
||||||
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$this->client = new Guzzle('https://' . $this->apiEndpoint . '/' . $this->apiVersion . '/');
|
$this->client = new Guzzle('https://' . $this->apiEndpoint . '/' . $this->apiVersion . '/');
|
||||||
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
|
|
||||||
$this->client->setDefaultOption('exceptions', false);
|
|
||||||
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
|
||||||
|
$this->client->setDefaultOption('exceptions', true);
|
||||||
|
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
|
||||||
|
|
||||||
$request = $this->client->delete($endpointUrl);
|
$request = $this->client->delete($endpointUrl);
|
||||||
$response = $request->send();
|
$response = $request->send();
|
||||||
$httpResponeCode = $response->getStatusCode();
|
$httpResponeCode = $response->getStatusCode();
|
||||||
@ -115,6 +126,13 @@ class HttpBroker{
|
|||||||
$result->$key = $value;
|
$result->$key = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elseif($httpStatusCode == 401){
|
||||||
|
throw new InvalidCredentials("Your credentials are incorrect.");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
throw new GenericHTTPError("A generic HTTP Error has occurred! Check your network connection and try again.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$result->http_response_code = $httpResponeCode;
|
$result->http_response_code = $httpResponeCode;
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
@ -122,16 +140,14 @@ class HttpBroker{
|
|||||||
public function putRequest($endpointUrl, $queryString){
|
public function putRequest($endpointUrl, $queryString){
|
||||||
if($this->debug){
|
if($this->debug){
|
||||||
$this->client = new Guzzle('https://api.ninomail.com/' . $this->apiVersion . '/', array('ssl.certificate_authority' => false));
|
$this->client = new Guzzle('https://api.ninomail.com/' . $this->apiVersion . '/', array('ssl.certificate_authority' => false));
|
||||||
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
|
|
||||||
$this->client->setDefaultOption('exceptions', false);
|
|
||||||
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$this->client = new Guzzle('https://' . $this->apiEndpoint . '/' . $this->apiVersion . '/');
|
$this->client = new Guzzle('https://' . $this->apiEndpoint . '/' . $this->apiVersion . '/');
|
||||||
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
|
|
||||||
$this->client->setDefaultOption('exceptions', false);
|
|
||||||
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->client->setDefaultOption('auth', array ($this->apiUser, $this->apiKey));
|
||||||
|
$this->client->setDefaultOption('exceptions', true);
|
||||||
|
$this->client->setUserAgent($this->sdkUserAgent . '/' . $this->sdkVersion);
|
||||||
$request = $this->client->put($endpointUrl, $queryString);
|
$request = $this->client->put($endpointUrl, $queryString);
|
||||||
$response = $request->send();
|
$response = $request->send();
|
||||||
$httpResponeCode = $response->getStatusCode();
|
$httpResponeCode = $response->getStatusCode();
|
||||||
@ -141,6 +157,13 @@ class HttpBroker{
|
|||||||
$result->$key = $value;
|
$result->$key = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elseif($httpStatusCode == 401){
|
||||||
|
throw new InvalidCredentials("Your credentials are incorrect.");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
throw new GenericHTTPError("A generic HTTP Error has occurred! Check your network connection and try again.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$result->http_response_code = $httpResponeCode;
|
$result->http_response_code = $httpResponeCode;
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
24
src/Mailgun/Logs/Logs.php
Normal file
24
src/Mailgun/Logs/Logs.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?PHP
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Logs.php - Processing Logs.
|
||||||
|
*/
|
||||||
|
namespace Mailgun\Logs;
|
||||||
|
|
||||||
|
class Logs{
|
||||||
|
|
||||||
|
private $httpBroker;
|
||||||
|
private $workingDomain;
|
||||||
|
private $endpointUrl;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct($httpBroker){
|
||||||
|
$this->httpBroker = $httpBroker;
|
||||||
|
$this->endpointUrl = $this->httpBroker->returnWorkingDomain() . "/log";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLogs($limit, $skip){
|
||||||
|
$response = $this->httpBroker->getRequest($this->endpointUrl, array($limit, $skip));
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,10 @@ namespace Mailgun;
|
|||||||
use Mailgun\Connection\HttpBroker;
|
use Mailgun\Connection\HttpBroker;
|
||||||
use Mailgun\Unsubscribes\Unsubscribes;
|
use Mailgun\Unsubscribes\Unsubscribes;
|
||||||
use Mailgun\Messages\Messages;
|
use Mailgun\Messages\Messages;
|
||||||
|
use Mailgun\Complaints\Complaints;
|
||||||
|
use Mailgun\Bounces\Bounces;
|
||||||
|
use Mailgun\Stats\Stats;
|
||||||
|
use Mailgun\Logs\Logs;
|
||||||
|
|
||||||
|
|
||||||
use Mailgun\Connection\Exceptions\NoDomainsConfigured;
|
use Mailgun\Connection\Exceptions\NoDomainsConfigured;
|
||||||
@ -19,35 +23,6 @@ class MailgunClient{
|
|||||||
|
|
||||||
public function __construct($apiKey, $domain, $debug = false){
|
public function __construct($apiKey, $domain, $debug = false){
|
||||||
$this->httpBroker = new HttpBroker($apiKey, $domain, $debug);
|
$this->httpBroker = new HttpBroker($apiKey, $domain, $debug);
|
||||||
$this->validateCredentials();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function validateCredentials(){
|
|
||||||
$url = "domains";
|
|
||||||
|
|
||||||
$response = $this->httpBroker->getRequest($url);
|
|
||||||
|
|
||||||
$httpStatusCode = $response->http_response_code;
|
|
||||||
|
|
||||||
if($httpStatusCode == 200){
|
|
||||||
foreach ($response as $key => $value){
|
|
||||||
$object->$key = $value;
|
|
||||||
}
|
|
||||||
if($object->total_count > 0){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
throw new NoDomainsConfigured("You don't have any domains on your account.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elseif($httpStatusCode == 401){
|
|
||||||
throw new InvalidCredentials("Your credentials are incorrect.");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
throw new GenericHTTPError("A generic HTTP Error has occurred! Check your network connection and try again.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Factory Methods for Class Creation from MailgunClient
|
//Factory Methods for Class Creation from MailgunClient
|
||||||
@ -57,7 +32,18 @@ class MailgunClient{
|
|||||||
public function Unsubscribes(){
|
public function Unsubscribes(){
|
||||||
return new Unsubscribes($this->httpBroker);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
32
src/Mailgun/Stats/Stats.php
Normal file
32
src/Mailgun/Stats/Stats.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?PHP
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Stats.php - Processing Stats.
|
||||||
|
*/
|
||||||
|
namespace Mailgun\Stats;
|
||||||
|
|
||||||
|
class Stats{
|
||||||
|
|
||||||
|
private $httpBroker;
|
||||||
|
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 deleteTag($tag){
|
||||||
|
$requestUrl = $this->tagEndpointUrl . "/" . urlencode($tag);
|
||||||
|
$response = $this->httpBroker->deleteRequest($requestUrl);
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStats($limit, $skip){
|
||||||
|
$response = $this->httpBroker->getRequest($this->statsEndpointUrl, array($limit, $skip, $event, $start-date));
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
@ -33,12 +33,12 @@ class Unsubscribes{
|
|||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAddress($unsubAddress){
|
public function getUnsubscribe($unsubAddress){
|
||||||
$requestUrl = $this->endpointUrl . "/" . urlencode($unsubAddress);
|
$requestUrl = $this->endpointUrl . "/" . urlencode($unsubAddress);
|
||||||
$response = $this->httpBroker->getRequest($requestUrl);
|
$response = $this->httpBroker->getRequest($requestUrl);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
public function getAddresses($limit, $skip){
|
public function getUnsubscribes($limit, $skip){
|
||||||
$response = $this->httpBroker->getRequest($this->endpointUrl, array($limit, $skip));
|
$response = $this->httpBroker->getRequest($this->endpointUrl, array($limit, $skip));
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
40
tests/Mailgun/Tests/Bounces/BouncesTest.php
Normal file
40
tests/Mailgun/Tests/Bounces/BouncesTest.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?PHP
|
||||||
|
|
||||||
|
namespace Mailgun\Tests\Bounces;
|
||||||
|
|
||||||
|
use Mailgun\Tests\MailgunClientTest;
|
||||||
|
|
||||||
|
class BouncesTest extends \Mailgun\Tests\MailgunTestCase{
|
||||||
|
|
||||||
|
private $client;
|
||||||
|
|
||||||
|
public function setUp(){
|
||||||
|
$this->client = new MailgunClientTest("My-Super-Awesome-API-Key", "samples.mailgun.org", false);
|
||||||
|
|
||||||
|
}
|
||||||
|
public function testAddAddress(){
|
||||||
|
$client = $this->client->Bounces();
|
||||||
|
$response = $client->addAddress("test@samples.mailgun.org", 550, "This bounced!");
|
||||||
|
$httpCode = $response->http_response_code;
|
||||||
|
$this->assertEquals(200, $httpCode);
|
||||||
|
}
|
||||||
|
public function testDeleteAddress(){
|
||||||
|
$client = $this->client->Bounces();
|
||||||
|
$response = $client->deleteAddress("test@samples.mailgun.org");
|
||||||
|
$httpCode = $response->http_response_code;
|
||||||
|
$this->assertEquals(200, $httpCode);
|
||||||
|
}
|
||||||
|
public function testGetAddress(){
|
||||||
|
$client = $this->client->Bounces();
|
||||||
|
$response = $client->getBounce("test@samples.mailgun.org");
|
||||||
|
$httpCode = $response->http_response_code;
|
||||||
|
$this->assertEquals(200, $httpCode);
|
||||||
|
}
|
||||||
|
public function testGetAddresses(){
|
||||||
|
$client = $this->client->Bounces();
|
||||||
|
$response = $client->getBounces("1", "30");
|
||||||
|
$httpCode = $response->http_response_code;
|
||||||
|
$this->assertEquals(200, $httpCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
40
tests/Mailgun/Tests/Complaints/ComplaintsTest.php
Normal file
40
tests/Mailgun/Tests/Complaints/ComplaintsTest.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?PHP
|
||||||
|
|
||||||
|
namespace Mailgun\Tests\Complaints;
|
||||||
|
|
||||||
|
use Mailgun\Tests\MailgunClientTest;
|
||||||
|
|
||||||
|
class ComplaintsTest extends \Mailgun\Tests\MailgunTestCase{
|
||||||
|
|
||||||
|
private $client;
|
||||||
|
|
||||||
|
public function setUp(){
|
||||||
|
$this->client = new MailgunClientTest("My-Super-Awesome-API-Key", "samples.mailgun.org", false);
|
||||||
|
|
||||||
|
}
|
||||||
|
public function testAddAddress(){
|
||||||
|
$client = $this->client->Complaints();
|
||||||
|
$response = $client->addAddress("test@samples.mailgun.org");
|
||||||
|
$httpCode = $response->http_response_code;
|
||||||
|
$this->assertEquals(200, $httpCode);
|
||||||
|
}
|
||||||
|
public function testDeleteAddress(){
|
||||||
|
$client = $this->client->Complaints();
|
||||||
|
$response = $client->deleteAddress("test@samples.mailgun.org");
|
||||||
|
$httpCode = $response->http_response_code;
|
||||||
|
$this->assertEquals(200, $httpCode);
|
||||||
|
}
|
||||||
|
public function testGetAddress(){
|
||||||
|
$client = $this->client->Complaints();
|
||||||
|
$response = $client->getComplaint("test@samples.mailgun.org");
|
||||||
|
$httpCode = $response->http_response_code;
|
||||||
|
$this->assertEquals(200, $httpCode);
|
||||||
|
}
|
||||||
|
public function testGetAddresses(){
|
||||||
|
$client = $this->client->Complaints();
|
||||||
|
$response = $client->getComplaints("1", "30");
|
||||||
|
$httpCode = $response->http_response_code;
|
||||||
|
$this->assertEquals(200, $httpCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -8,11 +8,9 @@ class ConnectionTest extends \Mailgun\Tests\MailgunTestCase{
|
|||||||
private $client;
|
private $client;
|
||||||
|
|
||||||
public function setUp(){
|
public function setUp(){
|
||||||
$this->client = new MailgunClientTest("My-Super-Awesome-API-Key", "samples.mailgun.org", false);
|
|
||||||
}
|
}
|
||||||
public function testNewClientConnection(){
|
public function testNewClientInstantiation(){
|
||||||
$result = $this->client->validateCredentials();
|
$this->client = new MailgunClientTest("My-Super-Awesome-API-Key", "samples.mailgun.org", false);
|
||||||
$this->assertTrue($result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,26 @@ class TestBroker extends HttpBroker{
|
|||||||
}
|
}
|
||||||
$result->http_response_code = $httpResponseCode;
|
$result->http_response_code = $httpResponseCode;
|
||||||
}
|
}
|
||||||
|
elseif(preg_match("/\/complaints$/", $endpointUrl)){
|
||||||
|
$httpResponseCode = "200";
|
||||||
|
//$jsonResponseData = json_encode('{"message": "Address has been added to the unsubscribes table","address": "ev@mailgun.net"}');
|
||||||
|
if($httpResponseCode === 200){
|
||||||
|
foreach($jsonResponseData as $key => $value){
|
||||||
|
$result->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result->http_response_code = $httpResponseCode;
|
||||||
|
}
|
||||||
|
elseif(preg_match("/\/bounces$/", $endpointUrl)){
|
||||||
|
$httpResponseCode = "200";
|
||||||
|
//$jsonResponseData = json_encode('{"message": "Address has been added to the unsubscribes table","address": "ev@mailgun.net"}');
|
||||||
|
if($httpResponseCode === 200){
|
||||||
|
foreach($jsonResponseData as $key => $value){
|
||||||
|
$result->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result->http_response_code = $httpResponseCode;
|
||||||
|
}
|
||||||
else{
|
else{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -69,7 +89,42 @@ class TestBroker extends HttpBroker{
|
|||||||
}
|
}
|
||||||
elseif(preg_match("/\/unsubscribes/", $endpointUrl)){
|
elseif(preg_match("/\/unsubscribes/", $endpointUrl)){
|
||||||
$httpResponseCode = "200";
|
$httpResponseCode = "200";
|
||||||
$jsonResponseData = json_encode('{"total_count": 4,"items": [{"created_at": "Thu, 15 Mar 2012 08:35:02 GMT","tag": "*","id": "4f3b954a6addaa3e196735a2","address":"ev@mailgun.net"},{"created_at": "Thu, 15 Mar 2012 08:35:02 GMT","tag": "tag1","id": "4f3b954a6addaa3e1967359f","address":ev@mailgun.net"},{"created_at": "Wed, 01 Feb 2012 08:09:45 GMT","tag": "Testing Tag","id": "4f28f3494d532a3a823d0d9f","address": "alex@mailgun.net"},{"created_at": "Wed, 01 Feb 2012 08:09:38 GMT","tag": "*","id": "4f28f1024d532a3a823d0d68","address": "alex@mailgun.net"}]}');
|
if($httpResponseCode === 200){
|
||||||
|
foreach($jsonResponseData as $key => $value){
|
||||||
|
$result->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result->http_response_code = $httpResponseCode;
|
||||||
|
}
|
||||||
|
elseif(preg_match("/\/complaints/", $endpointUrl)){
|
||||||
|
$httpResponseCode = "200";
|
||||||
|
if($httpResponseCode === 200){
|
||||||
|
foreach($jsonResponseData as $key => $value){
|
||||||
|
$result->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result->http_response_code = $httpResponseCode;
|
||||||
|
}
|
||||||
|
elseif(preg_match("/\/bounces/", $endpointUrl)){
|
||||||
|
$httpResponseCode = "200";
|
||||||
|
if($httpResponseCode === 200){
|
||||||
|
foreach($jsonResponseData as $key => $value){
|
||||||
|
$result->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result->http_response_code = $httpResponseCode;
|
||||||
|
}
|
||||||
|
elseif(preg_match("/\/stats/", $endpointUrl)){
|
||||||
|
$httpResponseCode = "200";
|
||||||
|
if($httpResponseCode === 200){
|
||||||
|
foreach($jsonResponseData as $key => $value){
|
||||||
|
$result->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result->http_response_code = $httpResponseCode;
|
||||||
|
}
|
||||||
|
elseif(preg_match("/\/log/", $endpointUrl)){
|
||||||
|
$httpResponseCode = "200";
|
||||||
if($httpResponseCode === 200){
|
if($httpResponseCode === 200){
|
||||||
foreach($jsonResponseData as $key => $value){
|
foreach($jsonResponseData as $key => $value){
|
||||||
$result->$key = $value;
|
$result->$key = $value;
|
||||||
@ -100,6 +155,36 @@ class TestBroker extends HttpBroker{
|
|||||||
}
|
}
|
||||||
$result->http_response_code = $httpResponseCode;
|
$result->http_response_code = $httpResponseCode;
|
||||||
}
|
}
|
||||||
|
elseif(preg_match("/\/complaints\//", $endpointUrl)){
|
||||||
|
$httpResponseCode = "200";
|
||||||
|
$jsonResponseData = json_encode('{"message": "Unsubscribe event has been removed","address": "ev@mailgun.net"}');
|
||||||
|
if($httpResponseCode === 200){
|
||||||
|
foreach($jsonResponseData as $key => $value){
|
||||||
|
$result->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result->http_response_code = $httpResponseCode;
|
||||||
|
}
|
||||||
|
elseif(preg_match("/\/bounces\//", $endpointUrl)){
|
||||||
|
$httpResponseCode = "200";
|
||||||
|
$jsonResponseData = json_encode('{"message": "Unsubscribe event has been removed","address": "ev@mailgun.net"}');
|
||||||
|
if($httpResponseCode === 200){
|
||||||
|
foreach($jsonResponseData as $key => $value){
|
||||||
|
$result->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result->http_response_code = $httpResponseCode;
|
||||||
|
}
|
||||||
|
elseif(preg_match("/\/tags\//", $endpointUrl)){
|
||||||
|
$httpResponseCode = "200";
|
||||||
|
$jsonResponseData = json_encode('{"message": "Unsubscribe event has been removed","address": "ev@mailgun.net"}');
|
||||||
|
if($httpResponseCode === 200){
|
||||||
|
foreach($jsonResponseData as $key => $value){
|
||||||
|
$result->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result->http_response_code = $httpResponseCode;
|
||||||
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
public function putRequest($endpointUrl, $queryString){
|
public function putRequest($endpointUrl, $queryString){
|
||||||
|
22
tests/Mailgun/Tests/Logs/LogsTest.php
Normal file
22
tests/Mailgun/Tests/Logs/LogsTest.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?PHP
|
||||||
|
|
||||||
|
namespace Mailgun\Tests\Logs;
|
||||||
|
|
||||||
|
use Mailgun\Tests\MailgunClientTest;
|
||||||
|
|
||||||
|
class LogsTest extends \Mailgun\Tests\MailgunTestCase{
|
||||||
|
|
||||||
|
private $client;
|
||||||
|
|
||||||
|
public function setUp(){
|
||||||
|
$this->client = new MailgunClientTest("My-Super-Awesome-API-Key", "samples.mailgun.org", false);
|
||||||
|
|
||||||
|
}
|
||||||
|
public function testGetLogs(){
|
||||||
|
$client = $this->client->Logs();
|
||||||
|
$response = $client->getLogs("1", "30");
|
||||||
|
$httpCode = $response->http_response_code;
|
||||||
|
$this->assertEquals(200, $httpCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -12,7 +12,7 @@ class MailgunClientTest extends MailgunClient
|
|||||||
|
|
||||||
public function __construct($apiKey, $domain, $debug = false){
|
public function __construct($apiKey, $domain, $debug = false){
|
||||||
$this->httpBroker = new TestBroker($apiKey, $domain, $debug);
|
$this->httpBroker = new TestBroker($apiKey, $domain, $debug);
|
||||||
$this->validateCredentials();
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
28
tests/Mailgun/Tests/Stats/Stats.php
Normal file
28
tests/Mailgun/Tests/Stats/Stats.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?PHP
|
||||||
|
|
||||||
|
namespace Mailgun\Tests\Stats;
|
||||||
|
|
||||||
|
use Mailgun\Tests\MailgunClientTest;
|
||||||
|
|
||||||
|
class StatsTest extends \Mailgun\Tests\MailgunTestCase{
|
||||||
|
|
||||||
|
private $client;
|
||||||
|
|
||||||
|
public function setUp(){
|
||||||
|
$this->client = new MailgunClientTest("My-Super-Awesome-API-Key", "samples.mailgun.org", false);
|
||||||
|
|
||||||
|
}
|
||||||
|
public function testDeleteTag(){
|
||||||
|
$client = $this->client->Stats();
|
||||||
|
$response = $client->deleteTag("My-Tag");
|
||||||
|
$httpCode = $response->http_response_code;
|
||||||
|
$this->assertEquals(200, $httpCode);
|
||||||
|
}
|
||||||
|
public function testGetStats(){
|
||||||
|
$client = $this->client->Stats();
|
||||||
|
$response = $client->getStats("1", "30", "Sent", "10/10/10");
|
||||||
|
$httpCode = $response->http_response_code;
|
||||||
|
$this->assertEquals(200, $httpCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -13,26 +13,26 @@ class UnsubscribeTest extends \Mailgun\Tests\MailgunTestCase{
|
|||||||
|
|
||||||
}
|
}
|
||||||
public function testAddAddress(){
|
public function testAddAddress(){
|
||||||
$unsub = $this->client->Unsubscribes();
|
$client = $this->client->Unsubscribes();
|
||||||
$response = $unsub->addAddress("test@samples.mailgun.org");
|
$response = $client->addAddress("test@samples.mailgun.org");
|
||||||
$httpCode = $response->http_response_code;
|
$httpCode = $response->http_response_code;
|
||||||
$this->assertEquals(200, $httpCode);
|
$this->assertEquals(200, $httpCode);
|
||||||
}
|
}
|
||||||
public function testDeleteAddress(){
|
public function testDeleteAddress(){
|
||||||
$unsub = $this->client->Unsubscribes();
|
$client = $this->client->Unsubscribes();
|
||||||
$response = $unsub->deleteAddress("test@samples.mailgun.org");
|
$response = $client->deleteAddress("test@samples.mailgun.org");
|
||||||
$httpCode = $response->http_response_code;
|
$httpCode = $response->http_response_code;
|
||||||
$this->assertEquals(200, $httpCode);
|
$this->assertEquals(200, $httpCode);
|
||||||
}
|
}
|
||||||
public function testGetAddress(){
|
public function testGetAddress(){
|
||||||
$unsub = $this->client->Unsubscribes();
|
$client = $this->client->Unsubscribes();
|
||||||
$response = $unsub->getAddress("test@samples.mailgun.org");
|
$response = $client->getUnsubscribe("test@samples.mailgun.org");
|
||||||
$httpCode = $response->http_response_code;
|
$httpCode = $response->http_response_code;
|
||||||
$this->assertEquals(200, $httpCode);
|
$this->assertEquals(200, $httpCode);
|
||||||
}
|
}
|
||||||
public function testGetAddresses(){
|
public function testGetAddresses(){
|
||||||
$unsub = $this->client->Unsubscribes();
|
$client = $this->client->Unsubscribes();
|
||||||
$response = $unsub->getAddresses("1", "30");
|
$response = $client->getUnsubscribes("1", "30");
|
||||||
$httpCode = $response->http_response_code;
|
$httpCode = $response->http_response_code;
|
||||||
$this->assertEquals(200, $httpCode);
|
$this->assertEquals(200, $httpCode);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user