From 8d23a5bb9f36db8594836329b3905d0dfb137da7 Mon Sep 17 00:00:00 2001 From: Travis Swientek Date: Thu, 30 Jan 2014 16:48:41 -0800 Subject: [PATCH] This patch swaps the aggregator to "PHPAggregator" if files are included. Also added straight download. --- CHANGELOG.md | 5 +++++ README.md | 4 +++- SharedHostInstall.md | 4 ++-- src/Mailgun/Connection/RestClient.php | 22 +++++++++++++++++++++- src/Mailgun/Constants/Constants.php | 2 +- 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c9afc7..550fd76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.7 (2014-1-30) + +Bugfixes: + - patched bug for attachments related to duplicate aggregator bug in Guzzle (#32 @travelton) + ## 1.6 (2014-1-13) Enhancement: diff --git a/README.md b/README.md index 77d5338..3faa2f7 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,13 @@ composer and the Mailgun SDK. curl -sS https://getcomposer.org/installer | php # Add Mailgun as a dependency -php composer.phar require mailgun/mailgun-php:~1.6 +php composer.phar require mailgun/mailgun-php:~1.7 ``` **For shared hosts without SSH access, check out our [Shared Host Instructions](SharedHostInstall.md).** +**Rather just download the files? [Library Download](https://9f67cbbd1116d8afb399-7760483f5d1e5f28c2d253278a2a5045.ssl.cf2.rackcdn.com/mailgun-php-1.7.zip).** + Next, require Composer's autoloader, in your application, to automatically load the Mailgun SDK in your project: ```PHP diff --git a/SharedHostInstall.md b/SharedHostInstall.md index c4d0b02..c6b4b8c 100644 --- a/SharedHostInstall.md +++ b/SharedHostInstall.md @@ -11,7 +11,7 @@ Linux / Mac OSX: *PHP is typically installed by default, consult your distribution documentation. Instructions from [getcomposer.org](http://getcomposer.org/doc/00-intro.md#installation-nix).* 1. curl -sS https://getcomposer.org/installer | php -2. php composer.phar require mailgun/mailgun-php:~1.6 +2. php composer.phar require mailgun/mailgun-php:~1.7 3. The files will be downloaded to your local computer. 4. Upload the files to your webserver. @@ -20,7 +20,7 @@ Windows: *PHP must be installed on your computer, [download](http://windows.php.net/download/0). Instructions from [getcomposer.org](http://getcomposer.org/doc/00-intro.md#installation-windows).* 1. Download and run [Composer-Setup.exe](https://getcomposer.org/Composer-Setup.exe). -2. Open a Command Prompt and type "php composer require mailgun/mailgun-php:~1.6". +2. Open a Command Prompt and type "php composer require mailgun/mailgun-php:~1.7". 3. The files will be downloaded to your local computer. 4. Upload the files to your webserver. diff --git a/src/Mailgun/Connection/RestClient.php b/src/Mailgun/Connection/RestClient.php index d32a92e..88bd574 100644 --- a/src/Mailgun/Connection/RestClient.php +++ b/src/Mailgun/Connection/RestClient.php @@ -7,6 +7,7 @@ use Mailgun\MailgunClient; use Mailgun\Connection\Exceptions\GenericHTTPError; use Guzzle\Http\QueryAggregator\DuplicateAggregator; +use Guzzle\Http\QueryAggregator\PhpAggregator; use Mailgun\Connection\Exceptions\InvalidCredentials; use Mailgun\Connection\Exceptions\NoDomainsConfigured; use Mailgun\Connection\Exceptions\MissingRequiredParameters; @@ -20,6 +21,7 @@ class RestClient{ private $apiKey; protected $mgClient; + protected $hasFiles = False; public function __construct($apiKey, $apiEndpoint, $apiVersion, $ssl){ $this->apiKey = $apiKey; @@ -34,11 +36,14 @@ class RestClient{ $request = $this->mgClient->post($endpointUrl, array(), $postData); if(isset($files["message"])){ + $this->hasFiles = True; foreach($files as $message){ $request->addPostFile("message", $message); } } + if(isset($files["attachment"])){ + $this->hasFiles = True; foreach($files["attachment"] as $attachment){ // Backward compatibility code if (is_array($attachment)){ @@ -51,7 +56,9 @@ class RestClient{ } } } + if(isset($files["inline"])){ + $this->hasFiles = True; foreach($files["inline"] as $inline){ // Backward compatibility code if (is_array($inline)){ @@ -65,7 +72,20 @@ class RestClient{ } } - $request->getPostFields()->setAggregator(new DuplicateAggregator()); + /* + 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()); + } + + else{ + $request->getPostFields()->setAggregator(new DuplicateAggregator()); + } + $response = $request->send(); return $this->responseHandler($response); } diff --git a/src/Mailgun/Constants/Constants.php b/src/Mailgun/Constants/Constants.php index d18fce7..0f0a053 100644 --- a/src/Mailgun/Constants/Constants.php +++ b/src/Mailgun/Constants/Constants.php @@ -1,7 +1,7 @@