mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-25 14:26:04 +03:00
Updated response section (#240)
* Updated response section * Update README.md * Update README.md
This commit is contained in:
parent
4fcf878d39
commit
479df95971
62
README.md
62
README.md
@ -81,62 +81,36 @@ $mg->get("$domain/log", array('limit' => 25,
|
|||||||
|
|
||||||
### Response
|
### Response
|
||||||
|
|
||||||
The results, provided by the endpoint, are returned as an object, which you
|
The results of a API call is, by default, a domain object. This will make it easy
|
||||||
can traverse like an array.
|
to understand the response without reading the documentation. One can just read the
|
||||||
|
doc blocks on the response classes. This provide an excellet IDE integration.
|
||||||
Example:
|
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$mg = new Mailgun("key-example");
|
$mg = new Mailgun("key-example");
|
||||||
$domain = "example.com";
|
$dns = $mg->domains()->show('example.com')->getInboundDNSRecords();
|
||||||
|
|
||||||
$result = $mg->get("$domain/log", array('limit' => 25,
|
foreach ($dns as $record) {
|
||||||
'skip' => 0));
|
echo $record->getType();
|
||||||
|
|
||||||
$httpResponseCode = $result->http_response_code;
|
|
||||||
$httpResponseBody = $result->http_response_body;
|
|
||||||
|
|
||||||
# Iterate through the results and echo the message IDs.
|
|
||||||
$logItems = $result->http_response_body->items;
|
|
||||||
foreach($logItems as $logItem){
|
|
||||||
echo $logItem->message_id . "\n";
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Example Contents:
|
If you rather be working with array then object you can inject the `ArrayDeserializer`
|
||||||
**$httpResponseCode** will contain an integer. You can find how we use HTTP response
|
to the Mailgun class.
|
||||||
codes in our documentation:
|
|
||||||
http://documentation.mailgun.com/api-intro.html?highlight=401#errors
|
|
||||||
|
|
||||||
**$httpResponseBody** will contain an object of the API response. In the above
|
```php
|
||||||
example, a var_dump($result) would contain the following:
|
use Mailgun\Deserializer\ArrayDeserializer;
|
||||||
|
|
||||||
```
|
$mg = new Mailgun("key-example", null, null, new ArrayDeserializer());
|
||||||
object(stdClass)#26 (2) {
|
$data = $mg->domains()->show('example.com');
|
||||||
["http_response_body"]=>
|
|
||||||
object(stdClass)#26 (2) {
|
foreach ($data['receiving_dns_records'] as $record) {
|
||||||
["total_count"]=>
|
echo isset($record['record_type']) ? $record['record_type'] : null;
|
||||||
int(12)
|
|
||||||
["items"]=>
|
|
||||||
array(1) {
|
|
||||||
[0]=>
|
|
||||||
object(stdClass)#31 (5) {
|
|
||||||
["hap"]=>
|
|
||||||
string(9) "delivered"
|
|
||||||
["created_at"]=>
|
|
||||||
string(29) "Tue, 20 Aug 2013 20:24:34 GMT"
|
|
||||||
["message"]=>
|
|
||||||
string(66) "Delivered: me@samples.mailgun.org → travis@mailgunhq.com 'Hello'"
|
|
||||||
["type"]=>
|
|
||||||
string(4) "info"
|
|
||||||
["message_id"]=>
|
|
||||||
string(46) "20130820202406.24739.21973@samples.mailgun.org"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You could also use the `PSR7Deserializer` to get a PSR7 Response returned from
|
||||||
|
the API calls.
|
||||||
|
|
||||||
### Debugging
|
### Debugging
|
||||||
|
|
||||||
Debugging the PHP SDK can be really helpful when things aren't working quite right.
|
Debugging the PHP SDK can be really helpful when things aren't working quite right.
|
||||||
|
Loading…
Reference in New Issue
Block a user