From 6176cd81a3f9df94663fe2b5bb9e5797ebf1b07e Mon Sep 17 00:00:00 2001 From: Junade Ali Date: Fri, 9 Jun 2017 16:18:24 +0100 Subject: [PATCH] Added extra endpoints. --- src/Endpoints/DNS.php | 46 +++++++++++++++++++++++++++++++++++ src/Endpoints/Zones.php | 3 +-- tests/Endpoints/DNSTest.php | 14 +++++++++++ tests/Endpoints/PageRules.php | 22 +++++++++++++++++ 4 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 src/Endpoints/DNS.php create mode 100644 tests/Endpoints/DNSTest.php create mode 100644 tests/Endpoints/PageRules.php diff --git a/src/Endpoints/DNS.php b/src/Endpoints/DNS.php new file mode 100644 index 0000000..3b8d2e9 --- /dev/null +++ b/src/Endpoints/DNS.php @@ -0,0 +1,46 @@ +adapter = $adapter; + } + + public function addRecord(string $zoneID, string $type, string $name, string $content, int $ttl = 0, bool $proxied = true): bool + { + $options = [ + 'type' => $type, + 'name' => $name, + 'content' => $content, + 'proxied' => $proxied + ]; + + if ($ttl > 0) { + $options['ttl'] = $ttl; + } + + $user = $this->adapter->post('zones/' . $zoneID . '/dns_records', [], $options); + + $body = json_decode($user->getBody()); + + if (isset($body->result->id)) { + return true; + } + + return false; + } + +} \ No newline at end of file diff --git a/src/Endpoints/Zones.php b/src/Endpoints/Zones.php index f6ab4e2..486fa1b 100644 --- a/src/Endpoints/Zones.php +++ b/src/Endpoints/Zones.php @@ -9,7 +9,6 @@ namespace Cloudflare\API\Endpoints; use Cloudflare\API\Adapter\Adapter; -use Symfony\Component\Config\Definition\Exception\Exception; class Zones implements API { @@ -123,7 +122,7 @@ class Zones implements API public function purge(string $zoneID, array $files = [], array $tags = []): bool { if (empty($files) && empty($tags)) { - throw new Exception("No files or tags to purge."); + throw new EndpointException("No files or tags to purge."); } $options = [ diff --git a/tests/Endpoints/DNSTest.php b/tests/Endpoints/DNSTest.php new file mode 100644 index 0000000..121d232 --- /dev/null +++ b/tests/Endpoints/DNSTest.php @@ -0,0 +1,14 @@ +adapter = $adapter; + } +} \ No newline at end of file