mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2025-02-06 08:19:25 +03:00
Merge pull request #29 from travelton/RenameFiles
Ability to rename attachments and inline images & Duplicate Post/Put Fields
This commit is contained in:
commit
cfa02122c9
13
CHANGELOG.md
13
CHANGELOG.md
@ -1,3 +1,16 @@
|
|||||||
|
## 1.6 (2014-1-13)
|
||||||
|
|
||||||
|
Enhancement:
|
||||||
|
- adjust file attachment/inline name (#21 @travelton)
|
||||||
|
|
||||||
|
Bugfixes:
|
||||||
|
- fixed issue with unordered route actions (#23 @travelton)
|
||||||
|
|
||||||
|
## 1.5 (2013-12-13)
|
||||||
|
|
||||||
|
Enhancement:
|
||||||
|
- added ability to define non-https endpoint for debugging purposes (#23 @travelton)
|
||||||
|
|
||||||
## 1.4 (2013-10-16)
|
## 1.4 (2013-10-16)
|
||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
@ -22,7 +22,7 @@ composer and the Mailgun SDK.
|
|||||||
curl -sS https://getcomposer.org/installer | php
|
curl -sS https://getcomposer.org/installer | php
|
||||||
|
|
||||||
# Add Mailgun as a dependency
|
# Add Mailgun as a dependency
|
||||||
php composer.phar require mailgun/mailgun-php:~1.5
|
php composer.phar require mailgun/mailgun-php:~1.6
|
||||||
```
|
```
|
||||||
|
|
||||||
**For shared hosts without SSH access, check out our [Shared Host Instructions](SharedHostInstall.md).**
|
**For shared hosts without SSH access, check out our [Shared Host Instructions](SharedHostInstall.md).**
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"name": "mailgun/mailgun-php",
|
"name": "mailgun/mailgun-php",
|
||||||
"description": "The Mailgun SDK provides methods for all API functions.",
|
"description": "The Mailgun SDK provides methods for all API functions.",
|
||||||
"require": {
|
"require": {
|
||||||
"guzzle/guzzle": "3.7.*"
|
"guzzle/guzzle": "3.8.*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "3.7.*"
|
"phpunit/phpunit": "3.7.*"
|
||||||
|
@ -6,6 +6,7 @@ use Guzzle\Http\Client as Guzzle;
|
|||||||
use Mailgun\MailgunClient;
|
use Mailgun\MailgunClient;
|
||||||
|
|
||||||
use Mailgun\Connection\Exceptions\GenericHTTPError;
|
use Mailgun\Connection\Exceptions\GenericHTTPError;
|
||||||
|
use Guzzle\Http\QueryAggregator\DuplicateAggregator;
|
||||||
use Mailgun\Connection\Exceptions\InvalidCredentials;
|
use Mailgun\Connection\Exceptions\InvalidCredentials;
|
||||||
use Mailgun\Connection\Exceptions\NoDomainsConfigured;
|
use Mailgun\Connection\Exceptions\NoDomainsConfigured;
|
||||||
use Mailgun\Connection\Exceptions\MissingRequiredParameters;
|
use Mailgun\Connection\Exceptions\MissingRequiredParameters;
|
||||||
@ -39,15 +40,32 @@ class RestClient{
|
|||||||
}
|
}
|
||||||
if(isset($files["attachment"])){
|
if(isset($files["attachment"])){
|
||||||
foreach($files["attachment"] as $attachment){
|
foreach($files["attachment"] as $attachment){
|
||||||
$request->addPostFile("attachment", $attachment);
|
// Backward compatibility code
|
||||||
|
if (is_array($attachment)){
|
||||||
|
$request->addPostFile("attachment",
|
||||||
|
$attachment['filePath'], null,
|
||||||
|
$attachment['remoteName']);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$request->addPostFile("attachment", $attachment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(isset($files["inline"])){
|
if(isset($files["inline"])){
|
||||||
foreach($files["inline"] as $attachment){
|
foreach($files["inline"] as $inline){
|
||||||
$request->addPostFile("inline", $attachment);
|
// Backward compatibility code
|
||||||
|
if (is_array($inline)){
|
||||||
|
$request->addPostFile("inline",
|
||||||
|
$inline['filePath'], null,
|
||||||
|
$inline['remoteName']);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$request->addPostFile("inline", $inline);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$request->getPostFields()->setAggregator(new DuplicateAggregator());
|
||||||
$response = $request->send();
|
$response = $request->send();
|
||||||
return $this->responseHandler($response);
|
return $this->responseHandler($response);
|
||||||
}
|
}
|
||||||
@ -71,6 +89,7 @@ class RestClient{
|
|||||||
|
|
||||||
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());
|
||||||
$response = $request->send();
|
$response = $request->send();
|
||||||
return $this->responseHandler($response);
|
return $this->responseHandler($response);
|
||||||
}
|
}
|
||||||
|
@ -136,13 +136,16 @@ class MessageBuilder{
|
|||||||
return $this->message['html'];
|
return $this->message['html'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addAttachment($attachmentPath){
|
public function addAttachment($attachmentPath, $attachmentName = null){
|
||||||
if(preg_match("/^@/", $attachmentPath)){
|
if(preg_match("/^@/", $attachmentPath)){
|
||||||
if(isset($this->files["attachment"])){
|
if(isset($this->files["attachment"])){
|
||||||
array_push($this->files["attachment"], $attachmentPath);
|
$attachment = array('filePath' => $attachmentPath,
|
||||||
|
'remoteName' => $attachmentName);
|
||||||
|
array_push($this->files["attachment"], $attachment);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$this->files["attachment"] = array($attachmentPath);
|
$this->files["attachment"] = array(array('filePath' => $attachmentPath,
|
||||||
|
'remoteName' => $attachmentName));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -151,16 +154,18 @@ class MessageBuilder{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addInlineImage($inlineImagePath){
|
public function addInlineImage($inlineImagePath, $inlineImageName = null){
|
||||||
if(preg_match("/^@/", $inlineImagePath)){
|
if(preg_match("/^@/", $inlineImagePath)){
|
||||||
if(isset($this->files['inline'])){
|
if(isset($this->files['inline'])){
|
||||||
array_push($this->files['inline'] , $inlineImagePath);
|
$inlineAttachment = array('filePath' => $inlineImagePath,
|
||||||
return true;
|
'remoteName' => $inlineImageName);
|
||||||
|
array_push($this->files['inline'] , $inlineAttachment);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$this->files['inline'] = array($inlineImagePath);
|
$this->files['inline'] = array(array('filePath' => $inlineImagePath,
|
||||||
return true;
|
'remoteName' => $inlineImageName));
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
throw new InvalidParameter(INVALID_PARAMETER_INLINE);
|
throw new InvalidParameter(INVALID_PARAMETER_INLINE);
|
||||||
|
@ -117,14 +117,40 @@ class MessageBuilderTest extends \Mailgun\Tests\MailgunTestCase{
|
|||||||
$message->addAttachment("@../TestAssets/mailgun_icon.png");
|
$message->addAttachment("@../TestAssets/mailgun_icon.png");
|
||||||
$message->addAttachment("@../TestAssets/rackspace_logo.png");
|
$message->addAttachment("@../TestAssets/rackspace_logo.png");
|
||||||
$messageObj = $message->getFiles();
|
$messageObj = $message->getFiles();
|
||||||
$this->assertEquals(array("attachment" => array("@../TestAssets/mailgun_icon.png", "@../TestAssets/rackspace_logo.png")), $messageObj);
|
$this->assertEquals(array(array('filePath' => "@../TestAssets/mailgun_icon.png",
|
||||||
|
'remoteName' => null),
|
||||||
|
array('filePath' => "@../TestAssets/rackspace_logo.png",
|
||||||
|
'remoteName' => null)), $messageObj["attachment"]);
|
||||||
}
|
}
|
||||||
public function testAddInlineImages(){
|
public function testAddInlineImages(){
|
||||||
$message = $this->client->MessageBuilder();
|
$message = $this->client->MessageBuilder();
|
||||||
$message->addInlineImage("@../TestAssets/mailgun_icon.png");
|
$message->addInlineImage("@../TestAssets/mailgun_icon.png");
|
||||||
$message->addInlineImage("@../TestAssets/rackspace_logo.png");
|
$message->addInlineImage("@../TestAssets/rackspace_logo.png");
|
||||||
$messageObj = $message->getFiles();
|
$messageObj = $message->getFiles();
|
||||||
$this->assertEquals(array("inline" => array("@../TestAssets/mailgun_icon.png", "@../TestAssets/rackspace_logo.png")), $messageObj);
|
$this->assertEquals(array(array('filePath' => "@../TestAssets/mailgun_icon.png",
|
||||||
|
'remoteName' => null),
|
||||||
|
array('filePath' => "@../TestAssets/rackspace_logo.png",
|
||||||
|
'remoteName' => null)), $messageObj['inline']);
|
||||||
|
}
|
||||||
|
public function testAddAttachmentsPostName(){
|
||||||
|
$message = $this->client->MessageBuilder();
|
||||||
|
$message->addAttachment('@../TestAssets/mailgun_icon.png', 'mg_icon.png');
|
||||||
|
$message->addAttachment('@../TestAssets/rackspace_logo.png', 'rs_logo.png');
|
||||||
|
$messageObj = $message->getFiles();
|
||||||
|
$this->assertEquals(array(array('filePath' => '@../TestAssets/mailgun_icon.png',
|
||||||
|
'remoteName' => 'mg_icon.png'),
|
||||||
|
array('filePath' => '@../TestAssets/rackspace_logo.png',
|
||||||
|
'remoteName' => 'rs_logo.png')), $messageObj["attachment"]);
|
||||||
|
}
|
||||||
|
public function testAddInlineImagePostName(){
|
||||||
|
$message = $this->client->MessageBuilder();
|
||||||
|
$message->addInlineImage('@../TestAssets/mailgun_icon.png', 'mg_icon.png');
|
||||||
|
$message->addInlineImage('@../TestAssets/rackspace_logo.png', 'rs_logo.png');
|
||||||
|
$messageObj = $message->getFiles();
|
||||||
|
$this->assertEquals(array(array('filePath' => '@../TestAssets/mailgun_icon.png',
|
||||||
|
'remoteName' => 'mg_icon.png'),
|
||||||
|
array('filePath' => '@../TestAssets/rackspace_logo.png',
|
||||||
|
'remoteName' => 'rs_logo.png')), $messageObj['inline']);
|
||||||
}
|
}
|
||||||
public function testsetTestMode(){
|
public function testsetTestMode(){
|
||||||
$message = $this->client->MessageBuilder();
|
$message = $this->client->MessageBuilder();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user