diff --git a/README.md b/README.md index 8a4c2b7..d6cb9dc 100644 --- a/README.md +++ b/README.md @@ -27,44 +27,30 @@ php -d detect_unicode=Off -r "eval('?>'.file_get_contents('https://getcomposer.o Next, require Composer's autoloader, in your application, to automatically load the Mailgun SDK in your project: ```PHP require 'vendor/autoload.php'; -use Mailgun\MailgunClient; +use Mailgun\Mailgun; ``` Usage ----- -Using the SDK should feel simple, if you're already familiar with our API endpoints. If not, no problem... When you're reviewing our documentation, the endpoints are expressed as a class in the SDK to make things easier. +Using the SDK should feel simple, if you're already familiar with our API endpoints. If not, no problem... When you're reviewing our documentation, use the provided resource URL when creating the HTTP request. For example, here's how to use the "Messages" API endpoint: ```php -# First, instantiate the client with your API credentials and domain. -$mgClient = new MailgunClient("key-3ax6xnjp29jd6fds4gc373sgvjxteol0", "samples.mailgun.org"); +# First, instantiate the SDK with your API credentials and define your domain. +$mg = new Mailgun("key-example"); +$domain = "example.com"; -# Next, instantiate a Message object on the messages API endpoint. -$message = $mgClient->Messages(); - -# Now, compose your message. -$message->setMessage(array('from' => 'me@samples.mailgun.org', - 'to' => 'php-sdk@mailgun.net', - 'subject' => 'The PHP SDK is awesome!', - 'text' => 'It is so simple to send a message.')); - -# Finally, send the message. -$message->sendMessage(); +# Now, compose and send your message. +$mg->post('{$domain}/messages', array('from' => 'bob@example.com', + 'to' => 'sally@example.com', + 'subject' => 'The PHP SDK is awesome!', + 'text' => 'It is so simple to send a message.')); ``` -For usage examples on each API endpoint, go to the "src/Mailgun" folder and browse through each API endpoint folder. A README exists in each folder with examples. +For usage examples on each API endpoint, head over to our official documentation pages. -[Address](src/Mailgun/Address/) -[Bounces](src/Mailgun/Bounces/) -[Campaigns](src/Mailgun/Campaigns/) -[Complaints](src/Mailgun/Complaints/) -[Lists](src/Mailgun/Lists/) -[Logs](src/Mailgun/Logs/) -[Messages](src/Mailgun/Messages/) -[Routes](src/Mailgun/Routes/) -[Stats](src/Mailgun/Stats/) -[Unsubscribes](src/Mailgun/Unsubscribes/) +This SDK includes a [Message Builder](src/Mailgun/Messages/README.md) and [Batch Message](src/Mailgun/Messages/README.md) component. Support and Feedback -------------------- diff --git a/src/Mailgun/Address/Address.php b/src/Mailgun/Address/Address.php deleted file mode 100644 index ffbbf57..0000000 --- a/src/Mailgun/Address/Address.php +++ /dev/null @@ -1,27 +0,0 @@ -restClient = $restClient; - $this->endpointUrl = "address"; - } - - public function getValidate($address){ - $updatedUrl = $this->endpointUrl . "/validate"; - $getData = array('address' => $address); - $response = $this->restClient->getRequest($updatedUrl, $getData); - return $response; - } -} - -?> \ No newline at end of file diff --git a/src/Mailgun/Address/README.md b/src/Mailgun/Address/README.md deleted file mode 100644 index 1aefd26..0000000 --- a/src/Mailgun/Address/README.md +++ /dev/null @@ -1,30 +0,0 @@ -Mailgun - Address -=================== - -This is the Mailgun PHP *Email Validation* endpoint. Given an arbitrary address, we will validate the address based on: Syntax checks (RFC defined grammar), DNS validation, Spell checks, Email Service Provider (ESP) specific local-part grammar (if available). - -The below assumes you've already installed the Mailgun PHP SDK in to your project. If not, go back to the master README for instructions. - -Usage -------------- -Here's how to use the "Address" API endpoint: - -```php -# First, instantiate the client with your PUBLIC API credentials and domain. -$mgClient = new MailgunClient("pubkey-5ogiflzbnjrljiky49qxsiozqef5jxp7", "samples.mailgun.org"); - -# Next, instantiate an Address object on the Address API endpoint. -$address = $mgClient->Address(); - -# Now, validate the address and store the result in $result. -$result = $address->getValidate("me@samples.mailgun.org"); -``` - -Available Functions -------------------- - -`getValidate(string $address);` - -More Documentation ------------------- -See the official [Mailgun Docs](http://documentation.mailgun.com/api-email-validation.html) for more information. diff --git a/src/Mailgun/Bounces/Bounces.php b/src/Mailgun/Bounces/Bounces.php deleted file mode 100644 index 9a8d6b2..0000000 --- a/src/Mailgun/Bounces/Bounces.php +++ /dev/null @@ -1,46 +0,0 @@ -restClient = $restClient; - $this->endpointUrl = $this->restClient->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->restClient->postRequest($this->endpointUrl, $postData); - return $response; - } - - public function deleteAddress($bounceAddress){ - $requestUrl = $this->endpointUrl . "/" . urlencode($bounceAddress); - $response = $this->restClient->deleteRequest($requestUrl); - return $response; - } - - public function getBounce($bounceAddress){ - $requestUrl = $this->endpointUrl . "/" . urlencode($bounceAddress); - $response = $this->restClient->getRequest($requestUrl); - return $response; - } - public function getBounces($limit, $skip){ - $response = $this->restClient->getRequest($this->endpointUrl, array($limit, $skip)); - return $response; - } - -} \ No newline at end of file diff --git a/src/Mailgun/Bounces/README.md b/src/Mailgun/Bounces/README.md deleted file mode 100644 index d5cbbd4..0000000 --- a/src/Mailgun/Bounces/README.md +++ /dev/null @@ -1,38 +0,0 @@ -Mailgun - Bounces -=================== - -This is the Mailgun PHP *Bounces* endpoint. - -The below assumes you've already installed the Mailgun PHP SDK in to your project. If not, go back to the master README for instructions. - -Usage -------------- -Here's how to use the "Bounces" API endpoint: - -```php -# First, instantiate the client with your PUBLIC API credentials and domain. -$mgClient = new MailgunClient("key-3ax6xnjp29jd6fds4gc373sgvjxteol0", "samples.mailgun.org"); - -# Next, instantiate a Bounces object on the Bounces API endpoint. -$bounces = $mgClient->Bounces(); - -# Finally, add an address to the Bounces Table. -$result = $bounces->addAddress("bounce@samples.mailgun.org", 550, "Server not accepting messages for mailbox."); - -``` - -Available Functions -------------------- - -`addAddress(string $bounceAddress, int $bounceCode, string $bounceError);` - -`deleteAddress(string $bounceAddress);` - -`getBounce(string $bounceAddress);` - -`getBounces(int $limit, int $skip);` - - -More Documentation ------------------- -See the official [Mailgun Docs](http://documentation.mailgun.com/api-bounces.html) for more information. \ No newline at end of file diff --git a/src/Mailgun/Campaigns/Campaigns.php b/src/Mailgun/Campaigns/Campaigns.php deleted file mode 100644 index 6cc048e..0000000 --- a/src/Mailgun/Campaigns/Campaigns.php +++ /dev/null @@ -1,93 +0,0 @@ -restClient = $restClient; - $this->endpointUrl = $this->restClient->returnWorkingDomain() . "/campaigns"; - } - - public function getCampaigns($limit, $skip){ - $response = $this->restClient->getRequest($this->endpointUrl, array($limit, $skip)); - return $response; - } - - public function getCampaign($campaignId){ - $updatedUrl = $this->endpointUrl . "/" . $campaignId; - $response = $this->restClient->getRequest($updatedUrl); - return $response; - } - - public function addCampaign($name, $id){ - if(isset($id) && strlen($id) > 64){ - throw new InvalidParameter("The message ID is too long. Limit is 64 characters."); - } - $postData = array('name' => $name, 'id' => $id); - $response = $this->restClient->postRequest($this->endpointUrl, $postData); - return $response; - } - - public function updateCampaign($campaignId, $name, $id){ - if(isset($id) && strlen($id) > 64){ - throw new InvalidParameter("The message ID is too long. Limit is 64 characters."); - } - $updatedUrl = $this->endpointUrl . "/" . $campaignId; - $postData = array('name' => $name, 'id' => $id); - $response = $this->restClient->putRequest($updatedUrl, $postData); - return $response; - } - - public function deleteCampaign($campaignId){ - $updatedUrl = $this->endpointUrl . "/" . $campaignId; - $response = $this->restClient->deleteRequest($updatedUrl); - return $response; - } - - public function getCampaignEvents($campaignId, $filterParams = array()){ - $updatedUrl = $this->endpointUrl . "/" . $campaignId . "/events"; - $response = $this->restClient->getRequest($updatedUrl, $filterParams); - return $response; - } - - public function getCampaignStats($campaignId, $filterParams = array()){ - $updatedUrl = $this->endpointUrl . "/" . $campaignId . "/stats"; - $response = $this->restClient->getRequest($updatedUrl, $filterParams); - return $response; - } - - public function getCampaignClicks($campaignId, $filterParams = array()){ - $updatedUrl = $this->endpointUrl . "/" . $campaignId . "/clicks"; - $response = $this->restClient->getRequest($updatedUrl, $filterParams); - return $response; - } - - public function getCampaignOpens($campaignId, $filterParams = array()){ - $updatedUrl = $this->endpointUrl . "/" . $campaignId . "/opens"; - $response = $this->restClient->getRequest($updatedUrl, $filterParams); - return $response; - } - - public function getCampaignUnsubscribes($campaignId, $filterParams = array()){ - $updatedUrl = $this->endpointUrl . "/" . $campaignId . "/unsubscribes"; - $response = $this->restClient->getRequest($updatedUrl, $filterParams); - return $response; - } - - public function getCampaignComplaints($campaignId, $filterParams = array()){ - $updatedUrl = $this->endpointUrl . "/" . $campaignId . "/clicks"; - $response = $this->restClient->getRequest($updatedUrl, $filterParams); - return $response; - } -} - -?> \ No newline at end of file diff --git a/src/Mailgun/Campaigns/Exceptions/InvalidParameter.php b/src/Mailgun/Campaigns/Exceptions/InvalidParameter.php deleted file mode 100644 index 7df21a1..0000000 --- a/src/Mailgun/Campaigns/Exceptions/InvalidParameter.php +++ /dev/null @@ -1,6 +0,0 @@ - \ No newline at end of file diff --git a/src/Mailgun/Campaigns/README.md b/src/Mailgun/Campaigns/README.md deleted file mode 100644 index bdbd5d8..0000000 --- a/src/Mailgun/Campaigns/README.md +++ /dev/null @@ -1,53 +0,0 @@ -Mailgun - Campaigns -=================== - -This is the Mailgun PHP *Campaigns* endpoint. - -The below assumes you've already installed the Mailgun PHP SDK in to your project. If not, go back to the master README for instructions. - -Usage -------------- -Here's how to use the "Campaign" API endpoint: - -```php -# First, instantiate the client with your PUBLIC API credentials and domain. -$mgClient = new MailgunClient("key-3ax6xnjp29jd6fds4gc373sgvjxteol0", "samples.mailgun.org"); - -# Next, instantiate a Campaign object on the Campaign API endpoint. -$campaigns = $mgClient->Campaigns(); - -$ Finally, get a list of campaigns, limit 5, skip 0. -$campaigns->getCampaigns(5, 0); - -``` - -Available Functions -------------------- - -`getCampaigns(int $limit, int $skip)` - -`getCampaign(string $campaignId)` - -`addCampaign(string $name, string $id)` - -`updateCampaign(string $campaignId, string $name, string $id)` - -`deleteCampaign(string $campaignId)` - -`getCampaignEvents(string $campaignId, array $filterParams)` - -`getCampaignStats(string $campaignId, array $filterParams)` - -`getCampaignClicks(string $campaignId, array $filterParams)` - -`getCampaignOpens(string $campaignId, array $filterParams)` - -`getCampaignUnsubscribes(string $campaignId, array $filterParams)` - -`getCampaignComplaints(string $campaignId, array $filterParams)` - -$filterParams are unique to the endpoint being called. See the documentation below for specifics. - -More Documentation ------------------- -See the official [Mailgun Docs](http://documentation.mailgun.com/api-campaigns.html) for more information. \ No newline at end of file diff --git a/src/Mailgun/Complaints/Complaints.php b/src/Mailgun/Complaints/Complaints.php deleted file mode 100644 index 5a48974..0000000 --- a/src/Mailgun/Complaints/Complaints.php +++ /dev/null @@ -1,41 +0,0 @@ -restClient = $restClient; - $this->endpointUrl = $this->restClient->returnWorkingDomain() . "/complaints"; - } - - public function addAddress($spamAddress){ - $postData = array("address" => $spamAddress); - $response = $this->restClient->postRequest($this->endpointUrl, $postData); - return $response; - } - - public function deleteAddress($spamAddress){ - $requestUrl = $this->endpointUrl . "/" . urlencode($spamAddress); - $response = $this->restClient->deleteRequest($requestUrl); - return $response; - } - - public function getComplaint($spamAddress){ - $requestUrl = $this->endpointUrl . "/" . urlencode($spamAddress); - $response = $this->restClient->getRequest($requestUrl); - return $response; - } - public function getComplaints($limit, $skip){ - $response = $this->restClient->getRequest($this->endpointUrl, array($limit, $skip)); - return $response; - } - -} \ No newline at end of file diff --git a/src/Mailgun/Complaints/README.md b/src/Mailgun/Complaints/README.md deleted file mode 100644 index 654b815..0000000 --- a/src/Mailgun/Complaints/README.md +++ /dev/null @@ -1,37 +0,0 @@ -Mailgun - Complaints -==================== - -This is the Mailgun PHP *Complaints* endpoint. - -The below assumes you've already installed the Mailgun PHP SDK in to your project. If not, go back to the master README for instructions. - -Usage -------------- -Here's how to use the "Complaints" API endpoint: - -```php -# First, instantiate the client with your PUBLIC API credentials and domain. -$mgClient = new MailgunClient("key-3ax6xnjp29jd6fds4gc373sgvjxteol0", "samples.mailgun.org"); - -# Next, instantiate a Complaints object on the Complaints API endpoint. -$complaints = $mgClient->Complaints(); - -# Finally, add a complaint to the Spam Complaints table. -$result = $complaints->addAddress("junk@samples.mailgun.org"); - -``` - -Available Functions -------------------- - -`addAddress(string $spamAddress)` - -`deleteAddress(string $spamAddress)` - -`getComplaint(string $spamAddress)` - -`getComplaints(int $limit, int $skip)` - -More Documentation ------------------- -See the official [Mailgun Docs](http://documentation.mailgun.com/api-complaints.html) for more information. \ No newline at end of file diff --git a/src/Mailgun/Lists/Lists.php b/src/Mailgun/Lists/Lists.php deleted file mode 100644 index 4d68b9e..0000000 --- a/src/Mailgun/Lists/Lists.php +++ /dev/null @@ -1,80 +0,0 @@ -restClient = $restClient; - $this->endpointUrl = "lists"; - - } - - public function getLists($limit, $skip){ - $response = $this->restClient->getRequest($this->endpointUrl, array($limit, $skip)); - return $response; - } - public function getList($listAddress){ - $updatedUrl = $this->endpointUrl . "/" . $listAddress; - $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->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->restClient->putRequest($updatedUrl, $postData); - return $response; - } - public function deleteList($listAddress){ - $updatedUrl = $this->endpointUrl . "/" . $listAddress; - $response = $this->restClient->deleteRequest($updatedUrl); - return $response; - } - public function getListMembers($listAddress, $filterParams = array()){ - $updatedUrl = $this->endpointUrl . "/" . $listAddress . "/members"; - $response = $this->restClient->getRequest($updatedUrl, $filterParams); - return $response; - } - public function getListMember($listAddress, $memberAddress){ - $updatedUrl = $this->endpointUrl . "/" . $listAddress . "/members/" . $memberAddress; - $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->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->restClient->putRequest($updatedUrl, $postData); - return $response; - } - public function deleteListMember($listAddress, $memberAddress){ - $updatedUrl = $this->endpointUrl . "/" . $listAddress . "/members/" . $memberAddress; - $response = $this->restClient->deleteRequest($updatedUrl); - return $response; - } - public function getListStats($listAddress){ - $updatedUrl = $this->endpointUrl . "/" . $listAddress . "/stats"; - $response = $this->restClient->getRequest($updatedUrl); - return $response; - } -} - -?> \ No newline at end of file diff --git a/src/Mailgun/Lists/README.md b/src/Mailgun/Lists/README.md deleted file mode 100644 index 27ce738..0000000 --- a/src/Mailgun/Lists/README.md +++ /dev/null @@ -1,53 +0,0 @@ -Mailgun - Lists -==================== - -This is the Mailgun PHP *Lists* endpoint. - -The below assumes you've already installed the Mailgun PHP SDK in to your project. If not, go back to the master README for instructions. - -Usage -------------- -Here's how to use the "Lists" API endpoint: - -```php -# First, instantiate the client with your PUBLIC API credentials and domain. -$mgClient = new MailgunClient("key-3ax6xnjp29jd6fds4gc373sgvjxteol0", "samples.mailgun.org"); - -# Next, instantiate a Lists object on the Lists API endpoint. -$lists = $mgClient->Lists(); - -# Finally, get 50 results and store in $result. -$result = $lists->getLists(50, 0); - -``` - -Available Functions -------------------- - -`getLists(int $limit, int $skip)` - -`getList(string $listAddress)` - -`addList(string $listAddress, string $name, string $description, string $access_level)` - -`updateList(string $listAddress, string $name, string $description, string $access_level)` - -`deleteList(string $listAddress)` - -`getListMembers(string $listAddress, array $filterParams)` - -`getListMember(string $listAddress, string $memberAddress)` - -`addListMember(string $listAddress, string $memberAddress, string $name, array $vars, bool $subscribed, bool $upsert)` - -`updateListMember(string $listAddress, string $memberAddress, string $name, array $vars, bool $subscribed)` - -`deleteListMember(string $listAddress, string $memberAddress)` - -`getListStats(string $listAddress)` - - - -More Documentation ------------------- -See the official [Mailgun Docs](http://documentation.mailgun.com/api-mailinglists.html) for more information. \ No newline at end of file diff --git a/src/Mailgun/Logs/Logs.php b/src/Mailgun/Logs/Logs.php deleted file mode 100644 index 664ef61..0000000 --- a/src/Mailgun/Logs/Logs.php +++ /dev/null @@ -1,26 +0,0 @@ -restClient = $restClient; - $this->endpointUrl = $this->restClient->returnWorkingDomain() . "/log"; - } - - public function getLogs($limit, $skip){ - $response = $this->restClient->getRequest($this->endpointUrl, array($limit, $skip)); - return $response; - } -} - -?> \ No newline at end of file diff --git a/src/Mailgun/Logs/README.md b/src/Mailgun/Logs/README.md deleted file mode 100644 index 913322e..0000000 --- a/src/Mailgun/Logs/README.md +++ /dev/null @@ -1,31 +0,0 @@ -Mailgun - Logs -==================== - -This is the Mailgun PHP *Logs* endpoint. - -The below assumes you've already installed the Mailgun PHP SDK in to your project. If not, go back to the master README for instructions. - -Usage -------------- -Here's how to use the "Logs" API endpoint: - -```php -# First, instantiate the client with your PUBLIC API credentials and domain. -$mgClient = new MailgunClient("key-3ax6xnjp29jd6fds4gc373sgvjxteol0", "samples.mailgun.org"); - -# Next, instantiate a Logs object on the Logs API endpoint. -$logs = $mgClient->Logs(); - -# Finally, get the 50 most recent log items. -$result = $logs->getLogs(50, 0); - -``` - -Available Functions -------------------- - -`getLogs(int $limit, int $skip)` - -More Documentation ------------------- -See the official [Mailgun Docs](http://documentation.mailgun.com/api-logs.html) for more information. \ No newline at end of file diff --git a/src/Mailgun/Mailgun.php b/src/Mailgun/Mailgun.php index 6545182..c4009b3 100644 --- a/src/Mailgun/Mailgun.php +++ b/src/Mailgun/Mailgun.php @@ -38,8 +38,8 @@ class Mailgun{ return new MessageBuilder(); } - public function BatchMessage($autoSend = true){ - return new BatchMessage($this->restClient, $autoSend); + public function BatchMessage($workingDomain, $autoSend = true){ + return new BatchMessage($this->restClient, $workingDomain, $autoSend); } } diff --git a/src/Mailgun/Messages/BatchMessage.php b/src/Mailgun/Messages/BatchMessage.php index 81e5fe8..81b45ea 100644 --- a/src/Mailgun/Messages/BatchMessage.php +++ b/src/Mailgun/Messages/BatchMessage.php @@ -2,20 +2,24 @@ namespace Mailgun\Messages; +use Mailgun\Messages\MessageBuilder; use Mailgun\Messages\Exceptions\TooManyParameters; use Mailgun\Messages\Exceptions\MissingRequiredMIMEParameters; -class BatchMessage{ +class BatchMessage extends MessageBuilder{ protected $batchRecipientAttributes; protected $autoSend; protected $restClient; + protected $workingDomain; - public function __construct($restClient, $autoSend){ + public function __construct($restClient, $workingDomain, $autoSend){ $this->batchRecipientAttributes = array(); $this->autoSend = $autoSend; $this->restClient = $restClient; + $this->workingDomain = $workingDomain; + $this->endpointUrl = $workingDomain . "/messages"; } public function addToRecipient($address, $attributes){ @@ -76,5 +80,8 @@ class BatchMessage{ return $response; } } + public function finalize(){ + return $this->sendMessage(); + } } ?> \ No newline at end of file diff --git a/src/Mailgun/Messages/MessageBuilder.php b/src/Mailgun/Messages/MessageBuilder.php index 8408511..27dab7f 100644 --- a/src/Mailgun/Messages/MessageBuilder.php +++ b/src/Mailgun/Messages/MessageBuilder.php @@ -327,6 +327,15 @@ class MessageBuilder{ return true; } } + + public function setMessage($message = array(), $files = array()){ + $this->message = $message; + $this->files = $files; + } + + public function getMessage(){ + return $this->message; + } public function getFiles(){ return $this->files; diff --git a/src/Mailgun/Messages/README.md b/src/Mailgun/Messages/README.md index a3f1145..901ea03 100644 --- a/src/Mailgun/Messages/README.md +++ b/src/Mailgun/Messages/README.md @@ -1,57 +1,33 @@ Mailgun - Messages ==================== -This is the Mailgun PHP *Messages* endpoint. +This is the Mailgun PHP *Message* utilities. The below assumes you've already installed the Mailgun PHP SDK in to your project. If not, go back to the master README for instructions. -Usage - Messages ----------------- -Here's how to use the "Messages" API endpoint: +There are two utilities included, Message Builder and Batch Message. -```php -# First, instantiate the client with your PUBLIC API credentials and domain. -$mgClient = new MailgunClient("key-3ax6xnjp29jd6fds4gc373sgvjxteol0", "samples.mailgun.org"); - -# Next, instantiate a Message object on the Messages API endpoint. -$message = $mgClient->Messages(); - -# Next, set the message content. -$message->setMessage(array('from' => 'me@samples.mailgun.org', - 'to' => 'php-sdk@mailgun.net', - 'subject' => 'The PHP SDK is awesome!', - 'text' => 'It is so simple to send a message.')); - -# Finally, send the message. -$message->sendMessage(); -``` - -Available Functions -------------------- - -`sendMessage(array $message, array $files)` - -`setMessage(array $message, array $files)` - -`sendMessage()` +Message Builder: Allows you to build a message object by calling methods for each MIME attribute. +Batch Message: Inherits Message Builder and allows you to iterate through recipients from a list. Messages will fire after the 1,000th recipient has been added. Usage - Message Builder ---------------------- -Here's how to use the "Messages" API endpoint with Message Builder: +----------------------- +Here's how to use Message Builder to build your Message. ```php -# First, instantiate the client with your PUBLIC API credentials and domain. -$mgClient = new MailgunClient("key-3ax6xnjp29jd6fds4gc373sgvjxteol0", "samples.mailgun.org"); +# First, instantiate the SDK with your API credentials and define your domain. +$mg = new Mailgun("key-example"); +$domain = "example.com"; -# Next, instantiate a Message Builder object on the Messages API endpoint. -$messageBldr = $mgClient->Messages()->MessageBuilder(); +# Next, instantiate a Message Builder object from the SDK. +$messageBldr = $mg->MessageBuilder(); # Define the from address. -$messageBldr->setFromAddress("me@samples.mailgun.org", array("first"=>"PHP", "last" => "SDK")); +$messageBldr->setFromAddress("me@example.com", array("first"=>"PHP", "last" => "SDK")); # Define a to recipient. -$messageBldr->addToRecipient("john.doe@samples.mailgun.org", array("first" => "John", "last" => "Doe")); +$messageBldr->addToRecipient("john.doe@example.com", array("first" => "John", "last" => "Doe")); # Define a cc recipient. -$messageBldr->addCcRecipient("sally.doe@samples.mailgun.org", array("first" => "Sally", "last" => "Doe")); +$messageBldr->addCcRecipient("sally.doe@example.com", array("first" => "Sally", "last" => "Doe")); # Define the subject. $messageBldr->setSubject("A message from the PHP SDK using Message Builder!"); # Define the body of the message. @@ -65,13 +41,13 @@ $messageBldr->setDeliveryTime("tomorrow 8:00AM", "PST"); $messageBldr->setClickTracking(true); # Finally, send the message. -$messageBldr->sendMessage(); +$mg->post('{$domain}/messages', $messageBldr->getMessage()); ``` -Available Functions (Inherits all Messages Functions) +Available Functions ----------------------------------------------------- -`addToRecipient(string $address, array $attributes)` +`addToRecipient(string $address, array $attributes)` `addCcRecipient(string $address, array $attributes)` @@ -103,42 +79,50 @@ Available Functions (Inherits all Messages Functions) `addCustomOption(string $optionName, string $data)` +`addCustomParameter(string $parameterName, string $data)` + +`setMessage(array $message, array $files)` + `getMessage()` `getFiles()` -Usage - Batch Sending +Usage - Batch Message --------------------- -Here's how to use the "Messages" API endpoint with Batch Sending: +Here's how to use Batch Message to easily handle batch sending jobs. ```php -# First, instantiate the client with your API credentials and domain. -$mgClient = new MailgunClient("key-3ax6xnjp29jd6fds4gc373sgvjxteol0", "samples.mailgun.org"); +# First, instantiate the SDK with your API credentials and define your domain. +$mg = new Mailgun("key-example"); +$domain = "example.com"; -# Next, instantiate a Batch Message object on the Messages API endpoint. -$batchMessage = $mgClient->Messages()->BatchMessage(); +# Next, instantiate a Message Builder object from the SDK, pass in your sending domain. +$batchMsg = $mg->BatchMessage($domain); # Define the from address. -$batchMessage->setFromAddress("me@samples.mailgun.org", array("first"=>"PHP", "last" => "SDK")); +$batchMsg->setFromAddress("me@samples.mailgun.org", array("first"=>"PHP", "last" => "SDK")); # Define the subject. -$batchMessage->setSubject("A Batch Message from the PHP SDK!"); +$batchMsg->setSubject("A Batch Message from the PHP SDK!"); # Define the body of the message. -$batchMessage->setTextBody("This is the text body of the message!"); +$batchMsg->setTextBody("This is the text body of the message!"); # Next, let's add a few recipients to the batch job. -$batchMessage->addBatchRecipient("john.doe@samples.mailgun.org", array("first" => "John", "last" => "Doe")); -$batchMessage->addBatchRecipient("sally.doe@samples.mailgun.org", array("first" => "Sally", "last" => "Doe")); -$batchMessage->addBatchRecipient("mike.jones@samples.mailgun.org", array("first" => "Mike", "last" => "Jones")); +$batchMsg->addToRecipient("john.doe@samples.mailgun.org", array("first" => "John", "last" => "Doe")); +$batchMsg->addToRecipient("sally.doe@samples.mailgun.org", array("first" => "Sally", "last" => "Doe")); +$batchMsg->addToRecipient("mike.jones@samples.mailgun.org", array("first" => "Mike", "last" => "Jones")); +... +// After 1,000 recipeints, Batch Message will automatically post your message to the messages endpoint. + +// Call finalize() to send any remaining recipients still in the buffer. +$batchMsg->finalize(); -# Finally, submit the batch job. -$batchMessage->sendMessage(); ``` Available Functions (Inherits all Batch Message and Messages Functions) ----------------------------------------------------------------------- -`addBatchRecipient(string $address, string $attributes)` +`addToRecipient(string $address, string $attributes)` More Documentation ------------------ diff --git a/src/Mailgun/Routes/Exceptions/InvalidParameter.php b/src/Mailgun/Routes/Exceptions/InvalidParameter.php deleted file mode 100644 index 76bb9a7..0000000 --- a/src/Mailgun/Routes/Exceptions/InvalidParameter.php +++ /dev/null @@ -1,6 +0,0 @@ - \ No newline at end of file diff --git a/src/Mailgun/Routes/README.md b/src/Mailgun/Routes/README.md deleted file mode 100644 index ace0bab..0000000 --- a/src/Mailgun/Routes/README.md +++ /dev/null @@ -1,38 +0,0 @@ -Mailgun - Routes -==================== - -This is the Mailgun PHP *Routes* endpoint. - -The below assumes you've already installed the Mailgun PHP SDK in to your project. If not, go back to the master README for instructions. - -Usage -------------- -Here's how to use the "Routes" API endpoint: - -```php -# First, instantiate the client with your PUBLIC API credentials and domain. -$mgClient = new MailgunClient("key-3ax6xnjp29jd6fds4gc373sgvjxteol0", "samples.mailgun.org"); - -# Next, instantiate a Routes object on the Routes API endpoint. -$routes = $mgClient->Routes(); - -# Next, add the new route. -$routes->addRoute(0, "Match defined recipient", "match_recipient(\"^chris\+(.*)@example.com$\")", "forward(\"mbx@externaldomain.com\")"); -``` - -Available Functions -------------------- - -`getRoutes(int $limit, int $skip)` - -`getRoute(string $routeId)` - -`addRoute(int $priority, string $description, string $expression, string $action)` - -`updateRoute(string $routeId, int $priority, string $description, string $expression, string $action)` - -`deleteRoute(string $routeId)` - -More Documentation ------------------- -See the official [Mailgun Docs](http://documentation.mailgun.com/api-routes.html) for more information. diff --git a/src/Mailgun/Routes/Routes.php b/src/Mailgun/Routes/Routes.php deleted file mode 100644 index 87e1c78..0000000 --- a/src/Mailgun/Routes/Routes.php +++ /dev/null @@ -1,86 +0,0 @@ -restClient = $restClient; - $this->endpointUrl = "routes"; - } - - public function getRoutes($limit, $skip){ - $response = $this->restClient->getRequest($this->endpointUrl, array($limit, $skip)); - return $response; - } - - public function getRoute($routeId){ - $updatedUrl = $this->endpointUrl . "/" . $routeId; - $response = $this->restClient->getRequest($updatedUrl); - return $response; - } - - public function addRoute($priority, $description, $expression, $action){ - - if(!is_int($priority) || $priority < 0){ - throw new InvalidParameter("The priority is not a positive integer."); - } - - if(!isset($description)){ - throw new InvalidParameter("The description seems to be missing."); - } - - if(!isset($expression)){ - throw new InvalidParameter("The expression seems to be missing."); - } - if(!isset($action)){ - throw new InvalidParameter("The action seems to be missing."); - } - - $postData = array('priority' => $priority, 'description' => $description, 'expression' => $expression, 'action' => $action); - - $response = $this->restClient->postRequest($this->endpointUrl, $postData); - return $response; - } - - public function updateRoute($routeId, $priority, $description, $expression, $action){ - if(!is_int($priority) || $priority < 0){ - throw new InvalidParameter("The priority is not a positive integer."); - } - - if(!isset($description)){ - throw new InvalidParameter("The description seems to be missing."); - } - - if(!isset($expression)){ - throw new InvalidParameter("The expression seems to be missing."); - } - if(!isset($action)){ - throw new InvalidParameter("The action seems to be missing."); - } - - $postData = array('priority' => $priority, 'description' => $description, 'expression' => $expression, 'action' => $action); - - $updatedUrl = $this->endpointUrl . "/" . $routeId; - - $response = $this->restClient->putRequest($updatedUrl, $postData); - return $response; - } - - public function deleteRoute($routeId){ - $updatedUrl = $this->endpointUrl . "/" . $routeId; - $response = $this->restClient->deleteRequest($updatedUrl); - return $response; - } -} - -?> \ No newline at end of file diff --git a/src/Mailgun/Stats/README.md b/src/Mailgun/Stats/README.md deleted file mode 100644 index 988fd95..0000000 --- a/src/Mailgun/Stats/README.md +++ /dev/null @@ -1,32 +0,0 @@ -Mailgun - Stats -==================== - -This is the Mailgun PHP *Stats* endpoint. - -The below assumes you've already installed the Mailgun PHP SDK in to your project. If not, go back to the master README for instructions. - -Usage -------------- -Here's how to use the "Stats" API endpoint: - -```php -# First, instantiate the client with your PUBLIC API credentials and domain. -$mgClient = new MailgunClient("key-3ax6xnjp29jd6fds4gc373sgvjxteol0", "samples.mailgun.org"); - -# Next, instantiate a Stats object on the Stats API endpoint. -$stats = $mgClient->Stats(); - -# Next, get the last 50 stats. -$stats->getStats(array('limit' => 50, 'skip' => 0, 'event' => 'sent')); -``` - -Available Functions -------------------- - -`deleteTag(string $tag)` - -`getStats(array $filterParams)` - -More Documentation ------------------- -See the official [Mailgun Docs](http://documentation.mailgun.com/api-stats.html) for more information. \ No newline at end of file diff --git a/src/Mailgun/Stats/Stats.php b/src/Mailgun/Stats/Stats.php deleted file mode 100644 index 4b54036..0000000 --- a/src/Mailgun/Stats/Stats.php +++ /dev/null @@ -1,32 +0,0 @@ -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->restClient->deleteRequest($requestUrl); - return $response; - } - - public function getStats($filterParams = array()){ - $response = $this->restClient->getRequest($this->statsEndpointUrl, $filterParams); - return $response; - } -} \ No newline at end of file diff --git a/src/Mailgun/Unsubscribes/README.md b/src/Mailgun/Unsubscribes/README.md deleted file mode 100644 index 6ebea97..0000000 --- a/src/Mailgun/Unsubscribes/README.md +++ /dev/null @@ -1,37 +0,0 @@ -Mailgun - Unsubscribes -====================== - -This is the Mailgun PHP *Unsubscribes* endpoint. - -The below assumes you've already installed the Mailgun PHP SDK in to your project. If not, go back to the master README for instructions. - -Usage -------------- -Here's how to use the "Unsubscribes" API endpoint: - -```php -# First, instantiate the client with your PUBLIC API credentials and domain. -$mgClient = new MailgunClient("key-3ax6xnjp29jd6fds4gc373sgvjxteol0", "samples.mailgun.org"); - -# Next, instantiate a Unsubscribes object on the Unsubscribes API endpoint. -$unsubscribe = $mgClient->Unsubscribes(); - -# Next, unsubscribe the address from the weekly-emails tag. -$unsubscribe->addAddress("removeme@samples.mailgun.org", "weekly-emails"); -``` - -Available Functions -------------------- - -`addAddress(string $unsubAddress, string $unsubTag)` - -`deleteAddress(string $unsubAddress)` - -`getUnsubscribe(string $unsubAddress)` - -`getUnsubscribes(int $limit, int $skip)` - - -More Documentation ------------------- -See the official [Mailgun Docs](http://documentation.mailgun.com/api-unsubscribes.html) for more information. \ No newline at end of file diff --git a/src/Mailgun/Unsubscribes/Unsubscribes.php b/src/Mailgun/Unsubscribes/Unsubscribes.php deleted file mode 100644 index 01a47f3..0000000 --- a/src/Mailgun/Unsubscribes/Unsubscribes.php +++ /dev/null @@ -1,46 +0,0 @@ -restClient = $restClient; - $this->endpointUrl = $this->restClient->returnWorkingDomain() . "/unsubscribes"; - } - - public function addAddress($unsubAddress, $unsubTag = NULL){ - if(isset($unsubTag)){ - $postData = array("address" => $unsubAddress, "tag" => $unsubTag); - } - else{ - $postData = array("address" => $unsubAddress, "tag" => "*"); - } - $response = $this->restClient->postRequest($this->endpointUrl, $postData); - return $response; - } - - public function deleteAddress($unsubAddress){ - $requestUrl = $this->endpointUrl . "/" . urlencode($unsubAddress); - $response = $this->restClient->deleteRequest($requestUrl); - return $response; - } - - public function getUnsubscribe($unsubAddress){ - $requestUrl = $this->endpointUrl . "/" . urlencode($unsubAddress); - $response = $this->restClient->getRequest($requestUrl); - return $response; - } - public function getUnsubscribes($limit, $skip){ - $response = $this->restClient->getRequest($this->endpointUrl, array($limit, $skip)); - return $response; - } - -} \ No newline at end of file diff --git a/test.php b/test.php new file mode 100644 index 0000000..9e454c6 --- /dev/null +++ b/test.php @@ -0,0 +1,16 @@ + $arguments); + + } + +} + +$test = new Test(); + +var_dump($test->olakwnfelkajweklfjlwkjelkmg("Asdfasdf")); + +?> \ No newline at end of file diff --git a/tests/Mailgun/Tests/Address/AddressTest.php b/tests/Mailgun/Tests/Address/AddressTest.php deleted file mode 100644 index 1524307..0000000 --- a/tests/Mailgun/Tests/Address/AddressTest.php +++ /dev/null @@ -1,22 +0,0 @@ -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); - } -} \ No newline at end of file diff --git a/tests/Mailgun/Tests/Bounces/BouncesTest.php b/tests/Mailgun/Tests/Bounces/BouncesTest.php deleted file mode 100644 index 3b80272..0000000 --- a/tests/Mailgun/Tests/Bounces/BouncesTest.php +++ /dev/null @@ -1,40 +0,0 @@ -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); - } - -} \ No newline at end of file diff --git a/tests/Mailgun/Tests/Campaigns/CampaignsTest.php b/tests/Mailgun/Tests/Campaigns/CampaignsTest.php deleted file mode 100644 index 4b170ce..0000000 --- a/tests/Mailgun/Tests/Campaigns/CampaignsTest.php +++ /dev/null @@ -1,78 +0,0 @@ -client = new MailgunClientTest("My-Super-Awesome-API-Key", "samples.mailgun.org", false); - - } - - public function testGetCampaigns(){ - $client = $this->client->Campaigns(); - $response = $client->getCampaigns("1", "30"); - $httpCode = $response->http_response_code; - $this->assertEquals(200, $httpCode); - } - - public function testGetCampaign(){ - $client = $this->client->Campaigns(); - $response = $client->getCampaign(12345); - $httpCode = $response->http_response_code; - $this->assertEquals(200, $httpCode); - } - - public function testAddCampaign(){ - $client = $this->client->Campaigns(); - $response = $client->addCampaign("MyCampaign", "TheID"); - $httpCode = $response->http_response_code; - $this->assertEquals(200, $httpCode); - } - - public function testUpdateCampaign(){ - $client = $this->client->Campaigns(); - $response = $client->updateCampaign(12345, "MyCampaign", "TheID"); - $httpCode = $response->http_response_code; - $this->assertEquals(200, $httpCode); - } - - public function testDeleteCampaign(){ - $client = $this->client->Campaigns(); - $response = $client->deleteCampaign(12345); - $httpCode = $response->http_response_code; - $this->assertEquals(200, $httpCode); - } - - public function testGetCampaignEvents(){ - $client = $this->client->Campaigns(); - $response = $client->getCampaignEvents(12345, array()); - $httpCode = $response->http_response_code; - $this->assertEquals(200, $httpCode); - } - - public function testGetCampaignStats(){ - $client = $this->client->Campaigns(); - $response = $client->getCampaignStats(12345, array()); - $httpCode = $response->http_response_code; - $this->assertEquals(200, $httpCode); - } - - public function testGetCampaignClicks(){ - $client = $this->client->Campaigns(); - $response = $client->getCampaignClicks(12345, array()); - $httpCode = $response->http_response_code; - $this->assertEquals(200, $httpCode); - } - - public function testGetCampaignOpens(){ - $client = $this->client->Campaigns(); - $response = $client->getCampaignOpens(12345, array()); - $httpCode = $response->http_response_code; - $this->assertEquals(200, $httpCode); - } -} \ No newline at end of file diff --git a/tests/Mailgun/Tests/Complaints/ComplaintsTest.php b/tests/Mailgun/Tests/Complaints/ComplaintsTest.php deleted file mode 100644 index b8ac768..0000000 --- a/tests/Mailgun/Tests/Complaints/ComplaintsTest.php +++ /dev/null @@ -1,40 +0,0 @@ -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); - } - -} \ No newline at end of file diff --git a/tests/Mailgun/Tests/Connection/ConnectionTest.php b/tests/Mailgun/Tests/Connection/ConnectionTest.php index f43269c..40b0192 100644 --- a/tests/Mailgun/Tests/Connection/ConnectionTest.php +++ b/tests/Mailgun/Tests/Connection/ConnectionTest.php @@ -1,7 +1,7 @@ client = new MailgunClientTest("My-Super-Awesome-API-Key", "samples.mailgun.org", false); + $this->client = new MailgunTest("My-Super-Awesome-API-Key", "samples.mailgun.org", false); } } diff --git a/tests/Mailgun/Tests/Connection/TestBroker.php b/tests/Mailgun/Tests/Connection/TestBroker.php index 887fc5a..d6549b2 100644 --- a/tests/Mailgun/Tests/Connection/TestBroker.php +++ b/tests/Mailgun/Tests/Connection/TestBroker.php @@ -5,19 +5,16 @@ use Mailgun\Connection\RestClient; class TestBroker extends RestClient{ private $apiKey; - protected $domain; - protected $debug; - protected $apiEndpoint = API_ENDPOINT; + protected $apiEndpoint; protected $apiVersion = API_VERSION; protected $apiUser = API_USER; protected $sdkVersion = SDK_VERSION; protected $sdkUserAgent = SDK_USER_AGENT; - public function __construct($apiKey, $domain, $debug = false){ + public function __construct($apiKey = null, $apiEndpoint = "api.mailgun.net"){ $this->apiKey = $apiKey; - $this->domain = $domain; - $this->debug = $debug; + $this->apiEndpoint = $apiEndpoint; } public function postRequest($endpointUrl, $postData = array(), $files = array()){ diff --git a/tests/Mailgun/Tests/Lists/ListsTest.php b/tests/Mailgun/Tests/Lists/ListsTest.php deleted file mode 100644 index bcc3db0..0000000 --- a/tests/Mailgun/Tests/Lists/ListsTest.php +++ /dev/null @@ -1,92 +0,0 @@ -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); - } -} \ No newline at end of file diff --git a/tests/Mailgun/Tests/Logs/LogsTest.php b/tests/Mailgun/Tests/Logs/LogsTest.php deleted file mode 100644 index b7b1299..0000000 --- a/tests/Mailgun/Tests/Logs/LogsTest.php +++ /dev/null @@ -1,22 +0,0 @@ -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); - } - -} \ No newline at end of file diff --git a/tests/Mailgun/Tests/MailgunClientTest.php b/tests/Mailgun/Tests/MailgunClientTest.php deleted file mode 100644 index 8c603e8..0000000 --- a/tests/Mailgun/Tests/MailgunClientTest.php +++ /dev/null @@ -1,20 +0,0 @@ -restClient = new TestBroker($apiKey, $domain, $debug); - return true; - } -} - - -?> \ No newline at end of file diff --git a/tests/Mailgun/Tests/MailgunTest.php b/tests/Mailgun/Tests/MailgunTest.php new file mode 100644 index 0000000..e4c62ac --- /dev/null +++ b/tests/Mailgun/Tests/MailgunTest.php @@ -0,0 +1,20 @@ +restClient = new TestBroker($apiKey, $apiEndpoint); + return true; + } +} + + +?> \ No newline at end of file diff --git a/tests/Mailgun/Tests/Message/BatchMessageTest.php b/tests/Mailgun/Tests/Message/BatchMessageTest.php index ddfc9eb..a96a485 100644 --- a/tests/Mailgun/Tests/Message/BatchMessageTest.php +++ b/tests/Mailgun/Tests/Message/BatchMessageTest.php @@ -1,47 +1,48 @@ client = new MailgunClientTest("My-Super-Awesome-API-Key", "samples.mailgun.org", false); + $this->client = new MailgunTest("My-Super-Awesome-API-Key"); } public function testBlankInstantiation(){ - $message = $this->client->Messages()->BatchMessage(); + $message = $this->client->BatchMessage($this->sampleDomain); $this->assertTrue(is_array($message->getMessage())); } - public function testAddBatchRecipient(){ - $message = $this->client->Messages()->BatchMessage(); - $message->addBatchRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User")); + public function testaddToRecipient(){ + $message = $this->client->BatchMessage($this->sampleDomain); + $message->addToRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User")); $messageObj= $message->getMessage(); $this->assertEquals(array("to" => array("Test User ")), $messageObj); } public function testAddMultipleBatchRecipients(){ - $message = $this->client->Messages()->BatchMessage(); + $message = $this->client->BatchMessage($this->sampleDomain); for($i=0; $i<100; $i++){ - $message->addBatchRecipient("$i@samples.mailgun.org", array("first" => "Test", "last" => "User $i")); + $message->addToRecipient("$i@samples.mailgun.org", array("first" => "Test", "last" => "User $i")); } $messageObj= $message->getMessage(); $this->assertEquals(100, count($messageObj["to"])); } public function testMaximumBatchSize(){ - $message = $this->client->Messages()->BatchMessage(); + $message = $this->client->BatchMessage($this->sampleDomain); $message->setFromAddress("samples@mailgun.org", array("first" => "Test", "last" => "User")); $message->setSubject("This is the subject of the message!"); $message->setTextBody("This is the text body of the message!"); for($i=0; $i<1001; $i++){ - $message->addBatchRecipient("$i@samples.mailgun.org", array("first" => "Test", "last" => "User $i")); + $message->addToRecipient("$i@samples.mailgun.org", array("first" => "Test", "last" => "User $i")); } $messageObj= $message->getMessage(); $this->assertEquals(1, count($messageObj["to"])); } public function testResetOnEndBatchMessage(){ - $message = $this->client->Messages()->BatchMessage(); - $message->addBatchRecipient("test-user@samples.mailgun.org", array("first" => "Test", "last" => "User")); + $message = $this->client->BatchMessage($this->sampleDomain); + $message->addToRecipient("test-user@samples.mailgun.org", array("first" => "Test", "last" => "User")); $message->setFromAddress("samples@mailgun.org", array("first" => "Test", "last" => "User")); $message->setSubject("This is the subject of the message!"); $message->setTextBody("This is the text body of the message!"); diff --git a/tests/Mailgun/Tests/Message/MessageBuilderTest.php b/tests/Mailgun/Tests/Message/MessageBuilderTest.php index d3d149c..8ca1201 100644 --- a/tests/Mailgun/Tests/Message/MessageBuilderTest.php +++ b/tests/Mailgun/Tests/Message/MessageBuilderTest.php @@ -1,83 +1,83 @@ client = new MailgunClientTest("My-Super-Awesome-API-Key", "samples.mailgun.org", false); + $this->client = new MailgunTest("My-Super-Awesome-API-Key", "samples.mailgun.org", false); } public function testBlankInstantiation(){ - $message = $this->client->Messages()->MessageBuilder(); + $message = $this->client->MessageBuilder(); $this->assertTrue(is_array($message->getMessage())); } public function testAddToRecipient(){ - $message = $this->client->Messages()->MessageBuilder(); + $message = $this->client->MessageBuilder(); $message->addToRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User")); $messageObj = $message->getMessage(); $this->assertEquals(array("to" => array("Test User ")), $messageObj); } public function testAddCcRecipient(){ - $message = $this->client->Messages()->MessageBuilder(); + $message = $this->client->MessageBuilder(); $message->addCcRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User")); $messageObj = $message->getMessage(); $this->assertEquals(array("cc" => array("Test User ")), $messageObj); } public function testAddBccRecipient(){ - $message = $this->client->Messages()->MessageBuilder(); + $message = $this->client->MessageBuilder(); $message->addBccRecipient("test@samples.mailgun.org", array("first" => "Test", "last" => "User")); $messageObj = $message->getMessage(); $this->assertEquals(array("bcc" => array("Test User ")), $messageObj); } public function testSetFromAddress(){ - $message = $this->client->Messages()->MessageBuilder(); + $message = $this->client->MessageBuilder(); $message->setFromAddress("test@samples.mailgun.org", array("first" => "Test", "last" => "User")); $messageObj = $message->getMessage(); $this->assertEquals(array("from" => "Test User "), $messageObj); } public function testSetSubject(){ - $message = $this->client->Messages()->MessageBuilder(); + $message = $this->client->MessageBuilder(); $message->setSubject("Test Subject"); $messageObj = $message->getMessage(); $this->assertEquals(array("subject" => "Test Subject"), $messageObj); } public function testAddCustomHeader(){ - $message = $this->client->Messages()->MessageBuilder(); + $message = $this->client->MessageBuilder(); $message->addCustomHeader("My-Header", "123"); $messageObj = $message->getMessage(); $this->assertEquals(array("h:My-Header" => array("123")), $messageObj); } public function testSetTextBody(){ - $message = $this->client->Messages()->MessageBuilder(); + $message = $this->client->MessageBuilder(); $message->setTextBody("This is the text body!"); $messageObj = $message->getMessage(); $this->assertEquals(array("text" => "This is the text body!"), $messageObj); } public function testSetHtmlBody(){ - $message = $this->client->Messages()->MessageBuilder(); + $message = $this->client->MessageBuilder(); $message->setHtmlBody("This is an awesome email"); $messageObj = $message->getMessage(); $this->assertEquals(array("html" => "This is an awesome email"), $messageObj); } public function testAddAttachments(){ - $message = $this->client->Messages()->MessageBuilder(); + $message = $this->client->MessageBuilder(); $message->addAttachment("@../TestAssets/mailgun_icon.png"); $message->addAttachment("@../TestAssets/rackspace_logo.png"); $messageObj = $message->getFiles(); $this->assertEquals(array("attachment" => array("@../TestAssets/mailgun_icon.png", "@../TestAssets/rackspace_logo.png")), $messageObj); } public function testAddInlineImages(){ - $message = $this->client->Messages()->MessageBuilder(); + $message = $this->client->MessageBuilder(); $message->addInlineImage("@../TestAssets/mailgun_icon.png"); $message->addInlineImage("@../TestAssets/rackspace_logo.png"); $messageObj = $message->getFiles(); $this->assertEquals(array("inline" => array("@../TestAssets/mailgun_icon.png", "@../TestAssets/rackspace_logo.png")), $messageObj); } public function testsetTestMode(){ - $message = $this->client->Messages()->MessageBuilder(); + $message = $this->client->MessageBuilder(); $message->setTestMode(true); $messageObj = $message->getMessage(); $this->assertEquals(array("o:testmode" => "yes"), $messageObj); @@ -92,7 +92,7 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase{ $this->assertEquals(array("o:testmode" => "no"), $messageObj); } public function addCampaignId(){ - $message = $this->client->Messages()->MessageBuilder(); + $message = $this->client->MessageBuilder(); $message->addCampaignId("ABC123"); $message->addCampaignId("XYZ987"); $message->addCampaignId("TUV456"); @@ -101,7 +101,7 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase{ $this->assertEquals(array("o:campaign" => array("ABC123", "XYZ987", "TUV456")), $messageObj); } public function testSetDkim(){ - $message = $this->client->Messages()->MessageBuilder(); + $message = $this->client->MessageBuilder(); $message->setDkim(true); $messageObj = $message->getMessage(); $this->assertEquals(array("o:dkim" => "yes"), $messageObj); @@ -116,7 +116,7 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase{ $this->assertEquals(array("o:dkim" => "no"), $messageObj); } public function testSetClickTracking(){ - $message = $this->client->Messages()->MessageBuilder(); + $message = $this->client->MessageBuilder(); $message->setClickTracking(true); $messageObj = $message->getMessage(); $this->assertEquals(array("o:tracking-clicks" => "yes"), $messageObj); @@ -131,7 +131,7 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase{ $this->assertEquals(array("o:tracking-clicks" => "no"), $messageObj); } public function testSetOpenTracking(){ - $message = $this->client->Messages()->MessageBuilder(); + $message = $this->client->MessageBuilder(); $message->setOpenTracking(true); $messageObj = $message->getMessage(); $this->assertEquals(array("o:tracking-opens" => "yes"), $messageObj); @@ -146,7 +146,7 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase{ $this->assertEquals(array("o:tracking-opens" => "no"), $messageObj); } public function testSetDeliveryTime(){ - $message = $this->client->Messages()->MessageBuilder(); + $message = $this->client->MessageBuilder(); $message->setDeliveryTime("January 15, 2014 8:00AM", "CST"); $messageObj = $message->getMessage(); $this->assertEquals(array("o:deliverytime" => "Wed, 15 Jan 2014 08:00:00 -0600"), $messageObj); @@ -161,13 +161,13 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase{ $this->assertEquals(array("o:deliverytime" => "Sat, 06 Jul 2013 08:00:00 -0500"), $messageObj); } public function testAddCustomData(){ - $message = $this->client->Messages()->MessageBuilder(); + $message = $this->client->MessageBuilder(); $message->addCustomData("My-Super-Awesome-Data", array("What" => "Mailgun Rocks!")); $messageObj = $message->getMessage(); $this->assertEquals(array("v:My-Super-Awesome-Data" => "{\"What\":\"Mailgun Rocks!\"}"), $messageObj); } public function testAddCustomOption(){ - $message = $this->client->Messages()->MessageBuilder(); + $message = $this->client->MessageBuilder(); $message->addCustomOption("my-option", "yes"); $message->addCustomOption("o:my-other-option", "no"); $messageObj = $message->getMessage(); diff --git a/tests/Mailgun/Tests/Routes/RoutesTest.php b/tests/Mailgun/Tests/Routes/RoutesTest.php deleted file mode 100644 index ecc9d0d..0000000 --- a/tests/Mailgun/Tests/Routes/RoutesTest.php +++ /dev/null @@ -1,46 +0,0 @@ -client = new MailgunClientTest("My-Super-Awesome-API-Key", "samples.mailgun.org", false); - - } - public function testAddRoute(){ - $client = $this->client->Routes(); - $response = $client->addRoute(10, "This is the description", "match_recipient('.*@gmail.com')", "forward('alex@mailgun.net')"); - $httpCode = $response->http_response_code; - $this->assertEquals(200, $httpCode); - } - public function testDeleteRoute(){ - $client = $this->client->Routes(); - $response = $client->deleteRoute(12345); - $httpCode = $response->http_response_code; - $this->assertEquals(200, $httpCode); - } - public function testGetRoute(){ - $client = $this->client->Routes(); - $response = $client->getRoute(12345); - $httpCode = $response->http_response_code; - $this->assertEquals(200, $httpCode); - } - public function testGetRoutes(){ - $client = $this->client->Routes(); - $response = $client->getRoutes("5", "10"); - $httpCode = $response->http_response_code; - $this->assertEquals(200, $httpCode); - } - public function testUpdateRoute(){ - $client = $this->client->Routes(); - $response = $client->updateRoute(12345, 10, "This is the description", "match_recipient('.*@gmail.com')", "forward('alex@mailgun.net')"); - $httpCode = $response->http_response_code; - $this->assertEquals(200, $httpCode); - } - -} \ No newline at end of file diff --git a/tests/Mailgun/Tests/Stats/Stats.php b/tests/Mailgun/Tests/Stats/Stats.php deleted file mode 100644 index ed64b9f..0000000 --- a/tests/Mailgun/Tests/Stats/Stats.php +++ /dev/null @@ -1,28 +0,0 @@ -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); - } - -} \ No newline at end of file diff --git a/tests/Mailgun/Tests/Unsubscribes/UnsubscribeTest.php b/tests/Mailgun/Tests/Unsubscribes/UnsubscribeTest.php deleted file mode 100644 index f8b56f0..0000000 --- a/tests/Mailgun/Tests/Unsubscribes/UnsubscribeTest.php +++ /dev/null @@ -1,40 +0,0 @@ -client = new MailgunClientTest("My-Super-Awesome-API-Key", "samples.mailgun.org", false); - - } - public function testAddAddress(){ - $client = $this->client->Unsubscribes(); - $response = $client->addAddress("test@samples.mailgun.org"); - $httpCode = $response->http_response_code; - $this->assertEquals(200, $httpCode); - } - public function testDeleteAddress(){ - $client = $this->client->Unsubscribes(); - $response = $client->deleteAddress("test@samples.mailgun.org"); - $httpCode = $response->http_response_code; - $this->assertEquals(200, $httpCode); - } - public function testGetAddress(){ - $client = $this->client->Unsubscribes(); - $response = $client->getUnsubscribe("test@samples.mailgun.org"); - $httpCode = $response->http_response_code; - $this->assertEquals(200, $httpCode); - } - public function testGetAddresses(){ - $client = $this->client->Unsubscribes(); - $response = $client->getUnsubscribes("1", "30"); - $httpCode = $response->http_response_code; - $this->assertEquals(200, $httpCode); - } - -} \ No newline at end of file