127 lines
4.4 KiB
PHP
127 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace Trinity\Bundle\AkamaiBundle\Service;
|
|
|
|
use Guzzle\Common\Exception\GuzzleException;
|
|
use Guzzle\Http\Exception\HttpException;
|
|
use Guzzle\Http\Exception\RequestException;
|
|
use GuzzleHttp\Client;
|
|
use GuzzleHttp\Command\Guzzle\Description;
|
|
use GuzzleHttp\Command\Guzzle\GuzzleClient;
|
|
use GuzzleHttp\Exception\ClientException;
|
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
|
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
|
|
|
/**
|
|
* Class AkamaiCcuApi
|
|
* @package Trinity\Bundle\AkamaiBundle\Service
|
|
* @require Guzzle
|
|
*/
|
|
class AkamaiCcuClient extends GuzzleClient
|
|
{
|
|
public function __construct(array $akamai_ws = [], array $config = [])
|
|
{
|
|
$resolver = new OptionsResolver();
|
|
$this->configureOptionResolver($resolver);
|
|
|
|
// validation des paramètres
|
|
$options = $resolver->resolve($akamai_ws);
|
|
|
|
// initialisation du client standard Guzzle
|
|
$client = new Client([
|
|
"defaults" => [
|
|
// headers attendus
|
|
"headers" => [
|
|
"Content-Type" => "application/json",
|
|
"Accept" => "application/json",
|
|
],
|
|
],
|
|
"base_url" => $options["base_url"]
|
|
]);
|
|
|
|
// définition des requètes supportées par notre service
|
|
$description = new Description([
|
|
"name" => 'Akamai',
|
|
"description" => "Content Control Utility",
|
|
"operations" => [
|
|
"getQueue" => [
|
|
"httpMethod" => "GET",
|
|
"uri" => "/ccu/v2/queues/{queueName}",
|
|
"responseModel" => "jsonResponse",
|
|
"parameters" => [
|
|
"queueName" => [
|
|
'type' => 'string',
|
|
'default' => 'default',
|
|
'location' => 'uri'
|
|
],
|
|
],
|
|
],
|
|
"addRequest" => [
|
|
"httpMethod" => "POST",
|
|
"uri" => "/ccu/v2/queues/{queueName}",
|
|
"responseModel" => "jsonResponse",
|
|
"parameters" => [
|
|
"queueName" => [
|
|
'type' => 'string',
|
|
'default' => 'default',
|
|
'location' => 'uri'
|
|
],
|
|
"objects" => [
|
|
'type' => 'array',
|
|
'required' => true,
|
|
'location' => 'postField'
|
|
],
|
|
"action" => [
|
|
'type' => 'string',
|
|
'default' => 'remove',
|
|
'location' => 'postField'
|
|
],
|
|
"type" => [
|
|
'type' => 'string',
|
|
'default' => 'url',
|
|
'location' => 'postField'
|
|
],
|
|
"domain" => [
|
|
'type' => 'string',
|
|
'default' => 'production',
|
|
'location' => 'postField'
|
|
]
|
|
]
|
|
],
|
|
"getStatus" => [
|
|
"httpMethod" => "GET",
|
|
"uri" => "/ccu/v2/purges/{purgeId}",
|
|
"responseModel" => "jsonResponse",
|
|
"parameters" => [
|
|
"purgeId" => [
|
|
'type' => 'string',
|
|
'required' => true,
|
|
'location' => 'uri'
|
|
]
|
|
],
|
|
],
|
|
],
|
|
// les models permettent de définir le traitement appliqué aux réponses de l'API
|
|
// on spécifie ici que l'on veut un objet php à partir du json contenu dans la réponse
|
|
"models" => [
|
|
"jsonResponse" => [
|
|
"type" => "object",
|
|
"additionalProperties" => [
|
|
"location" => "json"
|
|
]
|
|
]
|
|
]
|
|
]);
|
|
|
|
parent::__construct($client, $description, $config);
|
|
}
|
|
|
|
protected function configureOptionResolver(OptionsResolverInterface $resolver)
|
|
{
|
|
$resolver
|
|
->setRequired([
|
|
'base_url',
|
|
]);
|
|
}
|
|
}
|