From a674addd2a717a55e3b2271d918189f764b882ab Mon Sep 17 00:00:00 2001 From: Joshua Chamberlain Date: Fri, 5 Sep 2014 15:07:55 -0700 Subject: [PATCH 1/3] Don't require @ prefix for attachment filenames --- src/Mailgun/Messages/MessageBuilder.php | 30 +++++++++++-------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/Mailgun/Messages/MessageBuilder.php b/src/Mailgun/Messages/MessageBuilder.php index bf33269..c9e53ae 100644 --- a/src/Mailgun/Messages/MessageBuilder.php +++ b/src/Mailgun/Messages/MessageBuilder.php @@ -169,26 +169,22 @@ class MessageBuilder public function addAttachment($attachmentPath, $attachmentName = null) { - if (preg_match("/^@/", $attachmentPath)) { - if (isset($this->files["attachment"])) { - $attachment = array( + if (isset($this->files["attachment"])) { + $attachment = array( + 'filePath' => $attachmentPath, + 'remoteName' => $attachmentName + ); + array_push($this->files["attachment"], $attachment); + } else { + $this->files["attachment"] = array( + array( 'filePath' => $attachmentPath, 'remoteName' => $attachmentName - ); - array_push($this->files["attachment"], $attachment); - } else { - $this->files["attachment"] = array( - array( - 'filePath' => $attachmentPath, - 'remoteName' => $attachmentName - ) - ); - } - - return true; - } else { - throw new InvalidParameter(INVALID_PARAMETER_ATTACHMENT); + ) + ); } + + return true; } public function addInlineImage($inlineImagePath, $inlineImageName = null) From f2af6df7263891775bb78530bf4ccf0edb1cbcff Mon Sep 17 00:00:00 2001 From: Joshua Chamberlain Date: Mon, 8 Sep 2014 12:11:04 -0700 Subject: [PATCH 2/3] Allow any data type for custom data --- src/Mailgun/Messages/MessageBuilder.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/Mailgun/Messages/MessageBuilder.php b/src/Mailgun/Messages/MessageBuilder.php index bf33269..a605821 100644 --- a/src/Mailgun/Messages/MessageBuilder.php +++ b/src/Mailgun/Messages/MessageBuilder.php @@ -314,15 +314,7 @@ class MessageBuilder public function addCustomData($customName, $data) { - if (is_array($data)) { - $jsonArray = json_encode($data); - $this->message['v:' . $customName] = $jsonArray; - - return $this->message['v:' . $customName]; - } else { - throw new InvalidParameter(INVALID_PARAMETER_NON_ARRAY); - } - + $this->message['v:' . $customName] = json_encode($data); } public function addCustomParameter($parameterName, $data) From c6346e80df49733c6734d2fa510de27e383030c5 Mon Sep 17 00:00:00 2001 From: Joshua Chamberlain Date: Mon, 15 Sep 2014 16:01:24 -0700 Subject: [PATCH 3/3] Return non-JSON response data --- src/Mailgun/Connection/RestClient.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Mailgun/Connection/RestClient.php b/src/Mailgun/Connection/RestClient.php index 88bd574..3fcdaa0 100644 --- a/src/Mailgun/Connection/RestClient.php +++ b/src/Mailgun/Connection/RestClient.php @@ -117,9 +117,11 @@ class RestClient{ public function responseHandler($responseObj){ $httpResponseCode = $responseObj->getStatusCode(); if($httpResponseCode === 200){ - $jsonResponseData = json_decode($responseObj->getBody(), false); + $data = (string) $responseObj->getBody(); + $jsonResponseData = json_decode($data, false); $result = new \stdClass(); - $result->http_response_body = $jsonResponseData; + // return response data as json if possible, raw if not + $result->http_response_body = $data && $jsonResponseData === null ? $data : $jsonResponseData; } elseif($httpResponseCode == 400){ throw new MissingRequiredParameters(EXCEPTION_MISSING_REQUIRED_PARAMETERS);