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