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;
class GenericHTTPError extends \Exception{}
?>

View File

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

View File

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

View File

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

View File

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

View File

@ -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{
}
}
}
?>

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_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.";
?>

View File

@ -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);
}
}
?>

View File

@ -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;
}
}
?>

View File

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

View File

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

View File

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

View File

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

View File

@ -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;
}
}
?>

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);
}
}
?>

View File

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

View File

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

View File

@ -7,5 +7,3 @@ use Guzzle\Tests\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));
}
}
?>

View File

@ -354,5 +354,3 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase
$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);
}
}
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB