From 789eb27228023c831cc2be5b2f21b76486386c09 Mon Sep 17 00:00:00 2001 From: yoye Date: Thu, 5 Sep 2013 10:35:26 +0200 Subject: [PATCH 1/4] Fix bug toRecipientCount increment in BatchMessage --- .gitignore | 1 + src/Mailgun/Messages/BatchMessage.php | 1 - tests/Mailgun/Tests/Messages/BatchMessageTest.php | 9 +++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c469e72..cbc7bd2 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ rackspace_logo.jpg mailgun_icon.png build composer.lock +nbproject/* diff --git a/src/Mailgun/Messages/BatchMessage.php b/src/Mailgun/Messages/BatchMessage.php index 1e54036..2dceab6 100644 --- a/src/Mailgun/Messages/BatchMessage.php +++ b/src/Mailgun/Messages/BatchMessage.php @@ -38,7 +38,6 @@ class BatchMessage extends MessageBuilder{ $this->addRecipient("to", $address, $variables); $attributes["id"] = $this->toRecipientCount; $this->batchRecipientAttributes["$address"] = $variables; - $this->toRecipientCount++; } public function sendMessage($message = array(), $files = array()){ diff --git a/tests/Mailgun/Tests/Messages/BatchMessageTest.php b/tests/Mailgun/Tests/Messages/BatchMessageTest.php index d67cb11..6d17da6 100644 --- a/tests/Mailgun/Tests/Messages/BatchMessageTest.php +++ b/tests/Mailgun/Tests/Messages/BatchMessageTest.php @@ -50,6 +50,15 @@ class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase{ $messageObj= $message->getMessage(); $this->assertTrue(true, empty($messageObj)); } + public function testToRecipientCount() { + $message = $this->client->BatchMessage($this->sampleDomain); + $message->addToRecipient("test-user@samples.mailgun.org", array("first" => "Test", "last" => "User")); + + $reflectionClass = new \ReflectionClass(get_class($message)); + $property = $reflectionClass->getProperty('toRecipientCount'); + $property->setAccessible(true); + $this->assertEquals(1, $property->getValue($message)); + } } ?> From 4c80ff1058860e5461c2506057e5491e032ebeb2 Mon Sep 17 00:00:00 2001 From: yoye Date: Thu, 5 Sep 2013 10:39:20 +0200 Subject: [PATCH 2/4] Fix variables in BatchMessage:sendMessage() --- src/Mailgun/Messages/BatchMessage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mailgun/Messages/BatchMessage.php b/src/Mailgun/Messages/BatchMessage.php index 2dceab6..04a7715 100644 --- a/src/Mailgun/Messages/BatchMessage.php +++ b/src/Mailgun/Messages/BatchMessage.php @@ -58,7 +58,7 @@ class BatchMessage extends MessageBuilder{ throw new MissingRequiredMIMEParameters(EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS); } else{ - $this->message["recipient-variables"] = json_encode($this->batchRecipientAttributes); + $message["recipient-variables"] = json_encode($this->batchRecipientAttributes); $response = $this->restClient->post($this->endpointUrl, $message, $files); $this->batchRecipientAttributes = array(); $this->toRecipientCount = 0; From 95cc29e56b6ba598c04ddd0eed5f78ef953389c2 Mon Sep 17 00:00:00 2001 From: yoye Date: Thu, 5 Sep 2013 15:26:42 +0200 Subject: [PATCH 3/4] Fix typo in responseHandler --- src/Mailgun/Connection/RestClient.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Mailgun/Connection/RestClient.php b/src/Mailgun/Connection/RestClient.php index a026106..4ffeb59 100644 --- a/src/Mailgun/Connection/RestClient.php +++ b/src/Mailgun/Connection/RestClient.php @@ -88,9 +88,6 @@ class RestClient{ elseif($httpResponeCode == 401){ throw new InvalidCredentials(EXCEPTION_INVALID_CREDENTIALS); } - elseif($httpResponeCode == 401){ - throw new GenericHTTPError(EXCEPTION_INVALID_CREDENTIALS); - } elseif($httpResponeCode == 404){ throw new MissingEndpoint(EXCEPTION_MISSING_ENDPOINT); } From c445c4d8516959d57c953175069b8de69e662cbb Mon Sep 17 00:00:00 2001 From: yoye Date: Thu, 5 Sep 2013 15:34:17 +0200 Subject: [PATCH 4/4] Fix typo in responseHandler --- src/Mailgun/Connection/RestClient.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Mailgun/Connection/RestClient.php b/src/Mailgun/Connection/RestClient.php index 4ffeb59..7955c78 100644 --- a/src/Mailgun/Connection/RestClient.php +++ b/src/Mailgun/Connection/RestClient.php @@ -76,25 +76,25 @@ class RestClient{ } public function responseHandler($responseObj){ - $httpResponeCode = $responseObj->getStatusCode(); - if($httpResponeCode === 200){ + $httpResponseCode = $responseObj->getStatusCode(); + if($httpResponseCode === 200){ $jsonResponseData = json_decode($responseObj->getBody(), false); $result = new \stdClass(); $result->http_response_body = $jsonResponseData; } - elseif($httpResponeCode == 400){ + elseif($httpResponseCode == 400){ throw new MissingRequiredParameters(EXCEPTION_MISSING_REQUIRED_PARAMETERS); } - elseif($httpResponeCode == 401){ + elseif($httpResponseCode == 401){ throw new InvalidCredentials(EXCEPTION_INVALID_CREDENTIALS); } - elseif($httpResponeCode == 404){ + elseif($httpResponseCode == 404){ throw new MissingEndpoint(EXCEPTION_MISSING_ENDPOINT); } else{ throw new GenericHTTPError(EXCEPTION_GENERIC_HTTP_ERROR); } - $result->http_response_code = $httpResponeCode; + $result->http_response_code = $httpResponseCode; return $result; } }