Skip to content

Commit 7d838d7

Browse files
committed
Adds the query parameter to the guzzle call for GET requests.
1 parent a4ddb61 commit 7d838d7

File tree

15 files changed

+77
-48
lines changed

15 files changed

+77
-48
lines changed

src/Adapter/Adapter.php

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 8 additions & 10 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,14 @@ 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
$result = new \stdClass();
@@ -98,7 +96,7 @@ public function listPageRules(
9896

9997
public function getPageRuleDetails(string $zoneID, string $ruleID): \stdClass
10098
{
101-
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID, []);
99+
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID, [], []);
102100
$body = json_decode($user->getBody());
103101
return $body->result;
104102
}

src/Endpoints/UARules.php

Lines changed: 2 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 5 deletions
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

Lines changed: 6 additions & 8 deletions
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

Lines changed: 1 addition & 1 deletion
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
}

0 commit comments

Comments
 (0)