Added extra endpoints.

This commit is contained in:
Junade Ali
2017-06-09 16:18:24 +01:00
parent 7ab10aaeaa
commit 6176cd81a3
4 changed files with 83 additions and 2 deletions

46
src/Endpoints/DNS.php Normal file
View File

@@ -0,0 +1,46 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 09/06/2017
* Time: 15:14
*/
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
class DNS implements API
{
private $adapter;
public function __construct(Adapter $adapter)
{
$this->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;
}
}

View File

@@ -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 = [

View File

@@ -0,0 +1,14 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 09/06/2017
* Time: 15:31
*/
use Cloudflare\API\Endpoints\DNS;
class DNSTest extends PHPUnit_Framework_TestCase
{
}

View File

@@ -0,0 +1,22 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 09/06/2017
* Time: 16:17
*/
namespace Cloudflare\API\Adapter;
use Cloudflare\API\Endpoints\API;
class PageRules implements API
{
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
}