Merge pull request #4 from cloudflare/COM-40

COM-40 :: Added None Auth class, IPs endpoint and associated tests
This commit is contained in:
Junade
2017-09-05 13:13:03 +01:00
committed by GitHub
11 changed files with 155 additions and 52 deletions

View File

@@ -19,8 +19,12 @@ class Guzzle implements Adapter
/**
* @inheritDoc
*/
public function __construct(Auth $auth, String $baseURI = "https://api.cloudflare.com/client/v4/")
public function __construct(Auth $auth, String $baseURI = null)
{
if ($baseURI === null) {
$baseURI = "https://api.cloudflare.com/client/v4/";
}
$headers = $auth->getHeaders();
$this->client = new Client([

18
src/Auth/None.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 04/09/2017
* Time: 19:55
*/
namespace Cloudflare\API\Auth;
class None implements Auth
{
public function getHeaders(): array
{
return [];
}
}

View File

@@ -19,8 +19,14 @@ class DNS implements API
$this->adapter = $adapter;
}
public function addRecord(string $zoneID, string $type, string $name, string $content, int $ttl = 0, bool $proxied = true): bool
{
public function addRecord(
string $zoneID,
string $type,
string $name,
string $content,
int $ttl = 0,
bool $proxied = true
): bool {
$options = [
'type' => $type,
'name' => $name,
@@ -46,6 +52,7 @@ class DNS implements API
public function listRecords(
string $zoneID,
string $type = "",
string $name = "",
string $content = "",
int $page = 1,
int $perPage = 20,
@@ -79,7 +86,9 @@ class DNS implements API
$options['direction'] = $direction;
}
$user = $this->adapter->get('zones/'.$zoneID.'/dns_records', [], $options);
$query = http_build_query($options);
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records?' . $query, []);
$body = json_decode($user->getBody());
$result = new \stdClass();
@@ -91,20 +100,20 @@ class DNS implements API
public function getRecordDetails(string $zoneID, string $recordID): \stdClass
{
$user = $this->adapter->get('zones/'.$zoneID.'/dns_records/'.$recordID, []);
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records/' . $recordID, []);
$body = json_decode($user->getBody());
return $body->result;
}
public function updateRecordDetails(string $zoneID, string $recordID, array $details): \stdClass
{
$response = $this->adapter->put('zones/'.$zoneID.'/dns_records/'.$recordID, [], $details);
$response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, [], $details);
return json_decode($response->getBody());
}
public function deleteRecord(string $zoneID, string $recordID): bool
{
$user = $this->adapter->delete('zones/'.$zoneID.'/dns_records/'.$recordID, [], []);
$user = $this->adapter->delete('zones/' . $zoneID . '/dns_records/' . $recordID, [], []);
$body = json_decode($user->getBody());

29
src/Endpoints/IPs.php Normal file
View File

@@ -0,0 +1,29 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 04/09/2017
* Time: 19:56
*/
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
class IPs implements API
{
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
public function listIPs(): \stdClass {
$ips = $this->adapter->get('ips', []);
$body = json_decode($ips->getBody());
return $body->result;
}
}

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;
}
}

View File

@@ -80,7 +80,9 @@ class Zones implements API
$options['direction'] = $direction;
}
$user = $this->adapter->get('zones', [], $options);
$query = http_build_query($options);
$user = $this->adapter->get('zones?' . $query, []);
$body = json_decode($user->getBody());
$result = new \stdClass();