Removed legacy PHP closing braces

This commit is contained in:
Travis Swientek 2014-10-06 15:53:33 -07:00
parent 7f2fa66030
commit f781158019
25 changed files with 53 additions and 171 deletions

View File

@ -2,5 +2,3 @@
namespace Mailgun\Connection\Exceptions; namespace Mailgun\Connection\Exceptions;
class GenericHTTPError extends \Exception{} class GenericHTTPError extends \Exception{}
?>

View File

@ -2,5 +2,3 @@
namespace Mailgun\Connection\Exceptions; namespace Mailgun\Connection\Exceptions;
class InvalidCredentials extends \Exception{} class InvalidCredentials extends \Exception{}
?>

View File

@ -2,5 +2,3 @@
namespace Mailgun\Connection\Exceptions; namespace Mailgun\Connection\Exceptions;
class MissingEndpoint extends \Exception{} class MissingEndpoint extends \Exception{}
?>

View File

@ -2,5 +2,3 @@
namespace Mailgun\Connection\Exceptions; namespace Mailgun\Connection\Exceptions;
class MissingRequiredParameters extends \Exception{} class MissingRequiredParameters extends \Exception{}
?>

View File

@ -2,5 +2,3 @@
namespace Mailgun\Connection\Exceptions; namespace Mailgun\Connection\Exceptions;
class NoDomainsConfigured extends \Exception{} class NoDomainsConfigured extends \Exception{}
?>

View File

