Skip to content

Commit

Permalink
Merge pull request #5 from typhonius/add-query-to-get
Browse files Browse the repository at this point in the history
Adds the query parameter to the guzzle call for GET requests.
  • Loading branch information
IcyApril authored Sep 21, 2017
2 parents 77df7ea + 7d838d7 commit b91dd5e
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/Adapter/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(Auth $auth, String $baseURI);
*
* @return mixed
*/
public function get(String $uri, array $headers): ResponseInterface;
public function get(String $uri, array $query, array $headers): ResponseInterface;

/**
* @param String $uri
Expand Down
4 changes: 2 additions & 2 deletions src/Adapter/Guzzle.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public function __construct(Auth $auth, String $baseURI = null)
/**
* @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;
Expand Down
18 changes: 8 additions & 10 deletions src/Endpoints/DNS.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,35 +60,33 @@ public function listRecords(
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();
Expand All @@ -100,7 +98,7 @@ public function listRecords(

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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Endpoints/IPs.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(Adapter $adapter)
}

public function listIPs(): \stdClass {
$ips = $this->adapter->get('ips', []);
$ips = $this->adapter->get('ips', [], []);
$body = json_decode($ips->getBody());

return $body->result;
Expand Down
8 changes: 3 additions & 5 deletions src/Endpoints/PageRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,22 @@ public function listPageRules(
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;
}

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;
}
Expand Down
6 changes: 2 additions & 4 deletions src/Endpoints/UARules.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ public function listRules(
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();
Expand Down
2 changes: 1 addition & 1 deletion src/Endpoints/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(Adapter $adapter)

public function getUserDetails(): \stdClass
{
$user = $this->adapter->get('user', []);
$user = $this->adapter->get('user', [], []);
$body = json_decode($user->getBody());
return $body->result;
}
Expand Down
8 changes: 3 additions & 5 deletions src/Endpoints/ZoneLockdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ public function listLockdowns(
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();
Expand Down Expand Up @@ -75,7 +73,7 @@ public function createLockdown(

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;
}
Expand Down
14 changes: 6 additions & 8 deletions src/Endpoints/Zones.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,31 +58,29 @@ public function listZones(
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();
Expand Down
2 changes: 1 addition & 1 deletion tests/Adapter/GuzzleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testGet()
$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"});
}
Expand Down
13 changes: 11 additions & 2 deletions tests/Endpoints/DNSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,17 @@ public function testListRecords()

$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);
Expand Down
9 changes: 8 additions & 1 deletion tests/Endpoints/PageRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ public function testListPageRules()

$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);
Expand Down
8 changes: 6 additions & 2 deletions tests/Endpoints/UARulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ public function testListRules()

$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);
Expand Down
8 changes: 6 additions & 2 deletions tests/Endpoints/ZoneLockdownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ public function testListLockdowns()

$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);
Expand Down
21 changes: 18 additions & 3 deletions tests/Endpoints/ZonesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,16 @@ public function testListZones()

$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([])
);

Expand Down Expand Up @@ -280,8 +289,14 @@ public function testGetZoneID()

$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);
Expand Down

0 comments on commit b91dd5e

Please sign in to comment.