Skip to content

Commit b91dd5e

Browse files
authored
Merge pull request #5 from typhonius/add-query-to-get
Adds the query parameter to the guzzle call for GET requests.
2 parents 77df7ea + 7d838d7 commit b91dd5e

15 files changed

+77
-48
lines changed

src/Adapter/Adapter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(Auth $auth, String $baseURI);
3535
*
3636
* @return mixed
3737
*/
38-
public function get(String $uri, array $headers): ResponseInterface;
38+
public function get(String $uri, array $query, array $headers): ResponseInterface;
3939

4040
/**
4141
* @param String $uri

src/Adapter/Guzzle.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public function __construct(Auth $auth, String $baseURI = null)
3838
/**
3939
* @inheritDoc
4040
*/
41-
public function get(String $uri, array $headers = array()): ResponseInterface
41+
public function get(String $uri, array $query = array(), array $headers = array()): ResponseInterface
4242
{
43-
$response = $this->client->get($uri, ['headers' => $headers]);
43+
$response = $this->client->get($uri, ['query' => $query, 'headers' => $headers]);
4444

4545
$this->checkError($response);
4646
return $response;

src/Endpoints/DNS.php

+8-10
Original file line numberDiff line numberDiff line change
@@ -60,35 +60,33 @@ public function listRecords(
6060
string $direction = "",
6161
string $match = "all"
6262
): \stdClass {
63-
$options = [
63+
$query = [
6464
'page' => $page,
6565
'per_page' => $perPage,
6666
'match' => $match
6767
];
6868

6969
if (!empty($type)) {
70-
$options['type'] = $type;
70+
$query['type'] = $type;
7171
}
7272

7373
if (!empty($name)) {
74-
$options['name'] = $name;
74+
$query['name'] = $name;
7575
}
7676

7777
if (!empty($content)) {
78-
$options['content'] = $content;
78+
$query['content'] = $content;
7979
}
8080

8181
if (!empty($order)) {
82-
$options['order'] = $order;
82+
$query['order'] = $order;
8383
}
8484

8585
if (!empty($direction)) {
86-
$options['direction'] = $direction;
86+
$query['direction'] = $direction;
8787
}
8888

89-
$query = http_build_query($options);
90-
91-
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records?' . $query, []);
89+
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records', $query, []);
9290
$body = json_decode($user->getBody());
9391

9492
$result = new \stdClass();
@@ -100,7 +98,7 @@ public function listRecords(
10098

10199
public function getRecordDetails(string $zoneID, string $recordID): \stdClass
102100
{
103-
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records/' . $recordID, []);
101+
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records/' . $recordID, [], []);
104102
$body = json_decode($user->getBody());
105103
return $body->result;
106104
}

src/Endpoints/IPs.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct(Adapter $adapter)
2121
}
2222

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

2727
return $body->result;

src/Endpoints/PageRules.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,22 @@ public function listPageRules(
7777
throw new EndpointException('Match can only be any or all.');
7878
}
7979

80-
$options = [
80+
$query = [
8181
'status' => $status,
8282
'order' => $order,
8383
'direction' => $direction,
8484
'match' => $match
8585
];
8686

87-
$query = http_build_query($options);
88-
89-
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules?' . $query, []);
87+
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules', $query, []);
9088
$body = json_decode($user->getBody());
9189

9290
return $body->result;
9391
}
9492

9593
public function getPageRuleDetails(string $zoneID, string $ruleID): \stdClass
9694
{
97-
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID, []);
95+
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID, [], []);
9896
$body = json_decode($user->getBody());
9997
return $body->result;
10098
}

src/Endpoints/UARules.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ public function listRules(
2424
int $page = 1,
2525
int $perPage = 20
2626
): \stdClass {
27-
$options = [
27+
$query = [
2828
'page' => $page,
2929
'per_page' => $perPage
3030
];
3131

32-
$query = http_build_query($options);
33-
34-
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules?' . $query, []);
32+
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules', $query, []);
3533
$body = json_decode($user->getBody());
3634

3735
$result = new \stdClass();

src/Endpoints/User.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct(Adapter $adapter)
2121

2222
public function getUserDetails(): \stdClass
2323
{
24-
$user = $this->adapter->get('user', []);
24+
$user = $this->adapter->get('user', [], []);
2525
$body = json_decode($user->getBody());
2626
return $body->result;
2727
}

src/Endpoints/ZoneLockdown.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ public function listLockdowns(
2424
int $page = 1,
2525
int $perPage = 20
2626
): \stdClass {
27-
$options = [
27+
$query = [
2828
'page' => $page,
2929
'per_page' => $perPage
3030
];
3131

32-
$query = http_build_query($options);
33-
34-
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns?' . $query, []);
32+
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns', $query, []);
3533
$body = json_decode($user->getBody());
3634

3735
$result = new \stdClass();
@@ -75,7 +73,7 @@ public function createLockdown(
7573

7674
public function getLockdownDetails(string $zoneID, string $lockdownID): \stdClass
7775
{
78-
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, []);
76+
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, [], []);
7977
$body = json_decode($user->getBody());
8078
return $body->result;
8179
}

src/Endpoints/Zones.php

+6-8
Original file line numberDiff line numberDiff line change
@@ -58,31 +58,29 @@ public function listZones(
5858
string $direction = "",
5959
string $match = "all"
6060
): \stdClass {
61-
$options = [
61+
$query = [
6262
'page' => $page,
6363
'per_page' => $perPage,
6464
'match' => $match
6565
];
6666

6767
if (!empty($name)) {
68-
$options['name'] = $name;
68+
$query['name'] = $name;
6969
}
7070

7171
if (!empty($status)) {
72-
$options['status'] = $status;
72+
$query['status'] = $status;
7373
}
7474

7575
if (!empty($order)) {
76-
$options['order'] = $order;
76+
$query['order'] = $order;
7777
}
7878

7979
if (!empty($direction)) {
80-
$options['direction'] = $direction;
80+
$query['direction'] = $direction;
8181
}
8282

83-
$query = http_build_query($options);
84-
85-
$user = $this->adapter->get('zones?' . $query, []);
83+
$user = $this->adapter->get('zones', $query, []);
8684
$body = json_decode($user->getBody());
8785

8886
$result = new \stdClass();

tests/Adapter/GuzzleTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testGet()
3434
$body = json_decode($response->getBody());
3535
$this->assertEquals("Test", $body->headers->{"X-Testing"});
3636

37-
$response = $this->client->get('https://httpbin.org/get', ['X-Another-Test' => 'Test2']);
37+
$response = $this->client->get('https://httpbin.org/get', [], ['X-Another-Test' => 'Test2']);
3838
$body = json_decode($response->getBody());
3939
$this->assertEquals("Test2", $body->headers->{"X-Another-Test"});
4040
}

tests/Endpoints/DNSTest.php

+11-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,17 @@ public function testListRecords()
8888

8989
$mock->expects($this->once())
9090
->method('get')
91-
->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'),
92-
$this->equalTo([])
91+
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
92+
$this->equalTo([
93+
'page' => 1,
94+
'per_page' => 20,
95+
'match' => 'all',
96+
'type' => 'A',
97+
'name' => 'example.com',
98+
'content' => '127.0.0.1',
99+
'order' => 'type',
100+
'direction' => 'desc']),
101+
$this->equalTo([])
93102
);
94103

95104
$zones = new \Cloudflare\API\Endpoints\DNS($mock);

tests/Endpoints/PageRulesTest.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,14 @@ public function testListPageRules()
116116

117117
$mock->expects($this->once())
118118
->method('get')
119-
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules?status=active&order=status&direction=desc&match=all'), $this->equalTo([])
119+
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
120+
$this->equalTo([
121+
'status' => 'active',
122+
'order' => 'status',
123+
'direction' => 'desc',
124+
'match' => 'all'
125+
]),
126+
$this->equalTo([])
120127
);
121128

122129
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);

tests/Endpoints/UARulesTest.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ public function testListRules()
4545

4646
$mock->expects($this->once())
4747
->method('get')
48-
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules?page=1&per_page=20'),
49-
$this->equalTo([])
48+
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
49+
$this->equalTo([
50+
'page' => 1,
51+
'per_page' => 20
52+
]),
53+
$this->equalTo([])
5054
);
5155

5256
$zones = new \Cloudflare\API\Endpoints\UARules($mock);

tests/Endpoints/ZoneLockdownTest.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ public function testListLockdowns()
4343

4444
$mock->expects($this->once())
4545
->method('get')
46-
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns?page=1&per_page=20'),
47-
$this->equalTo([])
46+
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'),
47+
$this->equalTo([
48+
'page' => 1,
49+
'per_page' => 20,
50+
]),
51+
$this->equalTo([])
4852
);
4953

