public function purge_request($request) { $success = false; $webapi = new Webapi(); $response = $webapi->execute(self::PURGE_ENDPOINT, $this->config, 'POST', $request); $result = array('api-request' => $request, 'api-response' => $response); $json = json_decode($response['contents'], true); if ($response['http_code'] == 201) { // Request accepted. $cdnRequest = new \Model\CdnRequest(); $cdnRequest->cdnType = $this->get_cdn(); $cdnRequest->accountName = $this->user; $cdnRequest->estimatedSeconds = $json['estimatedSeconds']; $cdnRequest->progressUri = $json['progressUri']; $cdnRequest->purgeId = $json['purgeId']; $cdnRequest->supportId = $json['supportId']; $cdnRequest->httpStatus = $json['httpStatus']; $cdnRequest->detail = $json['detail']; $cdnRequest->pingAfterSeconds = $json['pingAfterSeconds']; $cdnRequest->created_at = date('Y-m-d H:i:s'); $cdnRequest->updated_at = date('Y-m-d H:i:s'); $cdnRequest->done = 0; $cdnRequest->save(); $success = true; $result['api-response-json'] = $json; $result['message'] = 'akamai(' . $this->user . '):: Purge request accepted - [' . $json['purgeId'] . ']'; } else { $result['error'] = $json['title']; } $result['success'] = $success; return $result; }
public function purge_request($request, $urls = null) { $success = false; $zone_id = $this->get_zoned_id($request); if ($zone_id != FALSE) { $webapi = new Webapi(); if (is_null($urls)) { $response = $webapi->execute(self::API_BASE . 'zones/purge/' . $zone_id . '.json', $this->config, 'GET'); } else { $params = array('urls' => $urls); $response = $webapi->execute(self::API_BASE . 'zones/purge/' . $zone_id . '.json', $this->config, 'DELETE', http_build_query($params)); } $result = array('api-request' => $request, 'api-response' => $response); $json = json_decode($response['contents'], true); if ($json['status'] == 'success') { // Request accepted. $cdnRequest = new \Model\CdnRequest(); $cdnRequest->cdnType = $this->get_cdn(); $cdnRequest->accountName = $this->user; $cdnRequest->estimatedSeconds = 0; $cdnRequest->progressUri = ''; $cdnRequest->purgeId = md5(uniqid('keycdn')); $cdnRequest->supportId = ''; $cdnRequest->httpStatus = 200; $cdnRequest->detail = $json['description']; $cdnRequest->pingAfterSeconds = 0; $cdnRequest->created_at = date('Y-m-d H:i:s'); $cdnRequest->updated_at = date('Y-m-d H:i:s'); $cdnRequest->done = 0; $cdnRequest->save(); $success = true; $result['api-response-json'] = $json; $result['message'] = 'keycdn(' . $this->user . '):: Purge request accepted - [' . $cdnRequest->purgeId . ']'; } else { $result['error'] = $json['description']; } } else { $result['error'] = 'Invalid zone name.'; } $result['success'] = $success; return $result; }