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
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
@@ -40,4 +40,4 @@ echo $user->getUserID();
## Licensing
Licensed under the 3-clause BSD license. See the [LICENSE](LICENSE) file for details.
Licensed under the 3-clause BSD license. See the [LICENSE](LICENSE) file for details.

View File

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

View File

@@ -38,9 +38,9 @@ class Guzzle implements Adapter
/**
* @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);
return $response;

View File

@@ -60,35 +60,33 @@ class DNS implements API
string $direction = "",
string $match = "all"
): \stdClass {
$options = [
$query = [
'page' => $page,
'per_page' => $perPage,
'match' => $match
];
if (!empty($type)) {
$options['type'] = $type;
$query['type'] = $type;
}
if (!empty($name)) {
$options['name'] = $name;
$query['name'] = $name;
}
if (!empty($content)) {
$options['content'] = $content;
$query['content'] = $content;
}
if (!empty($order)) {
$options['order'] = $order;
$query['order'] = $order;
}
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());
$result = new \stdClass();
@@ -100,7 +98,7 @@ 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;
}

View File

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

View File

@@ -77,16 +77,14 @@ class PageRules implements API
throw new EndpointException('Match can only be any or all.');
}
$options = [
$query = [
'status' => $status,
'order' => $order,
'direction' => $direction,
'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());
return $body->result;
@@ -94,7 +92,7 @@ class PageRules implements API
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());
return $body->result;
}

View File

@@ -24,14 +24,12 @@ class UARules implements API
int $page = 1,
int $perPage = 20
): \stdClass {
$options = [
$query = [
'page' => $page,
'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());
$result = new \stdClass();

View File

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

View File

@@ -24,14 +24,12 @@ class ZoneLockdown implements API
int $page = 1,
int $perPage = 20
): \stdClass {
$options = [
$query = [
'page' => $page,
'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());
$result = new \stdClass();
@@ -75,7 +73,7 @@ class ZoneLockdown implements API
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());
return $body->result;
}

View File

@@ -58,31 +58,29 @@ class Zones implements API
string $direction = "",
string $match = "all"
): \stdClass {
$options = [
$query = [
'page' => $page,
'per_page' => $perPage,
'match' => $match
];
if (!empty($name)) {
$options['name'] = $name;
$query['name'] = $name;
}
if (!empty($status)) {
$options['status'] = $status;
$query['status'] = $status;
}
if (!empty($order)) {
$options['order'] = $order;
$query['order'] = $order;
}
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());
$result = new \stdClass();
@@ -96,7 +94,7 @@ class Zones implements API
{
$zones = $this->listZones($name);
if (sizeof($zones) < 1) {
if (sizeof($zones->result) < 1) {
throw new EndpointException("Could not find zones with specified name.");
}
@@ -142,4 +140,4 @@ class Zones implements API
return false;
}
}
}

View File

@@ -34,7 +34,7 @@ class GuzzleTest extends PHPUnit_Framework_TestCase
$body = json_decode($response->getBody());
$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());
$this->assertEquals("Test2", $body->headers->{"X-Another-Test"});
}

View File

@@ -88,8 +88,17 @@ class DNSTest extends PHPUnit_Framework_TestCase
$mock->expects($this->once())
->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'),
$this->equalTo([])
->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([])
);
$zones = new \Cloudflare\API\Endpoints\DNS($mock);

View File

@@ -116,7 +116,14 @@ class PageRulesTest extends PHPUnit_Framework_TestCase
$mock->expects($this->once())
->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);

View File

@@ -45,8 +45,12 @@ class UARulesTest extends PHPUnit_Framework_TestCase
$mock->expects($this->once())
->method('get')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules?page=1&per_page=20'),
$this->equalTo([])
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
$this->equalTo([
'page' => 1,
'per_page' => 20
]),
$this->equalTo([])
);
$zones = new \Cloudflare\API\Endpoints\UARules($mock);

View File

@@ -43,8 +43,12 @@ class ZoneLockdownTest extends PHPUnit_Framework_TestCase
$mock->expects($this->once())
->method('get')
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns?page=1&per_page=20'),
$this->equalTo([])
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
]),
$this->equalTo([])
);
$zones = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);

View File

@@ -196,7 +196,16 @@ class ZonesTest extends PHPUnit_Framework_TestCase
$mock->expects($this->once())
->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([])
);
@@ -280,8 +289,14 @@ class ZonesTest extends PHPUnit_Framework_TestCase
$mock->expects($this->once())
->method('get')
->with($this->equalTo('zones?page=1&per_page=20&match=all&name=example.com'),
$this->equalTo([])
->with($this->equalTo('zones'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'name' => 'example.com',
]),
$this->equalTo([])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);