mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-29 16:36:07 +03:00
commit
e68f0ce74c
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@ rackspace_logo.jpg
|
|||||||
mailgun_icon.png
|
mailgun_icon.png
|
||||||
build
|
build
|
||||||
composer.lock
|
composer.lock
|
||||||
|
nbproject/*
|
||||||
|
@ -76,28 +76,25 @@ class RestClient{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function responseHandler($responseObj){
|
public function responseHandler($responseObj){
|
||||||
$httpResponeCode = $responseObj->getStatusCode();
|
$httpResponseCode = $responseObj->getStatusCode();
|
||||||
if($httpResponeCode === 200){
|
if($httpResponseCode === 200){
|
||||||
$jsonResponseData = json_decode($responseObj->getBody(), false);
|
$jsonResponseData = json_decode($responseObj->getBody(), false);
|
||||||
$result = new \stdClass();
|
$result = new \stdClass();
|
||||||
$result->http_response_body = $jsonResponseData;
|
$result->http_response_body = $jsonResponseData;
|
||||||
}
|
}
|
||||||
elseif($httpResponeCode == 400){
|
elseif($httpResponseCode == 400){
|
||||||
throw new MissingRequiredParameters(EXCEPTION_MISSING_REQUIRED_PARAMETERS);
|
throw new MissingRequiredParameters(EXCEPTION_MISSING_REQUIRED_PARAMETERS);
|
||||||
}
|
}
|
||||||
elseif($httpResponeCode == 401){
|
elseif($httpResponseCode == 401){
|
||||||
throw new InvalidCredentials(EXCEPTION_INVALID_CREDENTIALS);
|
throw new InvalidCredentials(EXCEPTION_INVALID_CREDENTIALS);
|
||||||
}
|
}
|
||||||
elseif($httpResponeCode == 401){
|
elseif($httpResponseCode == 404){
|
||||||
throw new GenericHTTPError(EXCEPTION_INVALID_CREDENTIALS);
|
|
||||||
}
|
|
||||||
elseif($httpResponeCode == 404){
|
|
||||||
throw new MissingEndpoint(EXCEPTION_MISSING_ENDPOINT);
|
throw new MissingEndpoint(EXCEPTION_MISSING_ENDPOINT);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
throw new GenericHTTPError(EXCEPTION_GENERIC_HTTP_ERROR);
|
throw new GenericHTTPError(EXCEPTION_GENERIC_HTTP_ERROR);
|
||||||
}
|
}
|
||||||
$result->http_response_code = $httpResponeCode;
|
$result->http_response_code = $httpResponseCode;
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,6 @@ class BatchMessage extends MessageBuilder{
|
|||||||
$this->addRecipient("to", $address, $variables);
|
$this->addRecipient("to", $address, $variables);
|
||||||
$attributes["id"] = $this->toRecipientCount;
|
$attributes["id"] = $this->toRecipientCount;
|
||||||
$this->batchRecipientAttributes["$address"] = $variables;
|
$this->batchRecipientAttributes["$address"] = $variables;
|
||||||
$this->toRecipientCount++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sendMessage($message = array(), $files = array()){
|
public function sendMessage($message = array(), $files = array()){
|
||||||
@ -59,7 +58,7 @@ class BatchMessage extends MessageBuilder{
|
|||||||
throw new MissingRequiredMIMEParameters(EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS);
|
throw new MissingRequiredMIMEParameters(EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$this->message["recipient-variables"] = json_encode($this->batchRecipientAttributes);
|
$message["recipient-variables"] = json_encode($this->batchRecipientAttributes);
|
||||||
$response = $this->restClient->post($this->endpointUrl, $message, $files);
|
$response = $this->restClient->post($this->endpointUrl, $message, $files);
|
||||||
$this->batchRecipientAttributes = array();
|
$this->batchRecipientAttributes = array();
|
||||||
$this->toRecipientCount = 0;
|
$this->toRecipientCount = 0;
|
||||||
|
@ -50,6 +50,15 @@ class BatchMessageTest extends \Mailgun\Tests\MailgunTestCase{
|
|||||||
$messageObj= $message->getMessage();
|
$messageObj= $message->getMessage();
|
||||||
$this->assertTrue(true, empty($messageObj));
|
$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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user