You are here

public function DrupalMailchimp::call in Mailchimp 7.3

Override MCAPI::callServer() to leverage Drupal's core HTTP handling.

File

includes/mailchimp.inc, line 68
Wrapper class around the Mailchimp API.

Class

DrupalMailchimp
Class DrupalMailchimp

Code

public function call($url, $params) {
  $params['apikey'] = $this->apikey;
  $params = drupal_json_encode($params);
  $response = drupal_http_request($this->root . $url . '.json', array(
    'method' => 'POST',
    'data' => $params,
    'headers' => array(
      'Content-type' => 'application/json',
      'Accept-Language' => language_default()->language,
      'User-Agent' => $this->userAgent,
    ),
    'timeout' => $this->timeout,
  ));
  $result = drupal_json_decode($response->data);
  if (!empty($response->error)) {
    throw new Mailchimp_HttpError(t("MailChimp API call to %url failed: @msg: @error", array(
      '%url' => $url,
      '@msg' => $response->error,
      '@error' => $result['error'],
    )));
  }
  if (floor($response->code / 100) >= 4) {
    throw $this
      ->castError($result);
  }
  return $result;
}