Zones endpoints.

This commit is contained in:
Junade Ali
2017-06-07 17:01:50 +01:00
parent bf8716e0b8
commit 7ab10aaeaa
3 changed files with 447 additions and 52 deletions

View File

@@ -9,6 +9,7 @@
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Symfony\Component\Config\Definition\Exception\Exception;
class Zones implements API
{
@@ -22,7 +23,7 @@ class Zones implements API
public function addZone(string $name, bool $jumpstart = false, string $organizationID = ''): \stdClass
{
$options = [
'name' => $name,
'name' => $name,
'jumpstart' => $jumpstart
];
@@ -36,4 +37,108 @@ class Zones implements API
$body = json_decode($user->getBody());
return $body->result;
}
public function activationCheck(string $zoneID): bool
{
$user = $this->adapter->put('zones/' . $zoneID . '/activation_check', [], []);
$body = json_decode($user->getBody());
if (isset($body->result->id)) {
return true;
}
return false;
}
public function listZones(
string $name = "",
string $status = "",
int $page = 1,
int $perPage = 20,
string $order = "",
string $direction = "",
string $match = "all"
): \stdClass {
$options = [
'page' => $page,
'per_page' => $perPage,
'match' => $match
];
if (!empty($name)) {
$options['name'] = $name;
}
if (!empty($status)) {
$options['status'] = $status;
}
if (!empty($order)) {
$options['order'] = $order;
}
if (!empty($direction)) {
$options['direction'] = $direction;
}
$user = $this->adapter->get('zones', [], $options);
$body = json_decode($user->getBody());
$result = new \stdClass();
$result->result = $body->result;
$result->result_info = $body->result_info;
return $result;
}
public function getZoneID(string $name = ""): string
{
$zones = $this->listZones($name);
if (sizeof($zones) < 1) {
throw new EndpointException("Could not find zones with specified name.");
}
return $zones->result[0]->id;
}
/**
* Purge Everything
* @param string $zoneID
* @return bool
*/
public function purgeAll(string $zoneID): bool
{
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', [], ["purge_everything" => true]);
$body = json_decode($user->getBody());
if (isset($body->result->id)) {
return true;
}
return false;
}
public function purge(string $zoneID, array $files = [], array $tags = []): bool
{
if (empty($files) && empty($tags)) {
throw new Exception("No files or tags to purge.");
}
$options = [
'files' => $files,
'tags' => $tags
];
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', [], $options);
$body = json_decode($user->getBody());
if (isset($body->result->id)) {
return true;
}
return false;
}
}