5 Commits
1.0.2 ... 1.0.3

Author SHA1 Message Date
Junade
b91dd5e684 Merge pull request #5 from typhonius/add-query-to-get
Adds the query parameter to the guzzle call for GET requests.
2017-09-21 23:16:50 +01:00
Junade
77df7ead1e Merge pull request #11 from typhonius/fix-zone-id-verification
Changes sizeof check to throw an error if no zone id is found.
2017-09-21 18:07:55 +01:00
Adam Malone
9939afd0b6 Changes sizeof check to throw an error if no zone id is found. 2017-09-22 02:53:25 +10:00
Adam Malone
7d838d7f5f Adds the query parameter to the guzzle call for GET requests. 2017-09-21 11:45:21 +10:00
Junade
ebe2a9803a Added link to Packagist and the Cloudflare KB 2017-09-20 16:17:49 +01:00
16 changed files with 81 additions and 52 deletions

View File

@@ -4,7 +4,7 @@
## Installation ## Installation
The recommended way to install this package is via the Packagist Dependency Manager. The recommended way to install this package is via the Packagist Dependency Manager ([cloudflare/sdk](https://packagist.org/packages/cloudflare/sdk)). You can specific usage examples on the Cloudflare Knowledge Base under: [Cloudflare PHP API Binding](https://support.cloudflare.com/hc/en-us/articles/115001661191)
## Cloudflare API version 4 ## Cloudflare API version 4

View File

@@ -35,7 +35,7 @@ interface Adapter
* *
* @return mixed * @return mixed
*/ */
public function get(String $uri, array $headers): ResponseInterface; public function get(String $uri, array $query, array $headers): ResponseInterface;
/** /**
* @param String $uri * @param String $uri

View File

@@ -38,9 +38,9 @@ class Guzzle implements Adapter
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function get(String $uri, array $headers = array()): ResponseInterface public function get(String $uri, array $query = array(), array $headers = array()): ResponseInterface
{ {
$response = $this->client->get($uri, ['headers' => $headers]); $response = $this->client->get($uri, ['query' => $query, 'headers' => $headers]);
$this->checkError($response); $this->checkError($response);
return $response; return $response;

View File

@@ -60,35 +60,33 @@ class DNS implements API
string $direction = "", string $direction = "",
string $match = "all" string $match = "all"
): \stdClass { ): \stdClass {
$options = [ $query = [
'page' => $page, 'page' => $page,
'per_page' => $perPage, 'per_page' => $perPage,
'match' => $match 'match' => $match
]; ];
if (!empty($type)) { if (!empty($type)) {
$options['type'] = $type; $query['type'] = $type;
} }
if (!empty($name)) { if (!empty($name)) {
$options['name'] = $name; $query['name'] = $name;
} }
if (!empty($content)) { if (!empty($content)) {
$options['content'] = $content; $query['content'] = $content;
} }
if (!empty($order)) { if (!empty($order)) {
$options['order'] = $order; $query['order'] = $order;
} }
if (!empty($direction)) { if (!empty($direction)) {
$options['direction'] = $direction; $query['direction'] = $direction;
} }
$query = http_build_query($options); $user = $this->adapter->get('zones/' . $zoneID . '/dns_records', $query, []);
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records?' . $query, []);
$body = json_decode($user->getBody()); $body = json_decode($user->getBody());
$result = new \stdClass(); $result = new \stdClass();
@@ -100,7 +98,7 @@ class DNS implements API
public function getRecordDetails(string $zoneID, string $recordID): \stdClass 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()); $body = json_decode($user->getBody());
return $body->result; return $body->result;
} }

View File

@@ -21,7 +21,7 @@ class IPs implements API
} }
public function listIPs(): \stdClass { public function listIPs(): \stdClass {
$ips = $this->adapter->get('ips', []); $ips = $this->adapter->get('ips', [], []);
$body = json_decode($ips->getBody()); $body = json_decode($ips->getBody());
return $body->result; return $body->result;

View File

@@ -77,16 +77,14 @@ class PageRules implements API
throw new EndpointException('Match can only be any or all.'); throw new EndpointException('Match can only be any or all.');
} }
$options = [ $query = [
'status' => $status, 'status' => $status,
'order' => $order, 'order' => $order,
'direction' => $direction, 'direction' => $direction,
'match' => $match 'match' => $match
]; ];
$query = http_build_query($options); $user = $this->adapter->get('zones/' . $zoneID . '/pagerules', $query, []);
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules?' . $query, []);
$body = json_decode($user->getBody()); $body = json_decode($user->getBody());
return $body->result; return $body->result;
@@ -94,7 +92,7 @@ class PageRules implements API
public function getPageRuleDetails(string $zoneID, string $ruleID): \stdClass public function getPageRuleDetails(string $zoneID, string $ruleID): \stdClass
{ {
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID, []); $user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID, [], []);
$body = json_decode($user->getBody()); $body = json_decode($user->getBody());
return $body->result; return $body->result;
} }

View File

@@ -24,14 +24,12 @@ class UARules implements API
int $page = 1, int $page = 1,
int $perPage = 20 int $perPage = 20
): \stdClass { ): \stdClass {
$options = [ $query = [
'page' => $page, 'page' => $page,
'per_page' => $perPage 'per_page' => $perPage
]; ];
$query = http_build_query($options); $user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules', $query, []);
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules?' . $query, []);
$body = json_decode($user->getBody()); $body = json_decode($user->getBody());
$result = new \stdClass(); $result = new \stdClass();

View File

@@ -21,7 +21,7 @@ class User implements API
public function getUserDetails(): \stdClass public function getUserDetails(): \stdClass
{ {
$user = $this->adapter->get('user', []); $user = $this->adapter->get('user', [], []);
$body = json_decode($user->getBody()); $body = json_decode($user->getBody());
return $body->result; return $body->result;
} }

View File

@@ -24,14 +24,12 @@ class ZoneLockdown implements API
int $page = 1, int $page = 1,
int $perPage = 20 int $perPage = 20
): \stdClass { ): \stdClass {
$options = [ $query = [
'page' => $page, 'page' => $page,
'per_page' => $perPage 'per_page' => $perPage
]; ];
$query = http_build_query($options); $user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns', $query, []);
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns?' . $query, []);
$body = json_decode($user->getBody()); $body = json_decode($user->getBody());
$result = new \stdClass(); $result = new \stdClass();
@@ -75,7 +73,7 @@ class ZoneLockdown implements API
public function getLockdownDetails(string $zoneID, string $lockdownID): \stdClass public function getLockdownDetails(string $zoneID, string $lockdownID): \stdClass
{ {
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, []); $user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, [], []);
$body = json_decode($user->getBody()); $body = json_decode($user->getBody());
return $body->result; return $body->result;
} }

View File

@@ -58,31 +58,29 @@ class Zones implements API
string $direction = "", string $direction = "",
string $match = "all" string $match = "all"
): \stdClass { ): \stdClass {
$options = [ $query = [
'page' => $page, 'page' => $page,
'per_page' => $perPage, 'per_page' => $perPage,
'match' => $match 'match' => $match
]; ];
if (!empty($name)) { if (!empty($name)) {
$options['name'] = $name; $query['name'] = $name;
} }
if (!empty($status)) { if (!empty($status)) {
$options['status'] = $status; $query['status'] = $status;
} }
if (!empty($order)) { if (!empty($order)) {
$options['order'] = $order; $query['order'] = $order;
} }
if (!empty($direction)) { if (!empty($direction)) {
$options['direction'] = $direction; $query['direction'] = $direction;
} }
$query = http_build_query($options); $user = $this->adapter->get('zones', $query, []);
$user = $this->adapter->get('zones?' . $query, []);
$body = json_decode($user->getBody()); $body = json_decode($user->getBody());
$result = new \stdClass(); $result = new \stdClass();
@@ -96,7 +94,7 @@ class Zones implements API
{ {
$zones = $this->listZones($name); $zones = $this->listZones($name);
if (sizeof($zones) < 1) { if (sizeof($zones->result) < 1) {
throw new EndpointException("Could not find zones with specified name."); throw new EndpointException("Could not find zones with specified name.");
} }

View File

@@ -34,7 +34,7 @@ class GuzzleTest extends PHPUnit_Framework_TestCase
$body = json_decode($response->getBody()); $body = json_decode($response->getBody());
$this->assertEquals("Test", $body->headers->{"X-Testing"}); $this->assertEquals("Test", $body->headers->{"X-Testing"});
$response = $this->client->get('https://httpbin.org/get', ['X-Another-Test' => 'Test2']); $response = $this->client->get('https://httpbin.org/get', [], ['X-Another-Test' => 'Test2']);
$body = json_decode($response->getBody()); $body = json_decode($response->getBody());
$this->assertEquals("Test2", $body->headers->{"X-Another-Test"}); $this->assertEquals("Test2", $body->headers->{"X-Another-Test"});
} }

View File

@@ -88,7 +88,16 @@ class DNSTest extends PHPUnit_Framework_TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('get') ->method('get')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records?page=1&per_page=20&match=all&type=A&name=example.com&content=127.0.0.1&order=type&direction=desc'), ->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'type' => 'A',
'name' => 'example.com',
'content' => '127.0.0.1',
'order' => 'type',
'direction' => 'desc']),
$this->equalTo([]) $this->equalTo([])
); );

View File

@@ -116,7 +116,14 @@ class PageRulesTest extends PHPUnit_Framework_TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('get') ->method('get')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules?status=active&order=status&direction=desc&match=all'), $this->equalTo([]) ->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
$this->equalTo([
'status' => 'active',
'order' => 'status',
'direction' => 'desc',
'match' => 'all'
]),
$this->equalTo([])
); );
$pr = new \Cloudflare\API\Endpoints\PageRules($mock); $pr = new \Cloudflare\API\Endpoints\PageRules($mock);

View File

@@ -45,7 +45,11 @@ class UARulesTest extends PHPUnit_Framework_TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('get') ->method('get')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules?page=1&per_page=20'), ->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
$this->equalTo([
'page' => 1,
'per_page' => 20
]),
$this->equalTo([]) $this->equalTo([])
); );

View File

@@ -43,7 +43,11 @@ class ZoneLockdownTest extends PHPUnit_Framework_TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('get') ->method('get')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns?page=1&per_page=20'), ->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
]),
$this->equalTo([]) $this->equalTo([])
); );

View File

@@ -196,7 +196,16 @@ class ZonesTest extends PHPUnit_Framework_TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('get') ->method('get')
->with($this->equalTo('zones?page=1&per_page=20&match=all&name=example.com&status=active&order=status&direction=desc'), ->with($this->equalTo('zones'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'name' => 'example.com',
'status' => 'active',
'order' => 'status',
'direction' => 'desc'
]),
$this->equalTo([]) $this->equalTo([])
); );
@@ -280,7 +289,13 @@ class ZonesTest extends PHPUnit_Framework_TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('get') ->method('get')
->with($this->equalTo('zones?page=1&per_page=20&match=all&name=example.com'), ->with($this->equalTo('zones'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'name' => 'example.com',
]),
$this->equalTo([]) $this->equalTo([])
); );