5054
$zones = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);

tests/Endpoints/ZonesTest.php

+18-3
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,16 @@ public function testListZones()
196196

197197
$mock->expects($this->once())
198198
->method('get')
199-
->with($this->equalTo('zones?page=1&per_page=20&match=all&name=example.com&status=active&order=status&direction=desc'),
199+
->with($this->equalTo('zones'),
200+
$this->equalTo([
201+
'page' => 1,
202+
'per_page' => 20,
203+
'match' => 'all',
204+
'name' => 'example.com',
205+
'status' => 'active',
206+
'order' => 'status',
207+
'direction' => 'desc'
208+
]),
200209
$this->equalTo([])
201210
);
202211

@@ -280,8 +289,14 @@ public function testGetZoneID()
280289

281290
$mock->expects($this->once())
282291
->method('get')
283-
->with($this->equalTo('zones?page=1&per_page=20&match=all&name=example.com'),
284-
$this->equalTo([])
292+
->with($this->equalTo('zones'),
293+
$this->equalTo([
294+
'page' => 1,
295+
'per_page' => 20,
296+
'match' => 'all',
297+
'name' => 'example.com',
298+
]),
299+
$this->equalTo([])
285300
);
286301

287302
$zones = new \Cloudflare\API\Endpoints\Zones($mock);

0 commit comments

Comments
 (0)