Merge pull request #33 from travelton/PatchAggregator

This patch swaps the aggregator to "PHPAggregator" if files are included...
This commit is contained in:
Travis Swientek 2014-01-30 17:09:06 -08:00
commit d8b57132d5
5 changed files with 32 additions and 5 deletions

View File

@ -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:

View File

@ -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

View File

@ -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.

View File

@ -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{
}
}
/*
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);
}

View File

@ -1,7 +1,7 @@
<?PHP
const API_USER = "api";
const SDK_VERSION = "1.11";
const SDK_VERSION = "1.7";
const SDK_USER_AGENT = "mailgun-sdk-php";
const RECIPIENT_COUNT_LIMIT = 1000;
const CAMPAIGN_ID_LIMIT = 3;