@ -13,8 +13,8 @@ use Mailgun\Connection\Exceptions\NoDomainsConfigured;
use Mailgun\Connection\Exceptions\MissingRequiredParameters; use Mailgun\Connection\Exceptions\MissingRequiredParameters;
use Mailgun\Connection\Exceptions\MissingEndpoint; 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{ class RestClient{
@ -22,19 +22,19 @@ class RestClient{
private $apiKey; private $apiKey;
protected $mgClient; protected $mgClient;
protected $hasFiles = False; protected $hasFiles = False;
public function __construct($apiKey, $apiEndpoint, $apiVersion, $ssl){ public function __construct($apiKey, $apiEndpoint, $apiVersion, $ssl){
$this->apiKey = $apiKey; $this->apiKey = $apiKey;
$this->mgClient = new Guzzle($this->generateEndpoint($apiEndpoint, $apiVersion, $ssl)); $this->mgClient = new Guzzle($this->generateEndpoint($apiEndpoint, $apiVersion, $ssl));
$this->mgClient->setDefaultOption('curl.options', array('CURLOPT_FORBID_REUSE' => true)); $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->setDefaultOption('exceptions', false);
$this->mgClient->setUserAgent(SDK_USER_AGENT . '/' . SDK_VERSION); $this->mgClient->setUserAgent(SDK_USER_AGENT . '/' . SDK_VERSION);
} }
public function post($endpointUrl, $postData = array(), $files = array()){ public function post($endpointUrl, $postData = array(), $files = array()){
$request = $this->mgClient->post($endpointUrl, array(), $postData); $request = $this->mgClient->post($endpointUrl, array(), $postData);
if(isset($files["message"])){ if(isset($files["message"])){
$this->hasFiles = True; $this->hasFiles = True;
foreach($files as $message){ foreach($files as $message){
@ -47,9 +47,9 @@ class RestClient{
foreach($files["attachment"] as $attachment){ foreach($files["attachment"] as $attachment){
// Backward compatibility code // Backward compatibility code
if (is_array($attachment)){ if (is_array($attachment)){
$request->addPostFile("attachment", $request->addPostFile("attachment",
$attachment['filePath'], null, $attachment['filePath'], null,
$attachment['remoteName']); $attachment['remoteName']);
} }
else{ else{
$request->addPostFile("attachment", $attachment); $request->addPostFile("attachment", $attachment);
@ -62,58 +62,58 @@ class RestClient{
foreach($files["inline"] as $inline){ foreach($files["inline"] as $inline){
// Backward compatibility code // Backward compatibility code
if (is_array($inline)){ if (is_array($inline)){
$request->addPostFile("inline", $request->addPostFile("inline",
$inline['filePath'], null, $inline['filePath'], null,
$inline['remoteName']); $inline['remoteName']);
} }
else{ else{
$request->addPostFile("inline", $inline); $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. See https://github.com/guzzle/guzzle/issues/545.
It can be removed when Guzzle resolves the issue. It can be removed when Guzzle resolves the issue.
*/ */
if($this->hasFiles){ if($this->hasFiles){
$request->getPostFields()->setAggregator(new PhpAggregator()); $request->getPostFields()->setAggregator(new PhpAggregator());
} }
else{ else{
$request->getPostFields()->setAggregator(new DuplicateAggregator()); $request->getPostFields()->setAggregator(new DuplicateAggregator());
} }
$response = $request->send(); $response = $request->send();
return $this->responseHandler($response); return $this->responseHandler($response);
} }
public function get($endpointUrl, $queryString = array()){ public function get($endpointUrl, $queryString = array()){
$request = $this->mgClient->get($endpointUrl); $request = $this->mgClient->get($endpointUrl);
if(isset($queryString)){ if(isset($queryString)){
foreach($queryString as $key=>$value){ foreach($queryString as $key=>$value){
$request->getQuery()->set($key, $value); $request->getQuery()->set($key, $value);
} }
} }
$response = $request->send(); $response = $request->send();
return $this->responseHandler($response); return $this->responseHandler($response);
} }
public function delete($endpointUrl){ public function delete($endpointUrl){
$request = $this->mgClient->delete($endpointUrl); $request = $this->mgClient->delete($endpointUrl);
$response = $request->send(); $response = $request->send();
return $this->responseHandler($response); return $this->responseHandler($response);
} }
public function put($endpointUrl, $putData){ public function put($endpointUrl, $putData){
$request = $this->mgClient->put($endpointUrl, array(), $putData); $request = $this->mgClient->put($endpointUrl, array(), $putData);
$request->getPostFields()->setAggregator(new DuplicateAggregator()); $request->getPostFields()->setAggregator(new DuplicateAggregator());
$response = $request->send(); $response = $request->send();
return $this->responseHandler($response); return $this->responseHandler($response);
} }
public function responseHandler($responseObj){ public function responseHandler($responseObj){
$httpResponseCode = $responseObj->getStatusCode(); $httpResponseCode = $responseObj->getStatusCode();
if($httpResponseCode === 200){ if($httpResponseCode === 200){
@ -146,5 +146,3 @@ class RestClient{
} }
} }
} }
?>

View File

@ -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_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_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."; const TOO_MANY_PARAMETERS_RECIPIENT = "You've exceeded the maximum recipient count (1,000) on the to field with autosend disabled.";
?>

View File

@ -11,30 +11,30 @@ use Mailgun\Messages\BatchMessage;
use Mailgun\Lists\OptInHandler; use Mailgun\Lists\OptInHandler;
use Mailgun\Messages\MessageBuilder; use Mailgun\Messages\MessageBuilder;
/* /*
This class is the base class for the Mailgun SDK. This class is the base class for the Mailgun SDK.
See the official documentation for usage instructions. See the official documentation for usage instructions.
*/ */
class Mailgun{ class Mailgun{
protected $workingDomain; protected $workingDomain;
protected $restClient; protected $restClient;
public function __construct($apiKey = null, $apiEndpoint = "api.mailgun.net", $apiVersion = "v2", $ssl = true){ public function __construct($apiKey = null, $apiEndpoint = "api.mailgun.net", $apiVersion = "v2", $ssl = true){
$this->restClient = new RestClient($apiKey, $apiEndpoint, $apiVersion, $ssl); $this->restClient = new RestClient($apiKey, $apiEndpoint, $apiVersion, $ssl);
} }
public function sendMessage($workingDomain, $postData, $postFiles = array()){ public function sendMessage($workingDomain, $postData, $postFiles = array()){
/* /*
This function allows the sending of a fully formed message OR a custom 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 MIME string. If sending MIME, the string must be passed in to the 3rd
position of the function call. position of the function call.
*/ */
if(is_array($postFiles)){ if(is_array($postFiles)){
return $this->post("$workingDomain/messages", $postData, $postFiles); return $this->post("$workingDomain/messages", $postData, $postFiles);
} }
else if(is_string($postFiles)){ else if(is_string($postFiles)){
@ -55,30 +55,28 @@ class Mailgun{
public function post($endpointUrl, $postData = array(), $files = array()){ public function post($endpointUrl, $postData = array(), $files = array()){
return $this->restClient->post($endpointUrl, $postData, $files); return $this->restClient->post($endpointUrl, $postData, $files);
} }
public function get($endpointUrl, $queryString = array()){ public function get($endpointUrl, $queryString = array()){
return $this->restClient->get($endpointUrl, $queryString); return $this->restClient->get($endpointUrl, $queryString);
} }
public function delete($endpointUrl){ public function delete($endpointUrl){
return $this->restClient->delete($endpointUrl); return $this->restClient->delete($endpointUrl);
} }
public function put($endpointUrl, $putData){ public function put($endpointUrl, $putData){
return $this->restClient->put($endpointUrl, $putData); return $this->restClient->put($endpointUrl, $putData);
} }
public function MessageBuilder(){ public function MessageBuilder(){
return new MessageBuilder(); return new MessageBuilder();
} }
public function OptInHandler(){ public function OptInHandler(){
return new OptInHandler(); return new OptInHandler();
} }
public function BatchMessage($workingDomain, $autoSend = true){ public function BatchMessage($workingDomain, $autoSend = true){
return new BatchMessage($this->restClient, $workingDomain, $autoSend); return new BatchMessage($this->restClient, $workingDomain, $autoSend);
} }
} }
?>

View File

@ -6,9 +6,9 @@ use Mailgun\Messages\MessageBuilder;
use Mailgun\Messages\Exceptions\TooManyParameters; use Mailgun\Messages\Exceptions\TooManyParameters;
use Mailgun\Messages\Exceptions\MissingRequiredMIMEParameters; use Mailgun\Messages\Exceptions\MissingRequiredMIMEParameters;
/* /*
This class is used for batch sending. See the official documentation This class is used for batch sending. See the official documentation
for usage instructions. for usage instructions.
*/ */
class BatchMessage extends MessageBuilder{ class BatchMessage extends MessageBuilder{
@ -26,7 +26,7 @@ class BatchMessage extends MessageBuilder{
$this->workingDomain = $workingDomain; $this->workingDomain = $workingDomain;
$this->endpointUrl = $workingDomain . "/messages"; $this->endpointUrl = $workingDomain . "/messages";
} }
protected function addRecipient($headerName, $address, $variables){ protected function addRecipient($headerName, $address, $variables){
if(array_key_exists($headerName, $this->counters['recipients'])){ if(array_key_exists($headerName, $this->counters['recipients'])){
if($this->counters['recipients'][$headerName] == RECIPIENT_COUNT_LIMIT){ if($this->counters['recipients'][$headerName] == RECIPIENT_COUNT_LIMIT){
@ -36,7 +36,7 @@ class BatchMessage extends MessageBuilder{
$this->sendMessage(); $this->sendMessage();
} }
} }
$compiledAddress = $this->parseAddress($address, $variables); $compiledAddress = $this->parseAddress($address, $variables);
if(isset($this->message[$headerName])){ if(isset($this->message[$headerName])){
@ -48,16 +48,16 @@ class BatchMessage extends MessageBuilder{
else{ else{
$this->message[$headerName] = array($compiledAddress); $this->message[$headerName] = array($compiledAddress);
} }
if(array_key_exists($headerName, $this->counters['recipients'])){ if(array_key_exists($headerName, $this->counters['recipients'])){
$this->counters['recipients'][$headerName] += 1; $this->counters['recipients'][$headerName] += 1;
if(!array_key_exists("id", $variables)){ if(!array_key_exists("id", $variables)){
$variables['id'] = $this->counters['recipients'][$headerName]; $variables['id'] = $this->counters['recipients'][$headerName];
} }
} }
$this->batchRecipientAttributes["$address"] = $variables; $this->batchRecipientAttributes["$address"] = $variables;
} }
public function sendMessage($message = array(), $files = array()){ public function sendMessage($message = array(), $files = array()){
if(count($message) < 1){ if(count($message) < 1){
$message = $this->message; $message = $this->message;
@ -75,7 +75,7 @@ class BatchMessage extends MessageBuilder{
elseif((!array_key_exists("text", $message) && !array_key_exists("html", $message))){ elseif((!array_key_exists("text", $message) && !array_key_exists("html", $message))){
throw new MissingRequiredMIMEParameters(EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS); throw new MissingRequiredMIMEParameters(EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS);
} }
else{ else{
$message["recipient-variables"] = json_encode($this->batchRecipientAttributes); $message["recipient-variables"] = json_encode($this->batchRecipientAttributes);
$response = $this->restClient->post($this->endpointUrl, $message, $files); $response = $this->restClient->post($this->endpointUrl, $message, $files);
$this->batchRecipientAttributes = array(); $this->batchRecipientAttributes = array();
@ -86,7 +86,7 @@ class BatchMessage extends MessageBuilder{
array_push($this->messageIds, $response->http_response_body->id); array_push($this->messageIds, $response->http_response_body->id);
} }
} }
public function finalize(){ public function finalize(){
return $this->sendMessage(); return $this->sendMessage();
} }
@ -95,4 +95,3 @@ class BatchMessage extends MessageBuilder{
return $this->messageIds; return $this->messageIds;
} }
} }
?>

View File

@ -2,5 +2,3 @@
namespace Mailgun\Messages\Exceptions; namespace Mailgun\Messages\Exceptions;
class InvalidParameter extends \Exception{} class InvalidParameter extends \Exception{}
?>

View File

@ -2,5 +2,3 @@
namespace Mailgun\Messages\Exceptions; namespace Mailgun\Messages\Exceptions;
class InvalidParameterType extends \Exception{} class InvalidParameterType extends \Exception{}
?>

View File

@ -2,5 +2,3 @@
namespace Mailgun\Messages\Exceptions; namespace Mailgun\Messages\Exceptions;
class MissingRequiredMIMEParameters extends \Exception{} class MissingRequiredMIMEParameters extends \Exception{}
?>

View File

@ -2,5 +2,3 @@
namespace Mailgun\Messages\Exceptions; namespace Mailgun\Messages\Exceptions;
class TooManyParameters extends \Exception{} class TooManyParameters extends \Exception{}
?>

View File

@ -6,11 +6,11 @@ use Mailgun\Messages\Exceptions\InvalidParameter;
use Mailgun\Messages\Exceptions\TooManyParameters; use Mailgun\Messages\Exceptions\TooManyParameters;
use Mailgun\Messages\Exceptions\InvalidParameterType; use Mailgun\Messages\Exceptions\InvalidParameterType;
/* /*
This class is used for composing a properly formed This class is used for composing a properly formed
message object. Dealing with arrays can be cumbersome, message object. Dealing with arrays can be cumbersome,
this class makes the process easier. See the official this class makes the process easier. See the official
documentation for usage instructions. documentation for usage instructions.
*/ */
class MessageBuilder class MessageBuilder
@ -353,5 +353,3 @@ class MessageBuilder
return $this->files; return $this->files;
} }
} }
?>

View File

@ -17,5 +17,3 @@ class ConnectionTest extends \Mailgun\Tests\MailgunTestCase
$this->client = new Mailgun("My-Super-Awesome-API-Key", "samples.mailgun.org", false); $this->client = new Mailgun("My-Super-Awesome-API-Key", "samples.mailgun.org", false);
} }
} }
?>

View File

@ -46,5 +46,3 @@ class OptInHandler extends \Mailgun\Tests\MailgunTestCase
$this->assertFalse($validation); $this->assertFalse($validation);
} }
} }
?>

View File

@ -14,5 +14,3 @@ class MailgunTest extends \Mailgun\Tests\MailgunTestCase
$client->sendMessage("test.mailgun.com", "etss", 1); $client->sendMessage("test.mailgun.com", "etss", 1);
} }
} }
?>

View File

@ -7,5 +7,3 @@ use Guzzle\Tests\GuzzleTestCase;
abstract class MailgunTestCase extends GuzzleTestCase abstract class MailgunTestCase extends GuzzleTestCase
{ {
} }
?>

View File

@ -170,75 +170,3 @@ class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase
$message->sendMessage(array("from" => 1, "to" => 2, "subject" => 3)); $message->sendMessage(array("from" => 1, "to" => 2, "subject" => 3));
} }
} }
?>

View File

@ -354,5 +354,3 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
$this->assertEquals($message, $messageBuilder->getMessage()); $this->assertEquals($message, $messageBuilder->getMessage());
} }
} }
?>

View File

@ -46,5 +46,3 @@ class StandardMessageTest extends \Mailgun\Tests\MailgunTestCase
} }
} }
?>

View File

@ -65,6 +65,3 @@ class TestBroker extends RestClient
} }
?>

View File

@ -15,6 +15,3 @@ class Mailgun extends Base
$this->restClient = new TestBroker($apiKey, $apiEndpoint, $apiVersion); $this->restClient = new TestBroker($apiKey, $apiEndpoint, $apiVersion);
} }
} }
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB