You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.1 KiB
PHTML
79 lines
2.1 KiB
PHTML
6 years ago
|
<?php
|
||
|
/**
|
||
|
* Copyright 2016 Akamai Technologies, Inc. All Rights Reserved.
|
||
|
*
|
||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
* you may not use this file except in compliance with the License.
|
||
|
*
|
||
|
* You may obtain a copy of the License at
|
||
|
*
|
||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||
|
*
|
||
|
* Unless required by applicable law or agreed to in writing, software
|
||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
* See the License for the specific language governing permissions and
|
||
|
* limitations under the License.
|
||
|
* Sample client for CCU
|
||
|
* Note that in order for this to work you need to provision credentials
|
||
|
* specifically for CCU - you cannot extend existing credentials to add
|
||
|
* CCU as it's managed under "CCU" in the API credential system.
|
||
|
*
|
||
|
* Configure->Organization->Manage APIs
|
||
|
* Select "CCU APIs"
|
||
|
* Create client collections/clients
|
||
|
* Add authorization
|
||
|
*
|
||
|
* Put the credentials in ~/.edgerc as demonstrated by api-kickstart/sample_edgerc
|
||
|
*/
|
||
|
namespace Akamai\Open\Example;
|
||
|
|
||
|
require_once __DIR__ . '/cli/init.php';
|
||
|
|
||
|
class CcuClient
|
||
|
{
|
||
|
/**
|
||
|
* @var \Akamai\Open\EdgeGrid\Client
|
||
|
*/
|
||
|
protected $client;
|
||
|
|
||
|
public function __construct()
|
||
|
{
|
||
|
$this->client = \Akamai\Open\EdgeGrid\Client::createFromEdgeRcFile('ccu');
|
||
|
|
||
|
}
|
||
|
|
||
|
public function postPurgeRequest($hostname, $objects)
|
||
|
{
|
||
|
$purge_body = [
|
||
|
'objects' => $objects
|
||
|
];
|
||
|
|
||
|
$response = $this->client->post('/ccu/v3/invalidate/url', [
|
||
|
'body' => json_encode($purge_body),
|
||
|
'headers' => ['Content-Type' => 'application/json']
|
||
|
]);
|
||
|
return $response;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$ccu = new CcuClient();
|
||
|
$url = $_POST['url'];
|
||
|
|
||
|
try {
|
||
|
$objects = [
|
||
|
$url
|
||
|
];
|
||
|
|
||
|
$purge = $ccu->postPurgeRequest('data.chinarundreisen.com', $objects);
|
||
|
$response = json_decode($purge->getBody());
|
||
|
if($response->httpStatus == 201){
|
||
|
echo '{"msg":"success"}';
|
||
|
}else{
|
||
|
echo json_encode($response);
|
||
|
}
|
||
|
} catch (\GuzzleHttp\Exception\ClientException $e) {
|
||
|
header("status: 404 not found");
|
||
|
echo "An error occurred: " .$e->getMessage(). "\n";
|
||
|
}
|