diff --git a/src/Mailgun/Connection/Exceptions/GenericHTTPError.php b/src/Mailgun/Connection/Exceptions/GenericHTTPError.php index f7cf8c3..bcbb61d 100644 --- a/src/Mailgun/Connection/Exceptions/GenericHTTPError.php +++ b/src/Mailgun/Connection/Exceptions/GenericHTTPError.php @@ -2,5 +2,3 @@ namespace Mailgun\Connection\Exceptions; class GenericHTTPError extends \Exception{} - -?> \ No newline at end of file diff --git a/src/Mailgun/Connection/Exceptions/InvalidCredentials.php b/src/Mailgun/Connection/Exceptions/InvalidCredentials.php index 8c66802..bfcc743 100644 --- a/src/Mailgun/Connection/Exceptions/InvalidCredentials.php +++ b/src/Mailgun/Connection/Exceptions/InvalidCredentials.php @@ -2,5 +2,3 @@ namespace Mailgun\Connection\Exceptions; class InvalidCredentials extends \Exception{} - -?> \ No newline at end of file diff --git a/src/Mailgun/Connection/Exceptions/MissingEndpoint.php b/src/Mailgun/Connection/Exceptions/MissingEndpoint.php index 1f8a5b0..61d4a7e 100644 --- a/src/Mailgun/Connection/Exceptions/MissingEndpoint.php +++ b/src/Mailgun/Connection/Exceptions/MissingEndpoint.php @@ -2,5 +2,3 @@ namespace Mailgun\Connection\Exceptions; class MissingEndpoint extends \Exception{} - -?> \ No newline at end of file diff --git a/src/Mailgun/Connection/Exceptions/MissingRequiredParameters.php b/src/Mailgun/Connection/Exceptions/MissingRequiredParameters.php index 8b313ef..eb93080 100644 --- a/src/Mailgun/Connection/Exceptions/MissingRequiredParameters.php +++ b/src/Mailgun/Connection/Exceptions/MissingRequiredParameters.php @@ -2,5 +2,3 @@ namespace Mailgun\Connection\Exceptions; class MissingRequiredParameters extends \Exception{} - -?> \ No newline at end of file diff --git a/src/Mailgun/Connection/Exceptions/NoDomainsConfigured.php b/src/Mailgun/Connection/Exceptions/NoDomainsConfigured.php index 39f19c5..54884aa 100644 --- a/src/Mailgun/Connection/Exceptions/NoDomainsConfigured.php +++ b/src/Mailgun/Connection/Exceptions/NoDomainsConfigured.php @@ -2,5 +2,3 @@ namespace Mailgun\Connection\Exceptions; class NoDomainsConfigured extends \Exception{} - -?> \ No newline at end of file diff --git a/src/Mailgun/Connection/RestClient.php b/src/Mailgun/Connection/RestClient.php index 88bd574..e68cdf3 100644 --- a/src/Mailgun/Connection/RestClient.php +++ b/src/Mailgun/Connection/RestClient.php @@ -13,8 +13,8 @@ use Mailgun\Connection\Exceptions\NoDomainsConfigured; use Mailgun\Connection\Exceptions\MissingRequiredParameters; use Mailgun\Connection\Exceptions\MissingEndpoint; -/* - This class is a wrapper for the Guzzle (HTTP Client Library). +/* + This class is a wrapper for the Guzzle (HTTP Client Library). */ class RestClient{ @@ -22,19 +22,19 @@ class RestClient{ private $apiKey; protected $mgClient; protected $hasFiles = False; - + public function __construct($apiKey, $apiEndpoint, $apiVersion, $ssl){ $this->apiKey = $apiKey; $this->mgClient = new Guzzle($this->generateEndpoint($apiEndpoint, $apiVersion, $ssl)); $this->mgClient->setDefaultOption('curl.options', array('CURLOPT_FORBID_REUSE' => true)); - $this->mgClient->setDefaultOption('auth', array (API_USER, $this->apiKey)); + $this->mgClient->setDefaultOption('auth', array (API_USER, $this->apiKey)); $this->mgClient->setDefaultOption('exceptions', false); $this->mgClient->setUserAgent(SDK_USER_AGENT . '/' . SDK_VERSION); } - + public function post($endpointUrl, $postData = array(), $files = array()){ $request = $this->mgClient->post($endpointUrl, array(), $postData); - + if(isset($files["message"])){ $this->hasFiles = True; foreach($files as $message){ @@ -47,9 +47,9 @@ class RestClient{ foreach($files["attachment"] as $attachment){ // Backward compatibility code if (is_array($attachment)){ - $request->addPostFile("attachment", - $attachment['filePath'], null, - $attachment['remoteName']); + $request->addPostFile("attachment", + $attachment['filePath'], null, + $attachment['remoteName']); } else{ $request->addPostFile("attachment", $attachment); @@ -62,58 +62,58 @@ class RestClient{ foreach($files["inline"] as $inline){ // Backward compatibility code if (is_array($inline)){ - $request->addPostFile("inline", - $inline['filePath'], null, - $inline['remoteName']); + $request->addPostFile("inline", + $inline['filePath'], null, + $inline['remoteName']); } else{ $request->addPostFile("inline", $inline); - } + } } } - + /* - This block of code is to accommodate for a bug in Guzzle. + This block of code is to accommodate for a bug in Guzzle. See https://github.com/guzzle/guzzle/issues/545. It can be removed when Guzzle resolves the issue. */ if($this->hasFiles){ - $request->getPostFields()->setAggregator(new PhpAggregator()); + $request->getPostFields()->setAggregator(new PhpAggregator()); } else{ $request->getPostFields()->setAggregator(new DuplicateAggregator()); } - + $response = $request->send(); return $this->responseHandler($response); } - + public function get($endpointUrl, $queryString = array()){ $request = $this->mgClient->get($endpointUrl); if(isset($queryString)){ foreach($queryString as $key=>$value){ $request->getQuery()->set($key, $value); - } + } } $response = $request->send(); return $this->responseHandler($response); } - + public function delete($endpointUrl){ $request = $this->mgClient->delete($endpointUrl); $response = $request->send(); - return $this->responseHandler($response); + return $this->responseHandler($response); } - + public function put($endpointUrl, $putData){ $request = $this->mgClient->put($endpointUrl, array(), $putData); $request->getPostFields()->setAggregator(new DuplicateAggregator()); $response = $request->send(); return $this->responseHandler($response); } - + public function responseHandler($responseObj){ $httpResponseCode = $responseObj->getStatusCode(); if($httpResponseCode === 200){ @@ -146,5 +146,3 @@ class RestClient{ } } } - -?> \ No newline at end of file diff --git a/src/Mailgun/Constants/Constants.php b/src/Mailgun/Constants/Constants.php index b5034a6..6d69195 100644 --- a/src/Mailgun/Constants/Constants.php +++ b/src/Mailgun/Constants/Constants.php @@ -21,6 +21,3 @@ const INVALID_PARAMETER_INLINE = "Inline images must be passed with an \"@\" pre const TOO_MANY_PARAMETERS_CAMPAIGNS = "You've exceeded the maximum (3) campaigns for a single message."; const TOO_MANY_PARAMETERS_TAGS = "You've exceeded the maximum (3) tags for a single message."; const TOO_MANY_PARAMETERS_RECIPIENT = "You've exceeded the maximum recipient count (1,000) on the to field with autosend disabled."; - - -?> diff --git a/src/Mailgun/Mailgun.php b/src/Mailgun/Mailgun.php index e183ec7..d761f49 100644 --- a/src/Mailgun/Mailgun.php +++ b/src/Mailgun/Mailgun.php @@ -11,30 +11,30 @@ use Mailgun\Messages\BatchMessage; use Mailgun\Lists\OptInHandler; use Mailgun\Messages\MessageBuilder; -/* - This class is the base class for the Mailgun SDK. - See the official documentation for usage instructions. +/* + This class is the base class for the Mailgun SDK. + See the official documentation for usage instructions. */ class Mailgun{ protected $workingDomain; protected $restClient; - + public function __construct($apiKey = null, $apiEndpoint = "api.mailgun.net", $apiVersion = "v2", $ssl = true){ $this->restClient = new RestClient($apiKey, $apiEndpoint, $apiVersion, $ssl); } public function sendMessage($workingDomain, $postData, $postFiles = array()){ - - /* + + /* This function allows the sending of a fully formed message OR a custom - MIME string. If sending MIME, the string must be passed in to the 3rd - position of the function call. + MIME string. If sending MIME, the string must be passed in to the 3rd + position of the function call. */ - + if(is_array($postFiles)){ - return $this->post("$workingDomain/messages", $postData, $postFiles); + return $this->post("$workingDomain/messages", $postData, $postFiles); } else if(is_string($postFiles)){ @@ -55,30 +55,28 @@ class Mailgun{ public function post($endpointUrl, $postData = array(), $files = array()){ return $this->restClient->post($endpointUrl, $postData, $files); } - + public function get($endpointUrl, $queryString = array()){ return $this->restClient->get($endpointUrl, $queryString); } - + public function delete($endpointUrl){ return $this->restClient->delete($endpointUrl); } - + public function put($endpointUrl, $putData){ return $this->restClient->put($endpointUrl, $putData); } - + public function MessageBuilder(){ return new MessageBuilder(); } - + public function OptInHandler(){ return new OptInHandler(); } - + public function BatchMessage($workingDomain, $autoSend = true){ return new BatchMessage($this->restClient, $workingDomain, $autoSend); } } - -?> \ No newline at end of file diff --git a/src/Mailgun/Messages/BatchMessage.php b/src/Mailgun/Messages/BatchMessage.php index 5a022a5..834089a 100644 --- a/src/Mailgun/Messages/BatchMessage.php +++ b/src/Mailgun/Messages/BatchMessage.php @@ -6,9 +6,9 @@ use Mailgun\Messages\MessageBuilder; use Mailgun\Messages\Exceptions\TooManyParameters; use Mailgun\Messages\Exceptions\MissingRequiredMIMEParameters; -/* +/* This class is used for batch sending. See the official documentation - for usage instructions. + for usage instructions. */ class BatchMessage extends MessageBuilder{ @@ -26,7 +26,7 @@ class BatchMessage extends MessageBuilder{ $this->workingDomain = $workingDomain; $this->endpointUrl = $workingDomain . "/messages"; } - + protected function addRecipient($headerName, $address, $variables){ if(array_key_exists($headerName, $this->counters['recipients'])){ if($this->counters['recipients'][$headerName] == RECIPIENT_COUNT_LIMIT){ @@ -36,7 +36,7 @@ class BatchMessage extends MessageBuilder{ $this->sendMessage(); } } - + $compiledAddress = $this->parseAddress($address, $variables); if(isset($this->message[$headerName])){ @@ -48,16 +48,16 @@ class BatchMessage extends MessageBuilder{ else{ $this->message[$headerName] = array($compiledAddress); } - + if(array_key_exists($headerName, $this->counters['recipients'])){ $this->counters['recipients'][$headerName] += 1; if(!array_key_exists("id", $variables)){ $variables['id'] = $this->counters['recipients'][$headerName]; } - } + } $this->batchRecipientAttributes["$address"] = $variables; } - + public function sendMessage($message = array(), $files = array()){ if(count($message) < 1){ $message = $this->message; @@ -75,7 +75,7 @@ class BatchMessage extends MessageBuilder{ elseif((!array_key_exists("text", $message) && !array_key_exists("html", $message))){ throw new MissingRequiredMIMEParameters(EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS); } - else{ + else{ $message["recipient-variables"] = json_encode($this->batchRecipientAttributes); $response = $this->restClient->post($this->endpointUrl, $message, $files); $this->batchRecipientAttributes = array(); @@ -86,7 +86,7 @@ class BatchMessage extends MessageBuilder{ array_push($this->messageIds, $response->http_response_body->id); } } - + public function finalize(){ return $this->sendMessage(); } @@ -95,4 +95,3 @@ class BatchMessage extends MessageBuilder{ return $this->messageIds; } } -?> \ No newline at end of file diff --git a/src/Mailgun/Messages/Exceptions/InvalidParameter.php b/src/Mailgun/Messages/Exceptions/InvalidParameter.php index cc36ef1..9ea1dfc 100644 --- a/src/Mailgun/Messages/Exceptions/InvalidParameter.php +++ b/src/Mailgun/Messages/Exceptions/InvalidParameter.php @@ -2,5 +2,3 @@ namespace Mailgun\Messages\Exceptions; class InvalidParameter extends \Exception{} - -?> \ No newline at end of file diff --git a/src/Mailgun/Messages/Exceptions/InvalidParameterType.php b/src/Mailgun/Messages/Exceptions/InvalidParameterType.php index b77885c..aae7f34 100644 --- a/src/Mailgun/Messages/Exceptions/InvalidParameterType.php +++ b/src/Mailgun/Messages/Exceptions/InvalidParameterType.php @@ -2,5 +2,3 @@ namespace Mailgun\Messages\Exceptions; class InvalidParameterType extends \Exception{} - -?> \ No newline at end of file diff --git a/src/Mailgun/Messages/Exceptions/MissingRequiredMIMEParameters.php b/src/Mailgun/Messages/Exceptions/MissingRequiredMIMEParameters.php index 754f47e..cf5fb89 100644 --- a/src/Mailgun/Messages/Exceptions/MissingRequiredMIMEParameters.php +++ b/src/Mailgun/Messages/Exceptions/MissingRequiredMIMEParameters.php @@ -2,5 +2,3 @@ namespace Mailgun\Messages\Exceptions; class MissingRequiredMIMEParameters extends \Exception{} - -?> \ No newline at end of file diff --git a/src/Mailgun/Messages/Exceptions/TooManyParameters.php b/src/Mailgun/Messages/Exceptions/TooManyParameters.php index 3a43bb3..78a3104 100644 --- a/src/Mailgun/Messages/Exceptions/TooManyParameters.php +++ b/src/Mailgun/Messages/Exceptions/TooManyParameters.php @@ -2,5 +2,3 @@ namespace Mailgun\Messages\Exceptions; class TooManyParameters extends \Exception{} - -?> \ No newline at end of file diff --git a/src/Mailgun/Messages/MessageBuilder.php b/src/Mailgun/Messages/MessageBuilder.php index bf33269..bf47871 100644 --- a/src/Mailgun/Messages/MessageBuilder.php +++ b/src/Mailgun/Messages/MessageBuilder.php @@ -6,11 +6,11 @@ use Mailgun\Messages\Exceptions\InvalidParameter; use Mailgun\Messages\Exceptions\TooManyParameters; use Mailgun\Messages\Exceptions\InvalidParameterType; -/* - This class is used for composing a properly formed - message object. Dealing with arrays can be cumbersome, - this class makes the process easier. See the official - documentation for usage instructions. +/* + This class is used for composing a properly formed + message object. Dealing with arrays can be cumbersome, + this class makes the process easier. See the official + documentation for usage instructions. */ class MessageBuilder @@ -353,5 +353,3 @@ class MessageBuilder return $this->files; } } - -?> diff --git a/tests/Mailgun/Tests/Connection/ConnectionTest.php b/tests/Mailgun/Tests/Connection/ConnectionTest.php index d7376d7..aed26de 100644 --- a/tests/Mailgun/Tests/Connection/ConnectionTest.php +++ b/tests/Mailgun/Tests/Connection/ConnectionTest.php @@ -17,5 +17,3 @@ class ConnectionTest extends \Mailgun\Tests\MailgunTestCase $this->client = new Mailgun("My-Super-Awesome-API-Key", "samples.mailgun.org", false); } } - -?> \ No newline at end of file diff --git a/tests/Mailgun/Tests/Lists/OptInHandlerTest.php b/tests/Mailgun/Tests/Lists/OptInHandlerTest.php index e42bc47..ed4d98a 100644 --- a/tests/Mailgun/Tests/Lists/OptInHandlerTest.php +++ b/tests/Mailgun/Tests/Lists/OptInHandlerTest.php @@ -46,5 +46,3 @@ class OptInHandler extends \Mailgun\Tests\MailgunTestCase $this->assertFalse($validation); } } - -?> \ No newline at end of file diff --git a/tests/Mailgun/Tests/MailgunTest.php b/tests/Mailgun/Tests/MailgunTest.php index 3747a02..05e10cd 100644 --- a/tests/Mailgun/Tests/MailgunTest.php +++ b/tests/Mailgun/Tests/MailgunTest.php @@ -14,5 +14,3 @@ class MailgunTest extends \Mailgun\Tests\MailgunTestCase $client->sendMessage("test.mailgun.com", "etss", 1); } } - -?> \ No newline at end of file diff --git a/tests/Mailgun/Tests/MailgunTestCase.php b/tests/Mailgun/Tests/MailgunTestCase.php index febcd87..0f476e8 100644 --- a/tests/Mailgun/Tests/MailgunTestCase.php +++ b/tests/Mailgun/Tests/MailgunTestCase.php @@ -7,5 +7,3 @@ use Guzzle\Tests\GuzzleTestCase; abstract class MailgunTestCase extends GuzzleTestCase { } - -?> \ No newline at end of file diff --git a/tests/Mailgun/Tests/Messages/BatchMessageTest.php b/tests/Mailgun/Tests/Messages/BatchMessageTest.php index b21785b..05a39a1 100644 --- a/tests/Mailgun/Tests/Messages/BatchMessageTest.php +++ b/tests/Mailgun/Tests/Messages/BatchMessageTest.php @@ -170,75 +170,3 @@ class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase $message->sendMessage(array("from" => 1, "to" => 2, "subject" => 3)); } } - -?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tests/Mailgun/Tests/Messages/MessageBuilderTest.php b/tests/Mailgun/Tests/Messages/MessageBuilderTest.php index cec36c0..4a46eea 100644 --- a/tests/Mailgun/Tests/Messages/MessageBuilderTest.php +++ b/tests/Mailgun/Tests/Messages/MessageBuilderTest.php @@ -354,5 +354,3 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase $this->assertEquals($message, $messageBuilder->getMessage()); } } - -?> \ No newline at end of file diff --git a/tests/Mailgun/Tests/Messages/StandardMessageTest.php b/tests/Mailgun/Tests/Messages/StandardMessageTest.php index ff81bb9..b1f885d 100644 --- a/tests/Mailgun/Tests/Messages/StandardMessageTest.php +++ b/tests/Mailgun/Tests/Messages/StandardMessageTest.php @@ -46,5 +46,3 @@ class StandardMessageTest extends \Mailgun\Tests\MailgunTestCase } } - -?> \ No newline at end of file diff --git a/tests/Mailgun/Tests/Mock/Connection/TestBroker.php b/tests/Mailgun/Tests/Mock/Connection/TestBroker.php index 5922aa4..80ebbff 100644 --- a/tests/Mailgun/Tests/Mock/Connection/TestBroker.php +++ b/tests/Mailgun/Tests/Mock/Connection/TestBroker.php @@ -65,6 +65,3 @@ class TestBroker extends RestClient } - - -?> \ No newline at end of file diff --git a/tests/Mailgun/Tests/Mock/Mailgun.php b/tests/Mailgun/Tests/Mock/Mailgun.php index 62a0a29..092ec7d 100644 --- a/tests/Mailgun/Tests/Mock/Mailgun.php +++ b/tests/Mailgun/Tests/Mock/Mailgun.php @@ -15,6 +15,3 @@ class Mailgun extends Base $this->restClient = new TestBroker($apiKey, $apiEndpoint, $apiVersion); } } - - -?> \ No newline at end of file diff --git a/tests/Mailgun/Tests/TestAssets/mailgun_icon1.png b/tests/Mailgun/Tests/TestAssets/mailgun_icon1.png new file mode 100644 index 0000000..604f673 Binary files /dev/null and b/tests/Mailgun/Tests/TestAssets/mailgun_icon1.png differ diff --git a/tests/Mailgun/Tests/TestAssets/mailgun_icon2.png b/tests/Mailgun/Tests/TestAssets/mailgun_icon2.png new file mode 100644 index 0000000..604f673 Binary files /dev/null and b/tests/Mailgun/Tests/TestAssets/mailgun_icon2.png differ