Skip to content

Commit

Permalink
Merge pull request #6 from betacie/master
Browse files Browse the repository at this point in the history
Fix Bugs in BatchMessage
  • Loading branch information
travelton committed Sep 5, 2013
2 parents 9438694 + c445c4d commit e68f0ce
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ rackspace_logo.jpg
mailgun_icon.png
build
composer.lock
nbproject/*
15 changes: 6 additions & 9 deletions src/Mailgun/Connection/RestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,25 @@ public function put($endpointUrl, $putData){
}

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 == 401){
throw new GenericHTTPError(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;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Mailgun/Messages/BatchMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public function addToRecipient($address, $variables = null){
$this->addRecipient("to", $address, $variables);
$attributes["id"] = $this->toRecipientCount;
$this->batchRecipientAttributes["$address"] = $variables;
$this->toRecipientCount++;
}

public function sendMessage($message = array(), $files = array()){
Expand All @@ -59,7 +58,7 @@ public function sendMessage($message = array(), $files = array()){
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;
Expand Down
9 changes: 9 additions & 0 deletions tests/Mailgun/Tests/Messages/BatchMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ public function testResetOnEndBatchMessage(){
$messageObj= $message->getMessage();
$this->assertTrue(true, empty($messageObj));
}
public function testToRecipientCount() {
$message = $this->client->BatchMessage($this->sampleDomain);
$message->addToRecipient("[email protected]", array("first" => "Test", "last" => "User"));

$reflectionClass = new \ReflectionClass(get_class($message));
$property = $reflectionClass->getProperty('toRecipientCount');
$property->setAccessible(true);
$this->assertEquals(1, $property->getValue($message));
}
}
?>

Expand Down

0 comments on commit e68f0ce

Please sign in to comment.