You are here

abstract class BaseCcuClient in Akamai 7.3

Hierarchy

Expanded class hierarchy of BaseCcuClient

File

src/BaseCcuClient.php, line 15
Constains the Drupal\akamai\BaseCcuClient class.

Namespace

Drupal\akamai
View source
abstract class BaseCcuClient implements CcuClientInterface {

  /**
   * The string used when invalidating objects.
   */
  const OPERATION_INVALIDATE = 'invalidate';

  /**
   * The string used when removing objects.
   */
  const OPERATION_DELETE = 'remove';

  /**
   * An instance of an OPEN EdgeGrid Client.
   *
   * @var \Akamai\Open\EdgeGrid\Client
   */
  protected $client;

  /**
   * The network to use when issuing purge requests.
   *
   * @var string
   */
  protected $network;

  /**
   * The operation to use when issuing purge requests.
   *
   * @var string
   */
  protected $operation;

  /**
   * Implements CcuClientInterface::__construct().
   */
  public function __construct(EdgeGridClient $client) {
    $this->client = $client;
    $this->network = static::NETWORK_PRODUCTION;
    $this->operation = static::OPERATION_INVALIDATE;
  }

  /**
   * Implements CcuClientInterface::setNetwork().
   */
  public function setNetwork($network) {
    if ($network != static::NETWORK_PRODUCTION && $network != static::NETWORK_STAGING) {
      throw new InvalidArgumentException('Invalid network supplied.');
    }
    $this->network = $network;
    return $this;
  }

  /**
   * Implements CcuClientInterface::setOperation().
   */
  public function setOperation($operation) {
    if ($operation != static::OPERATION_INVALIDATE && $operation != static::OPERATION_DELETE) {
      throw new InvalidArgumentException('Invalid operation supplied.');
    }
    $this->operation = $operation;
    return $this;
  }

  /**
   * Implements CcuClientInterface::checkProgress().
   */
  public function checkProgress($progress_uri) {
    $response = $this->client
      ->get($progress_uri);
    return json_decode($response
      ->getBody());
  }

  /**
   * Implements CcuClientInterface::postPurgeRequest().
   */
  public function postPurgeRequest($hostname, array $paths) {
    if (empty($hostname)) {
      throw new InvalidArgumentException("Expected hostname to be a non-empty string.");
    }
    $uri = $this
      ->getPurgeApiEndpoint();
    $response = $this->client
      ->post($uri, [
      'body' => $this
        ->getPurgeBody($hostname, $paths),
      'headers' => [
        'Content-Type' => 'application/json',
      ],
    ]);
    return json_decode($response
      ->getBody());
  }

  /**
   * Implements CcuClientInterface::bodyIsBelowLimit().
   */
  public function bodyIsBelowLimit($hostname, array $paths) {
    $body = $this
      ->getPurgeBody($hostname, $paths);
    $bytes = mb_strlen($body, '8bit');
    return $bytes < static::MAX_BODY_SIZE;
  }

}

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
CcuClientInterface::getPurgeApiEndpoint public function Generates the URL to use when posting a purge request. 2
CcuClientInterface::getPurgeBody public function Generates a JSON-encoded body for a purge request. 2
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.