You are here

function mailchimp_get_api_object in Mailchimp 7.2

Same name and namespace in other branches
  1. 8 mailchimp.module \mailchimp_get_api_object()
  2. 7.5 mailchimp.module \mailchimp_get_api_object()
  3. 7.3 mailchimp.module \mailchimp_get_api_object()
  4. 7.4 mailchimp.module \mailchimp_get_api_object()
  5. 2.x mailchimp.module \mailchimp_get_api_object()

Get a Mailchimp API object for communication with the mailchimp server.

Return value

MCAPI|NULL A valid MCAPI implementation or NULL if no one found.

20 calls to mailchimp_get_api_object()
mailchimp_activity_get_member_activity in modules/mailchimp_activity/mailchimp_activity.module
Get the MailChimp memberactivity for a given email address and list. Results are cached in the cache_mailchimp_user bin which is cleared by the MC web hooks system when needed.
mailchimp_campaign_delete_campaign in modules/mailchimp_campaign/mailchimp_campaign.module
Delete a MailChimp campaign and the local entity.
mailchimp_campaign_get_campaigns in modules/mailchimp_campaign/mailchimp_campaign.module
Return MailChimp campaigns.
mailchimp_campaign_get_templates in modules/mailchimp_campaign/mailchimp_campaign.module
Return all available user templates.
mailchimp_campaign_save_campaign in modules/mailchimp_campaign/mailchimp_campaign.module
Save a campaign in MailChimp and as a Drupal entity.

... See full list

File

./mailchimp.module, line 233
Mailchimp module.

Code

function mailchimp_get_api_object() {
  $library = libraries_load('mailchimp');
  if (!$library['installed']) {
    $msg = 'Failed to load MailChimp PHP library. Please refer to the installation requirements.';
    watchdog('mailchimp', $msg, array(), WATCHDOG_ERROR);
    drupal_set_message(t($msg), 'error');
    return NULL;
  }
  $api_key = variable_get('mailchimp_api_key', '');

  // We allow the class name to be overridden, following the example of core's
  // mailsystem, in order to use alternate MailChimp classes. The bundled tests
  // use this approach to extend the MailChimp class with a test server.
  $classname = variable_get('mailchimp_api_classname', 'MailChimp');
  $q = new $classname($api_key);

  // Set the timeout to something that won't take down the Drupal site:
  $q
    ->setTimeout(60);

  // Specify if a secure connection should be used with the API:
  $q
    ->useSecure(variable_get('mailchimp_use_secure', TRUE));
  if ($q->errorCode) {
    watchdog('mailchimp', 'MCAPI Error: %errmsg', array(
      '%errmsg' => $q->errorMessage,
    ), WATCHDOG_ERROR);
    return NULL;
  }
  return $q;
}