mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2025-02-06 08:19:25 +03:00
Finished Lists endpoint and added Address Validator
This commit is contained in:
parent
7872398f21
commit
017f4fcd92
27
src/Mailgun/Address/Address.php
Normal file
27
src/Mailgun/Address/Address.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?PHP
|
||||
|
||||
/*
|
||||
* Address.php - Validate Addresses.
|
||||
*/
|
||||
namespace Mailgun\Address;
|
||||
|
||||
class Address{
|
||||
|
||||
private $httpBroker;
|
||||
private $workingDomain;
|
||||
private $endpointUrl;
|
||||
|
||||
public function __construct($httpBroker){
|
||||
$this->httpBroker = $httpBroker;
|
||||
$this->endpointUrl = $this->httpBroker->returnWorkingDomain() . "/address";
|
||||
}
|
||||
|
||||
public function validateAddress($address){
|
||||
$updatedUrl = $this->endpointUrl . "/validate";
|
||||
$getData = array('address' => $address);
|
||||
$response = $this->httpBroker->getRequest($updatedUrl, $getData);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -49,7 +49,7 @@ class Campaigns{
|
||||
|
||||
public function deleteCampaign($campaignId){
|
||||
$updatedUrl = $this->endpointUrl . "/" . $campaignId;
|
||||
$response = $this->httpBroker->deleteCampaign($updatedUrl);
|
||||
$response = $this->httpBroker->deleteRequest($updatedUrl);
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -15,12 +15,66 @@ class Lists{
|
||||
public function __construct($httpBroker){
|
||||
$this->httpBroker = $httpBroker;
|
||||
$this->endpointUrl = $this->httpBroker->returnWorkingDomain() . "/lists";
|
||||
|
||||
}
|
||||
|
||||
public function getLists($limit, $skip){
|
||||
$response = $this->httpBroker->getRequest($this->endpointUrl, array($limit, $skip));
|
||||
return $response;
|
||||
}
|
||||
public function getList($listAddress){
|
||||
$updatedUrl = $this->endpointUrl . "/" . $listAddress;
|
||||
$response = $this->httpBroker->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);
|
||||
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);
|
||||
return $response;
|
||||
}
|
||||
public function deleteList($listAddress){
|
||||
$updatedUrl = $this->endpointUrl . "/" . $listAddress;
|
||||
$response = $this->httpBroker->deleteRequest($updatedUrl);
|
||||
return $response;
|
||||
}
|
||||
public function getListMembers($listAddress, $filterParams = array()){
|
||||
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/members";
|
||||
$response = $this->httpBroker->getRequest($updatedUrl, $filterParams);
|
||||
return $response;
|
||||
}
|
||||
public function getListMember($listAddress, $memberAddress){
|
||||
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/members/" . $memberAddress;
|
||||
$response = $this->httpBroker->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);
|
||||
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);
|
||||
return $response;
|
||||
}
|
||||
public function deleteListMember($listAddress, $memberAddress){
|
||||
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/members/" . $memberAddress;
|
||||
$response = $this->httpBroker->deleteRequest($updatedUrl);
|
||||
return $response;
|
||||
}
|
||||
public function getListStats($listAddress){
|
||||
$updatedUrl = $this->endpointUrl . "/" . $listAddress . "/stats";
|
||||
$response = $this->httpBroker->getRequest($updatedUrl);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -7,6 +7,7 @@ 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;
|
||||
@ -64,6 +65,9 @@ class MailgunClient{
|
||||
public function Lists(){
|
||||
return new Lists($this->httpBroker);
|
||||
}
|
||||
public function Address(){
|
||||
return new Address($this->httpBroker);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
22
tests/Mailgun/Tests/Address/AddressTest.php
Normal file
22
tests/Mailgun/Tests/Address/AddressTest.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?PHP
|
||||
|
||||
namespace Mailgun\Tests\Address;
|
||||
|
||||
use Mailgun\Tests\MailgunClientTest;
|
||||
|
||||
class AddressTest extends \Mailgun\Tests\MailgunTestCase{
|
||||
|
||||
private $client;
|
||||
|
||||
public function setUp(){
|
||||
$this->client = new MailgunClientTest("My-Super-Awesome-API-Key", "samples.mailgun.org", false);
|
||||
|
||||
}
|
||||
|
||||
public function testValidateAddress(){
|
||||
$client = $this->client->Address();
|
||||
$response = $client->validateAddress("addressvalidation@mailgun.com");
|
||||
$httpCode = $response->http_response_code;
|
||||
$this->assertEquals(200, $httpCode);
|
||||
}
|
||||
}
|
@ -48,30 +48,30 @@ class CampaignsTest extends \Mailgun\Tests\MailgunTestCase{
|
||||
$this->assertEquals(200, $httpCode);
|
||||
}
|
||||
|
||||
public function testGetCampaignEvents(12345, array()){
|
||||
public function testGetCampaignEvents(){
|
||||
$client = $this->client->Campaigns();
|
||||
$response = $client->getCampaignEvents(12345);
|
||||
$response = $client->getCampaignEvents(12345, array());
|
||||
$httpCode = $response->http_response_code;
|
||||
$this->assertEquals(200, $httpCode);
|
||||
}
|
||||
|
||||
public function testGetCampaignStats(12345, array()){
|
||||
public function testGetCampaignStats(){
|
||||
$client = $this->client->Campaigns();
|
||||
$response = $client->getCampaignStats(12345);
|
||||
$response = $client->getCampaignStats(12345, array());
|
||||
$httpCode = $response->http_response_code;
|
||||
$this->assertEquals(200, $httpCode);
|
||||
}
|
||||
|
||||
public function testGetCampaignStats(12345, array()){
|
||||
public function testGetCampaignClicks(){
|
||||
$client = $this->client->Campaigns();
|
||||
$response = $client->getCampaignClicks(12345);
|
||||
$response = $client->getCampaignClicks(12345, array());
|
||||
$httpCode = $response->http_response_code;
|
||||
$this->assertEquals(200, $httpCode);
|
||||
}
|
||||
|
||||
public function testGetCampaignStats(12345, array()){
|
||||
public function testGetCampaignOpens(){
|
||||
$client = $this->client->Campaigns();
|
||||
$response = $client->getCampaignOpens(12345);
|
||||
$response = $client->getCampaignOpens(12345, array());
|
||||
$httpCode = $response->http_response_code;
|
||||
$this->assertEquals(200, $httpCode);
|
||||
}
|
||||
|
92
tests/Mailgun/Tests/Lists/ListsTest.php
Normal file
92
tests/Mailgun/Tests/Lists/ListsTest.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?PHP
|
||||
|
||||
namespace Mailgun\Tests\Lists;
|
||||
|
||||
use Mailgun\Tests\MailgunClientTest;
|
||||
|
||||
class ListsTest extends \Mailgun\Tests\MailgunTestCase{
|
||||
|
||||
private $client;
|
||||
|
||||
public function setUp(){
|
||||
$this->client = new MailgunClientTest("My-Super-Awesome-API-Key", "samples.mailgun.org", false);
|
||||
|
||||
}
|
||||
|
||||
public function testGetLists(){
|
||||
$client = $this->client->Lists();
|
||||
$response = $client->getLists("1", "30");
|
||||
$httpCode = $response->http_response_code;
|
||||
$this->assertEquals(200, $httpCode);
|
||||
}
|
||||
|
||||
public function testGetList(){
|
||||
$client = $this->client->Lists();
|
||||
$response = $client->getList("mylist@mailgun.org");
|
||||
$httpCode = $response->http_response_code;
|
||||
$this->assertEquals(200, $httpCode);
|
||||
}
|
||||
|
||||
public function testAddList(){
|
||||
$client = $this->client->Lists();
|
||||
$response = $client->addList("mylist@mailgun.org", "My Sample List", "More Description Stuff", "readonly");
|
||||
$httpCode = $response->http_response_code;
|
||||
$this->assertEquals(200, $httpCode);
|
||||
}
|
||||
|
||||
public function testUpdateList(){
|
||||
$client = $this->client->Lists();
|
||||
$response = $client->updateList("mylist@mailgun.org", "My Sample List", "More Description Stuff", "readonly");
|
||||
$httpCode = $response->http_response_code;
|
||||
$this->assertEquals(200, $httpCode);
|
||||
}
|
||||
|
||||
public function testDeleteList(){
|
||||
$client = $this->client->Lists();
|
||||
$response = $client->deleteList(12345);
|
||||
$httpCode = $response->http_response_code;
|
||||
$this->assertEquals(200, $httpCode);
|
||||
}
|
||||
|
||||
public function testGetListMembers(){
|
||||
$client = $this->client->Lists();
|
||||
$response = $client->getListMembers("mylist@mailgun.org", array('subscribed'=>true, 'limit' => 50, 'skip' => 50));
|
||||
$httpCode = $response->http_response_code;
|
||||
$this->assertEquals(200, $httpCode);
|
||||
}
|
||||
|
||||
public function testGetListMember(){
|
||||
$client = $this->client->Lists();
|
||||
$response = $client->getListMember("mylist@mailgun.org", "subscribee@mailgun.org");
|
||||
$httpCode = $response->http_response_code;
|
||||
$this->assertEquals(200, $httpCode);
|
||||
}
|
||||
|
||||
public function testAddListMember(){
|
||||
$client = $this->client->Lists();
|
||||
$response = $client->getListMember("mylist@mailgun.org", "subscribee@mailgun.org", "Sample User", array('userid' => 'ABC123'), true, true);
|
||||
$httpCode = $response->http_response_code;
|
||||
$this->assertEquals(200, $httpCode);
|
||||
}
|
||||
|
||||
public function testUpdateListMember(){
|
||||
$client = $this->client->Lists();
|
||||
$response = $client->updateListMember("mylist@mailgun.org", "subscribee@mailgun.org", "Sample User", array('userid' => 'ABC123'), true);
|
||||
$httpCode = $response->http_response_code;
|
||||
$this->assertEquals(200, $httpCode);
|
||||
}
|
||||
|
||||
public function testDeleteListMember(){
|
||||
$client = $this->client->Lists();
|
||||
$response = $client->deleteListMember("mylist@mailgun.org", "subscribee@mailgun.org");
|
||||
$httpCode = $response->http_response_code;
|
||||
$this->assertEquals(200, $httpCode);
|
||||
}
|
||||
|
||||
public function testGetListStats(){
|
||||
$client = $this->client->Lists();
|
||||
$response = $client->getListStats("mylist@mailgun.org");
|
||||
$httpCode = $response->http_response_code;
|
||||
$this->assertEquals(200, $httpCode);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user