You are here

function AkamaiCacheControlClient::clear_url in Akamai 6.2

Same name and namespace in other branches
  1. 8 akamai.class.inc \AkamaiCacheControlClient::clear_url()
  2. 8.2 akamai.class.inc \AkamaiCacheControlClient::clear_url()
  3. 7.3 akamai.class.inc \AkamaiCacheControlClient::clear_url()
  4. 7 akamai.class.inc \AkamaiCacheControlClient::clear_url()
  5. 7.2 akamai.class.inc \AkamaiCacheControlClient::clear_url()

Clears the provided URLs from the Akamai Content Cache.

Parameters

array $paths: A path (or array of paths) to clear from Akamai

Return value

array An array with 2 keys: success: TRUE or FALSE indicating cache clearing success message: Blank if successful, the error message if not successful.

Overrides AkamaiCacheControl::clear_url

File

./akamai.class.inc, line 70
akamai.class.inc

Class

AkamaiCacheControlClient
Default implementation of the AkamaiCacheControl interface

Code

function clear_url($paths) {

  // Grab paramaters.
  extract($this->parameters);

  // Make sure $paths is an array.
  if (!is_array($paths)) {
    $url = array(
      $paths,
    );
  }

  // Prepend base path to paths to make URIs.
  $uris = array();
  foreach ($paths as $path) {
    $path = rtrim(preg_match("/^\\//", $path) ? $path : "/{$path}");
    array_push($uris, $basepath . $path);
  }
  $opt = array(
    "action={$action}",
    "domain={$domain}",
    "type={$type}",
  );
  if (!empty($email) && $email != AKAMAI_EMAIL_DISABLE) {
    $opt[] = "email-notification={$email}";
  }
  $data = array(
    "type" => "arl",
    "action" => "{$action}",
    "domain" => "{$domain}",
    "objects" => $uris,
  );
  $data_string = json_encode($data);
  $data_string = str_replace("\\/", '/', $data_string);

  // URL needs to be in the format of scheme://user:pass@url.
  $url_parsed = parse_url($restapi);
  $url = $url_parsed['scheme'] . '://' . $name . ':' . $pwd . '@' . $url_parsed['host'] . $url_parsed['path'];
  $headers = array(
    'Content-Type' => 'application/json',
    'Content-Length' => strlen($data_string),
  );
  $response = drupal_http_request($url, $headers, 'POST', $data_string, 3, 5);
  $is_success = $response->code < 300;
  if (!$is_success) {
    throw new \Exception($response->data);
  }
  $response_data = json_decode($response->data);
  watchdog('Akamai', "Akamai RestAPI %action for %uris: Response: %response", array(
    '%uris' => implode(' ', $uris),
    '%action' => $action,
    '%response' => $response_data->detail,
  ), WATCHDOG_NOTICE);
  return $response;
}