function Mandrill::request in Mandrill 6
Work horse. Every API call use this function to actually make the request to Mandrill's servers.
@link https://mandrillapp.com/api/docs/
Parameters
string $method API method name:
array $args query arguments:
string $http GET or POST request type:
string $output API response format (json,php,xml,yaml). json and xml are decoded into arrays automatically.:
Return value
array|string|Mandrill_Exception
29 calls to Mandrill::request()
- Mandrill::messages_search in ./
mandrill.class.php - @link https://mandrillapp.com/api/docs/messages.html#method=search
- Mandrill::messages_send in ./
mandrill.class.php - @link https://mandrillapp.com/api/docs/messages.html#method=send
- Mandrill::messages_send_template in ./
mandrill.class.php - @link https://mandrillapp.com/api/docs/messages.html#method=send-template
- Mandrill::senders_domains in ./
mandrill.class.php - @link https://mandrillapp.com/api/docs/senders.html#method=domains
- Mandrill::senders_info in ./
mandrill.class.php - @link https://mandrillapp.com/api/docs/senders.html#method=info
File
- ./
mandrill.class.php, line 47
Class
Code
function request($method, $args = array(), $http = 'POST', $output = 'json') {
if (!isset($args['key'])) {
$args['key'] = $this->api;
}
$api_version = self::API_VERSION;
$dot_output = 'json' == $output ? '' : ".{$output}";
$url = self::END_POINT . "{$api_version}/{$method}{$dot_output}";
$params = json_encode($args);
switch ($http) {
case 'GET':
$url .= '?' . $params;
$response = drupal_http_request($url, array(), 'GET', NULL, 3, $this->timeout);
break;
case 'POST':
$response = drupal_http_request($url, array(), 'POST', $params, 3, $this->timeout);
break;
default:
throw new Mandrill_Exception('Unknown request type');
}
$response_code = $response->code;
$body = $response->data;
switch ($output) {
case 'json':
$body = json_decode($body, TRUE);
break;
case 'php':
$body = unserialize($body);
break;
}
if (200 == $response_code) {
return $body;
}
else {
$message = isset($body['message']) ? $body['message'] : '';
throw new Mandrill_Exception($message . ' - ' . $body, $response_code);
}
}