function mailchimp_get_api_object in Mailchimp 7.3
Same name and namespace in other branches
- 8 mailchimp.module \mailchimp_get_api_object()
- 7.5 mailchimp.module \mailchimp_get_api_object()
- 7.2 mailchimp.module \mailchimp_get_api_object()
- 7.4 mailchimp.module \mailchimp_get_api_object()
- 2.x mailchimp.module \mailchimp_get_api_object()
Get a MailChimp API object for communication with the MailChimp server.
Return value
DrupalMailchimp The default return value is an instance of DrupalMailchimp, although that can be overridden.
31 calls to mailchimp_get_api_object()
- MailchimpCampaignsTestCase::setUp in modules/
mailchimp_campaign/ tests/ mailchimp_campaigns.test - Pre-test setup function.
- MailchimpListsTestCase::setUp in modules/
mailchimp_lists/ tests/ mailchimp_lists.test - Pre-test setup function.
- mailchimp_activity_get_member_activity in modules/
mailchimp_activity/ mailchimp_activity.module - Get the MailChimp member activity for a given email address and list.
- mailchimp_apikey_ready_access in ./
mailchimp.module - Access callback for mailchimp submodule menu items.
- mailchimp_batch_update_members in ./
mailchimp.module - Wrapper around MCAPI->lists->batch-subscribe.
File
- ./
mailchimp.module, line 108 - Mailchimp module.
Code
function mailchimp_get_api_object() {
$mailchimp =& drupal_static(__FUNCTION__);
if (isset($mailchimp)) {
return $mailchimp;
}
// 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', 'DrupalMailchimp');
$library = libraries_load('mailchimp');
if (!$library['installed'] && $classname != 'MailChimpTest') {
$msg = t('Failed to load MailChimp PHP library. Please refer to the installation requirements.');
watchdog('mailchimp', $msg, array(), WATCHDOG_ERROR);
drupal_set_message($msg, 'error');
return NULL;
}
$api_key = variable_get('mailchimp_api_key', '');
if (!strlen($api_key)) {
watchdog('mailchimp', t('MailChimp Error: API Key cannot be blank.'), array(), WATCHDOG_ERROR);
return NULL;
}
// Set the timeout to something that won't take down the Drupal site:
$options = array(
'timeout' => 60,
);
$mailchimp = new $classname($api_key, $options);
return $mailchimp;
}