ReadMe Adjustments and fixed an issue with result handler.

This commit is contained in:
Travis Swientek 2013-08-20 11:10:57 -07:00
parent f4b7ff61e7
commit d88fb82c1d
3 changed files with 13 additions and 10 deletions

View File

@ -1,6 +1,6 @@
Mailgun-PHP Mailgun-PHP
=========== ===========
[![Build Status](https://travis-ci.org/travelton/Mailgun-PHP.png?branch=master)](https://travis-ci.org/travelton/Mailgun-PHP) [![Build Status](https://travis-ci.org/mailgun/mailgun-php.png)](https://travis-ci.org/mailgun/mailgun-php)
This is the Mailgun PHP SDK. This SDK contains methods for easily interacting This is the Mailgun PHP SDK. This SDK contains methods for easily interacting
with the Mailgun API. with the Mailgun API.
@ -82,6 +82,12 @@ $result = $mg->get("$domain/log", array('limit' => 25,
$httpResponseCode = $result->http_response_code; $httpResponseCode = $result->http_response_code;
$httpResponseBody = $result->http_response_body; $httpResponseBody = $result->http_response_body;
# Iterate through the results and echo the message IDs.
$logItems = $result->http_response_body->items;
for($logItems as $logItem){
echo $logItem->message_id . "\n";
}
``` ```
Example Contents: Example Contents:

View File

@ -78,12 +78,9 @@ class RestClient{
public function responseHandler($responseObj){ public function responseHandler($responseObj){
$httpResponeCode = $responseObj->getStatusCode(); $httpResponeCode = $responseObj->getStatusCode();
if($httpResponeCode === 200){ if($httpResponeCode === 200){
$jsonResponseData = $responseObj->json(); $jsonResponseData = json_decode($responseObj->getBody(), false);
$result = new \stdClass(); $result = new \stdClass();
$result->http_response_body = new \stdClass(); $result->http_response_body = $jsonResponseData;
foreach ($jsonResponseData as $key => $value){
$result->http_response_body->$key = $value;
}
} }
elseif($httpResponeCode == 400){ elseif($httpResponeCode == 400){
throw new MissingRequiredMIMEParameters(EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS); throw new MissingRequiredMIMEParameters(EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS);

View File

@ -104,16 +104,16 @@ domain.
$batchMsg = $mg->BatchMessage($domain); $batchMsg = $mg->BatchMessage($domain);
# Define the from address. # Define the from address.
$batchMsg->setFromAddress("me@samples.mailgun.org", array("first"=>"PHP", "last" => "SDK")); $batchMsg->setFromAddress("me@example.com", array("first"=>"PHP", "last" => "SDK"));
# Define the subject. # Define the subject.
$batchMsg->setSubject("A Batch Message from the PHP SDK!"); $batchMsg->setSubject("A Batch Message from the PHP SDK!");
# Define the body of the message. # Define the body of the message.
$batchMsg->setTextBody("This is the text body of the message!"); $batchMsg->setTextBody("This is the text body of the message!");
# Next, let's add a few recipients to the batch job. # Next, let's add a few recipients to the batch job.
$batchMsg->addToRecipient("john.doe@samples.mailgun.org", array("first" => "John", "last" => "Doe")); $batchMsg->addToRecipient("john.doe@example.com", array("first" => "John", "last" => "Doe"));
$batchMsg->addToRecipient("sally.doe@samples.mailgun.org", array("first" => "Sally", "last" => "Doe")); $batchMsg->addToRecipient("sally.doe@example.com", array("first" => "Sally", "last" => "Doe"));
$batchMsg->addToRecipient("mike.jones@samples.mailgun.org", array("first" => "Mike", "last" => "Jones")); $batchMsg->addToRecipient("mike.jones@example.com", array("first" => "Mike", "last" => "Jones"));
... ...
// After 1,000 recipeints, Batch Message will automatically post your message to // After 1,000 recipeints, Batch Message will automatically post your message to
the messages endpoint. the messages endpoint.