You are here

public static function ALProfilesAPI::getInstance in Acquia Lift Connector 7.2

Same name and namespace in other branches
  1. 7 acquia_lift_profiles/includes/acquia_lift_profiles.classes.inc \ALProfilesAPI::getInstance()

Singleton factory method.

Parameters

$account_name: The name of the Acquia Lift Profiles account.

$api_url: The URL to use for API calls.

$access_key: The access key to use for authorization.

$secret_key: The secret key to use for authorization.

Return value

ALProfilesAPI

6 calls to ALProfilesAPI::getInstance()
acquia_lift_profiles_delete_action in acquia_lift_profiles/acquia_lift_profiles.module
Calls the Acquia Lift Profiles API to delete an event corresponding to a Visitor Actions action
acquia_lift_profiles_put_action in acquia_lift_profiles/acquia_lift_profiles.module
Calls the Acquia Lift Profiles API to create/update an event corresponding to a Visitor Actions action.
ALProfilesAPITest::getALProfilesAPI in acquia_lift_profiles/tests/acquia_lift_profiles_unit.test
Returns a ALProfilesAPI instance that can be used to test methods.
ALProfilesAPITest::testGetInstance in acquia_lift_profiles/tests/acquia_lift_profiles_unit.test
Tests getting ALProfilesAPI instance with invalid and valid credentials.
ALProfilesContext::create in acquia_lift_profiles/plugins/visitor_context/ALProfilesContext.inc
Implements PersonalizeContextInterface::create().

... See full list

File

acquia_lift_profiles/includes/acquia_lift_profiles.classes.inc, line 82
Provides an agent type for Acquia Lift Profiles

Class

ALProfilesAPI
@file Provides an agent type for Acquia Lift Profiles

Code

public static function getInstance($account_name = '', $customer_site = '', $api_url = '', $access_key = '', $secret_key = '') {
  if (empty(self::$instance)) {
    if (drupal_valid_test_ua()) {
      self::setTestInstance();
      return self::$instance;
    }

    // If no account name or api url has been passed in, fallback to getting them
    // from the variables.
    if (empty($account_name)) {
      $account_name = variable_get('acquia_lift_profiles_account_name', '');
    }
    if (empty($customer_site)) {
      $customer_site = variable_get('acquia_lift_profiles_site_name', '');
    }
    if (empty($api_url)) {
      $api_url = variable_get('acquia_lift_profiles_api_url', '');
    }
    if (empty($access_key)) {
      $access_key = variable_get('acquia_lift_profiles_access_key', '');
    }
    if (empty($secret_key)) {
      $secret_key = variable_get('acquia_lift_profiles_secret_key', '');
    }

    // If either account name or API URL is still missing, bail.
    if (empty($api_url) || empty($account_name) || empty($access_key) || empty($secret_key)) {
      throw new ALProfilesCredsException('Missing acquia_lift_profiles account information.');
    }
    if (!valid_url($api_url)) {
      throw new ALProfilesCredsException('API URL is not a valid URL.');
    }
    $needs_scheme = strpos($api_url, '://') === FALSE;
    if ($needs_scheme) {
      global $is_https;

      // Use the same scheme for Acquia Lift Profiles as we are using here.
      $url_scheme = $is_https ? 'https://' : 'http://';
      $api_url = $url_scheme . $api_url;
    }
    if (substr($api_url, -1) === '/') {
      $api_url = substr($api_url, 0, -1);
    }
    self::$instance = new self($account_name, $customer_site, $api_url, $access_key, $secret_key);
  }
  return self::$instance;
}