13 Commits
1.0.0 ... 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
Junade
f38b1c61f7 Merge pull request #10 from cloudflare/COM-45
COM-45 :: Bugfix active status in Page Rules
2017-09-20 15:00:53 +01:00
Junade Ali
635a299b43 COM-45 :: Update PageRule tests. 2017-09-20 14:55:44 +01:00
Junade Ali
85d64f8afc COM-45 :: Bugfix active status in Page Rules 2017-09-20 14:50:55 +01:00
Junade
48db6337c5 Merge pull request #9 from cloudflare/COM-45
COM-45 :: Bugfix Page Rules class
2017-09-20 14:35:25 +01:00
Junade Ali
4699270f51 COM-45 :: Bugfix Page Rules class 2017-09-20 14:32:46 +01:00
Junade
2a3929824e Merge pull request #8 from cloudflare/COM-45
COM-45 :: Change API submission type to JSON and adjust function names
2017-09-20 13:36:44 +01:00
Junade Ali
121209e4ca COM-45 :: Adjust Guzzle Tests 2017-09-20 13:25:00 +01:00
Junade Ali
1baeeee882 COM-40 :: Change API submission type to JSON and adjust function names 2017-09-20 13:15:34 +01:00
16 changed files with 99 additions and 74 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

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;
@@ -71,7 +71,7 @@ class Guzzle implements Adapter
$response = $this->client->put($uri, [
'headers' => $headers,
'body' => $jsonBody
'json' => $jsonBody
]
);
@@ -88,7 +88,7 @@ class Guzzle implements Adapter
$response = $this->client->patch($uri, [
'headers' => $headers,
'body' => $jsonBody
'json' => $jsonBody
]
);
@@ -103,7 +103,7 @@ class Guzzle implements Adapter
{
$response = $this->client->delete($uri, [
'headers' => $headers,
'form_params' => $body
'json' => $body
]
);

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

@@ -35,7 +35,7 @@ class PageRules implements API
];
if ($active !== null) {
$options['active'] = $active == true ? 'active' : 'disabled';
$options['status'] = $active == true ? 'active' : 'disabled';
}
if ($priority !== null) {
@@ -60,7 +60,7 @@ class PageRules implements API
string $order = null,
string $direction = null,
string $match = null
): \stdClass {
): array {
if (is_null($status) && !in_array($status, ['active', 'disabled'])) {
throw new EndpointException('Page Rules can only be listed by status of active or disabled.');
}
@@ -77,28 +77,22 @@ 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());
$result = new \stdClass();
$result->result = $body->result;
$result->result_info = $body->result_info;
return $result;
return $body->result;
}
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;
}
@@ -121,7 +115,7 @@ class PageRules implements API
}
if ($active !== null) {
$options['active'] = $active == true ? 'active' : 'disabled';
$options['status'] = $active == true ? 'active' : 'disabled';
}
if ($priority !== null) {

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.");
}
@@ -108,7 +106,7 @@ class Zones implements API
* @param string $zoneID
* @return bool
*/
public function purgeAll(string $zoneID): bool
public function cachePurgeEverything(string $zoneID): bool
{
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', [], ["purge_everything" => true]);
@@ -121,7 +119,7 @@ class Zones implements API
return false;
}
public function purge(string $zoneID, array $files = [], array $tags = []): bool
public function cachePurge(string $zoneID, array $files = [], array $tags = []): bool
{
if (empty($files) && empty($tags)) {
throw new EndpointException("No files or tags to purge.");

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"});
}
@@ -58,7 +58,7 @@ class GuzzleTest extends PHPUnit_Framework_TestCase
$this->assertEquals("application/json", $headers["Content-Type"][0]);
$body = json_decode($response->getBody());
$this->assertEquals("Testing a PUT request.", $body->json->{"X-Put-Test"});
$this->assertEquals("Testing a PUT request.", json_decode($body->json)->{"X-Put-Test"});
}
public function testPatch()
@@ -70,7 +70,7 @@ class GuzzleTest extends PHPUnit_Framework_TestCase
$this->assertEquals("application/json", $headers["Content-Type"][0]);
$body = json_decode($response->getBody());
$this->assertEquals("Testing a PATCH request.", $body->json->{"X-Patch-Test"});
$this->assertEquals("Testing a PATCH request.", json_decode($body->json)->{"X-Patch-Test"});
}
public function testDelete()
@@ -82,7 +82,7 @@ class GuzzleTest extends PHPUnit_Framework_TestCase
$this->assertEquals("application/json", $headers["Content-Type"][0]);
$body = json_decode($response->getBody());
$this->assertEquals("Testing a DELETE request.", $body->form->{"X-Delete-Test"});
$this->assertEquals("Testing a DELETE request.", $body->json->{"X-Delete-Test"});
}
public function testErrors()

View File

@@ -88,7 +88,16 @@ 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'),
->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([])
);

View File

@@ -57,8 +57,8 @@ class PageRulesTest extends PHPUnit_Framework_TestCase
$this->equalTo([
'targets' => $target->getArray(),
'actions' => $action->getArray(),
'active' => 'active',
'priority' => '1'
'status' => 'active',
'priority' => 1
])
);
@@ -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);
@@ -217,8 +224,8 @@ class PageRulesTest extends PHPUnit_Framework_TestCase
$this->equalTo([
'targets' => $target->getArray(),
'actions' => $action->getArray(),
'active' => 'active',
'priority' => '1'
'status' => 'active',
'priority' => 1
])
);

View File

@@ -45,7 +45,11 @@ 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'),
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
$this->equalTo([
'page' => 1,
'per_page' => 20
]),
$this->equalTo([])
);

View File

@@ -43,7 +43,11 @@ class ZoneLockdownTest extends PHPUnit_Framework_TestCase
$mock->expects($this->once())
->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([])
);

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,7 +289,13 @@ 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'),
->with($this->equalTo('zones'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'name' => 'example.com',
]),
$this->equalTo([])
);
@@ -290,7 +305,7 @@ class ZonesTest extends PHPUnit_Framework_TestCase
$this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result);
}
public function testPurgeAll()
public function testCachePurgeEverything()
{
$stream = GuzzleHttp\Psr7\stream_for('{
"success": true,
@@ -312,7 +327,7 @@ class ZonesTest extends PHPUnit_Framework_TestCase
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->purgeAll("c2547eb745079dac9320b638f5e225cf483cc5cfdda41");
$result = $zones->cachePurgeEverything("c2547eb745079dac9320b638f5e225cf483cc5cfdda41");
$this->assertTrue($result);
}