You are here

function mandrill_get_api_object in Mandrill 7.2

Same name and namespace in other branches
  1. 8 mandrill.module \mandrill_get_api_object()
  2. 6 mandrill.module \mandrill_get_api_object()
  3. 7 mandrill.module \mandrill_get_api_object()

Return Mandrill API object for communication with the mandrill server.

Parameters

bool $reset: Pass in TRUE to reset the statically cached object.

Return value

Mandrill|bool Mandrill Object upon success FALSE if variable_get('mandrill_api_key') is unset

15 calls to mandrill_get_api_object()
mandrill_activity_get_activity in modules/mandrill_activity/mandrill_activity.module
Return all activity on all lists for a given email address.
mandrill_add_inbound_domain in ./mandrill.module
Create a new inbound domain.
mandrill_add_inbound_route in ./mandrill.module
Create a new inbound route for a domain.
mandrill_add_webhook in ./mandrill.module
Create a new webhook.
mandrill_delete_inbound_domain in ./mandrill.module
Delete an inbound domain.

... See full list

File

./mandrill.module, line 287
Enables Drupal to send email directly through Mandrill.

Code

function mandrill_get_api_object($reset = FALSE) {
  $api =& drupal_static(__FUNCTION__, NULL);
  if ($api === NULL || $reset === TRUE) {
    $library = libraries_load('mandrill');
    if (!$library['installed']) {
      $msg = t('Failed to load Mandrill PHP library. Please refer to the installation requirements.');
      watchdog('mandrill', $msg, NULL, WATCHDOG_ERROR);
      drupal_set_message($msg, 'error');
      return NULL;
    }
    $api_key = variable_get('mandrill_api_key', '');
    $api_timeout = variable_get('mandrill_api_timeout', 60);
    if (empty($api_key)) {
      $msg = t('Failed to load Mandrill API Key. Please check your Mandrill settings.');
      drupal_set_message($msg, 'error');
      return FALSE;
    }

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