You are here

class Ccu2Client in Akamai 7.3

Hierarchy

Expanded class hierarchy of Ccu2Client

File

src/Ccu2Client.php, line 15
Contains the Drupal\akamai\Ccu2Client class.

Namespace

Drupal\akamai
View source
class Ccu2Client extends BaseCcuClient implements CcuClientInterface {

  /**
   * The version of the CCU API.
   *
   * @var string
   */
  protected $version = 'v2';

  /**
   * The queue to use when issuing a purge request.
   *
   * @var string
   */
  protected $queuename = 'default';

  /**
   * Sets the queue name.
   *
   * @param string $queuename
   *   Valid values are 'default' and 'emergency'.
   */
  public function setQueueName($queuename) {
    if ($queuename != 'default' && $queuename != 'emergency') {
      throw new InvalidArgumentException('Invalid queue name supplied.');
    }
    $this->queuename = $queuename;
  }

  /**
   * Gets the number of items in the queue.
   *
   * @return int
   *   The number of pending purge requests in the queue.
   */
  public function getQueueLength() {
    $uri = "/ccu/{$this->version}/queues/{$this->queuename}";
    $response = $this->client
      ->get($uri);
    return json_decode($response
      ->getBody())->queueLength;
  }

  /**
   * Implements CcuClientInterface::getPurgeApiEndpoint().
   */
  public function getPurgeApiEndpoint() {
    return "/ccu/{$this->version}/queues/{$this->queuename}";
  }

  /**
   * Implements CcuClientInterface::getPurgeBody().
   */
  public function getPurgeBody($hostname, array $paths) {

    // Strip whitespace from paths and ensure each path begins with a '/'.
    // CCU API v2 requires absolute URLs, so prepend hostname and schemes.
    foreach ($paths as $key => $path) {
      $path = rtrim(preg_match("/^\\//", $path) ? $path : "/{$path}");
      $paths[$key] = 'http://' . $hostname . $path;
      $paths[] = 'https://' . $hostname . $path;
    }
    $purge_body = array(
      'action' => $this->operation,
      'objects' => array_unique($paths),
      'domain' => $this->network,
    );
    return json_encode($purge_body);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BaseCcuClient::$client protected property An instance of an OPEN EdgeGrid Client.
BaseCcuClient::$network protected property The network to use when issuing purge requests.
BaseCcuClient::$operation protected property The operation to use when issuing purge requests.
BaseCcuClient::bodyIsBelowLimit public function Implements CcuClientInterface::bodyIsBelowLimit(). Overrides CcuClientInterface::bodyIsBelowLimit
BaseCcuClient::checkProgress public function Implements CcuClientInterface::checkProgress(). Overrides CcuClientInterface::checkProgress
BaseCcuClient::OPERATION_DELETE constant The string used when removing objects. 1
BaseCcuClient::OPERATION_INVALIDATE constant The string used when invalidating objects.
BaseCcuClient::postPurgeRequest public function Implements CcuClientInterface::postPurgeRequest(). Overrides CcuClientInterface::postPurgeRequest
BaseCcuClient::setNetwork public function Implements CcuClientInterface::setNetwork(). Overrides CcuClientInterface::setNetwork
BaseCcuClient::setOperation public function Implements CcuClientInterface::setOperation(). Overrides CcuClientInterface::setOperation
BaseCcuClient::__construct public function Implements CcuClientInterface::__construct(). Overrides CcuClientInterface::__construct
Ccu2Client::$queuename protected property The queue to use when issuing a purge request.
Ccu2Client::$version protected property The version of the CCU API.
Ccu2Client::getPurgeApiEndpoint public function Implements CcuClientInterface::getPurgeApiEndpoint(). Overrides CcuClientInterface::getPurgeApiEndpoint
Ccu2Client::getPurgeBody public function Implements CcuClientInterface::getPurgeBody(). Overrides CcuClientInterface::getPurgeBody
Ccu2Client::getQueueLength public function Gets the number of items in the queue.
Ccu2Client::setQueueName public function Sets the queue name.
CcuClientInterface::MAX_BODY_SIZE constant The maximum size, in bytes, of a request body allowed by the API.
CcuClientInterface::NETWORK_PRODUCTION constant String constant for the production network.
CcuClientInterface::NETWORK_STAGING constant String constant for the staging network.