You are here

function akamai_get_client in Akamai 7.3

Gets an instance of a CCU client class.

Parameters

int $version: Specifies which version of the CCU API to use. Either 2 or 3.

4 calls to akamai_get_client()
akamai_clear_url in ./akamai.module
Deprecated. Use akamai_purge_path() instead.
akamai_cron_process_queue in ./akamai.cron.inc
Processes queued purge requests and submits them to the CCU API in batches.
akamai_submit_purge_request in ./akamai.module
Submits a purge request to the CCU API.
_akamai_update_status in ./akamai.cron.inc
Checks the status of a purge request and updates its record.

File

./akamai.module, line 604
Integration with Akamai CDN CCU API.

Code

function akamai_get_client($version = NULL) {
  if (variable_get('akamai_credential_storage', 'database') == 'database') {
    $edgegrid_client = new \Akamai\Open\EdgeGrid\Client([
      'base_uri' => variable_get('akamai_base_uri', ''),
      'timeout' => variable_get('akamai_timeout', \Akamai\Open\EdgeGrid\Client::DEFAULT_REQUEST_TIMEOUT),
    ]);
    $client_token = variable_get('akamai_client_token', '');
    $client_secret = variable_get('akamai_client_secret', '');
    $access_token = variable_get('akamai_access_token', '');
    $edgegrid_client
      ->setAuth($client_token, $client_secret, $access_token);
  }
  else {
    $section = variable_get('akamai_edgerc_section', 'default');
    $path = variable_get('akamai_edgerc_path', NULL);
    $edgegrid_client = \Akamai\Open\EdgeGrid\Client::createFromEdgeRcFile($section, $path);
  }
  $version = empty($version) ? variable_get('akamai_ccu_version', 3) : $version;
  if ($version == 2) {
    $ccu_client = new \Drupal\akamai\Ccu2Client($edgegrid_client);
  }
  else {
    $ccu_client = new \Drupal\akamai\Ccu3Client($edgegrid_client);
  }
  $ccu_client
    ->setNetwork(variable_get('akamai_network', 'production'));
  if (variable_get('akamai_action', 'invalidate') == 'remove') {
    $ccu_client
      ->setOperation($ccu_client::OPERATION_DELETE);
  }
  return $ccu_client;
}