Skip to content

Commit 4694904

Browse files
authored
Merge pull request #69 from levidurfee/body-accessor
Added a `body` property to the endpoint classes with an accessor
2 parents 7e3e367 + 57318b2 commit 4694904

24 files changed

Lines changed: 244 additions & 106 deletions

src/Endpoints/AccessRules.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44

55
use Cloudflare\API\Adapter\Adapter;
66
use Cloudflare\API\Configurations\Configurations;
7+
use Cloudflare\API\Traits\BodyAccessorTrait;
78

89
class AccessRules implements API
910
{
11+
use BodyAccessorTrait;
12+
1013
private $adapter;
1114

1215
public function __construct(Adapter $adapter)
@@ -78,9 +81,9 @@ public function listRules(
7881
}
7982

8083
$data = $this->adapter->get('zones/' . $zoneID . '/firewall/access_rules/rules', $query);
81-
$body = json_decode($data->getBody());
84+
$this->body = json_decode($data->getBody());
8285

83-
return (object)['result' => $body->result, 'result_info' => $body->result_info];
86+
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
8487
}
8588

8689
public function createRule(
@@ -100,9 +103,9 @@ public function createRule(
100103

101104
$query = $this->adapter->post('zones/' . $zoneID . '/firewall/access_rules/rules', $options);
102105

103-
$body = json_decode($query->getBody());
106+
$this->body = json_decode($query->getBody());
104107

105-
if (isset($body->result->id)) {
108+
if (isset($this->body->result->id)) {
106109
return true;
107110
}
108111

@@ -125,9 +128,9 @@ public function updateRule(
125128

126129
$query = $this->adapter->patch('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, $options);
127130

128-
$body = json_decode($query->getBody());
131+
$this->body = json_decode($query->getBody());
129132

130-
if (isset($body->result->id)) {
133+
if (isset($this->body->result->id)) {
131134
return true;
132135
}
133136

@@ -142,9 +145,9 @@ public function deleteRule(string $zoneID, string $ruleID, string $cascade = 'no
142145

143146
$data = $this->adapter->delete('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, $options);
144147

145-
$body = json_decode($data->getBody());
148+
$this->body = json_decode($data->getBody());
146149

147-
if (isset($body->result->id)) {
150+
if (isset($this->body->result->id)) {
148151
return true;
149152
}
150153

src/Endpoints/CustomHostnames.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
namespace Cloudflare\API\Endpoints;
1010

1111
use Cloudflare\API\Adapter\Adapter;
12+
use Cloudflare\API\Traits\BodyAccessorTrait;
1213

1314
class CustomHostnames implements API
1415
{
16+
use BodyAccessorTrait;
17+
1518
private $adapter;
1619

1720
public function __construct(Adapter $adapter)
@@ -40,8 +43,8 @@ public function addHostname(string $zoneID, string $hostname, string $sslMethod
4043
];
4144

4245
$zone = $this->adapter->post('zones/'.$zoneID.'/custom_hostnames', $options);
43-
$body = json_decode($zone->getBody());
44-
return $body->result;
46+
$this->body = json_decode($zone->getBody());
47+
return $this->body->result;
4548
}
4649

4750
/**
@@ -88,9 +91,9 @@ public function listHostnames(
8891
}
8992

9093
$zone = $this->adapter->get('zones/'.$zoneID.'/custom_hostnames', $query);
91-
$body = json_decode($zone->getBody());
94+
$this->body = json_decode($zone->getBody());
9295

93-
return (object)['result' => $body->result, 'result_info' => $body->result_info];
96+
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
9497
}
9598

9699
/**
@@ -101,9 +104,9 @@ public function listHostnames(
101104
public function getHostname(string $zoneID, string $hostnameID)
102105
{
103106
$zone = $this->adapter->get('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID);
104-
$body = json_decode($zone->getBody());
107+
$this->body = json_decode($zone->getBody());
105108

106-
return $body->result;
109+
return $this->body->result;
107110
}
108111

109112
/**
@@ -132,8 +135,8 @@ public function updateHostname(string $zoneID, string $hostnameID, string $sslMe
132135
];
133136

134137
$zone = $this->adapter->patch('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID, $options);
135-
$body = json_decode($zone->getBody());
136-
return $body->result;
138+
$this->body = json_decode($zone->getBody());
139+
return $this->body->result;
137140
}
138141

139142
/**
@@ -144,7 +147,7 @@ public function updateHostname(string $zoneID, string $hostnameID, string $sslMe
144147
public function deleteHostname(string $zoneID, string $hostnameID): \stdClass
145148
{
146149
$zone = $this->adapter->delete('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID);
147-
$body = json_decode($zone->getBody());
148-
return $body;
150+
$this->body = json_decode($zone->getBody());
151+
return $this->body;
149152
}
150153
}

src/Endpoints/DNS.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
namespace Cloudflare\API\Endpoints;
1010

1111
use Cloudflare\API\Adapter\Adapter;
12+
use Cloudflare\API\Traits\BodyAccessorTrait;
1213

1314
class DNS implements API
1415
{
16+
use BodyAccessorTrait;
17+
1518
private $adapter;
1619

1720
public function __construct(Adapter $adapter)
@@ -63,9 +66,9 @@ public function addRecord(
6366

6467
$user = $this->adapter->post('zones/' . $zoneID . '/dns_records', $options);
6568

66-
$body = json_decode($user->getBody());
69+
$this->body = json_decode($user->getBody());
6770

68-
if (isset($body->result->id)) {
71+
if (isset($this->body->result->id)) {
6972
return true;
7073
}
7174

@@ -110,31 +113,32 @@ public function listRecords(
110113
}
111114

112115
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records', $query);
113-
$body = json_decode($user->getBody());
116+
$this->body = json_decode($user->getBody());
114117

115-
return (object)['result' => $body->result, 'result_info' => $body->result_info];
118+
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
116119
}
117120

118121
public function getRecordDetails(string $zoneID, string $recordID): \stdClass
119122
{
120123
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records/' . $recordID);
121-
$body = json_decode($user->getBody());
122-
return $body->result;
124+
$this->body = json_decode($user->getBody());
125+
return $this->body->result;
123126
}
124127

125128
public function updateRecordDetails(string $zoneID, string $recordID, array $details): \stdClass
126129
{
127130
$response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, $details);
128-
return json_decode($response->getBody());
131+
$this->body = json_decode($response->getBody());
132+
return $this->body;
129133
}
130134

131135
public function deleteRecord(string $zoneID, string $recordID): bool
132136
{
133137
$user = $this->adapter->delete('zones/' . $zoneID . '/dns_records/' . $recordID);
134138

135-
$body = json_decode($user->getBody());
139+
$this->body = json_decode($user->getBody());
136140

137-
if (isset($body->result->id)) {
141+
if (isset($this->body->result->id)) {
138142
return true;
139143
}
140144

src/Endpoints/IPs.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
namespace Cloudflare\API\Endpoints;
1010

1111
use Cloudflare\API\Adapter\Adapter;
12+
use Cloudflare\API\Traits\BodyAccessorTrait;
1213

1314
class IPs implements API
1415
{
16+
use BodyAccessorTrait;
17+
1518
private $adapter;
1619

1720
public function __construct(Adapter $adapter)
@@ -22,8 +25,8 @@ public function __construct(Adapter $adapter)
2225
public function listIPs(): \stdClass
2326
{
2427
$ips = $this->adapter->get('ips');
25-
$body = json_decode($ips->getBody());
28+
$this->body = json_decode($ips->getBody());
2629

27-
return $body->result;
30+
return $this->body->result;
2831
}
2932
}

src/Endpoints/PageRules.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
use Cloudflare\API\Adapter\Adapter;
1212
use Cloudflare\API\Configurations\PageRulesActions;
1313
use Cloudflare\API\Configurations\PageRulesTargets;
14+
use Cloudflare\API\Traits\BodyAccessorTrait;
1415

1516
class PageRules implements API
1617
{
18+
use BodyAccessorTrait;
19+
1720
private $adapter;
1821

1922
public function __construct(Adapter $adapter)
@@ -54,9 +57,9 @@ public function createPageRule(
5457

5558
$query = $this->adapter->post('zones/' . $zoneID . '/pagerules', $options);
5659

57-
$body = json_decode($query->getBody());
60+
$this->body = json_decode($query->getBody());
5861

59-
if (isset($body->result->id)) {
62+
if (isset($this->body->result->id)) {
6063
return true;
6164
}
6265

@@ -94,16 +97,16 @@ public function listPageRules(
9497
];
9598

9699
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules', $query);
97-
$body = json_decode($user->getBody());
100+
$this->body = json_decode($user->getBody());
98101

99-
return $body->result;
102+
return $this->body->result;
100103
}
101104

102105
public function getPageRuleDetails(string $zoneID, string $ruleID): \stdClass
103106
{
104107
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID);
105-
$body = json_decode($user->getBody());
106-
return $body->result;
108+
$this->body = json_decode($user->getBody());
109+
return $this->body->result;
107110
}
108111

109112
public function updatePageRule(
@@ -134,9 +137,9 @@ public function updatePageRule(
134137

135138
$query = $this->adapter->patch('zones/' . $zoneID . '/pagerules', $options);
136139

137-
$body = json_decode($query->getBody());
140+
$this->body = json_decode($query->getBody());
138141

139-
if (isset($body->result->id)) {
142+
if (isset($this->body->result->id)) {
140143
return true;
141144
}
142145

@@ -147,9 +150,9 @@ public function deletePageRule(string $zoneID, string $ruleID): bool
147150
{
148151
$user = $this->adapter->delete('zones/' . $zoneID . '/pagerules/' . $ruleID);
149152

150-
$body = json_decode($user->getBody());
153+
$this->body = json_decode($user->getBody());
151154

152-
if (isset($body->result->id)) {
155+
if (isset($this->body->result->id)) {
153156
return true;
154157
}
155158

src/Endpoints/Railgun.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
namespace Cloudflare\API\Endpoints;
1010

1111
use Cloudflare\API\Adapter\Adapter;
12+
use Cloudflare\API\Traits\BodyAccessorTrait;
1213

1314
class Railgun implements API
1415
{
16+
use BodyAccessorTrait;
17+
1518
private $adapter;
1619

1720
public function __construct(Adapter $adapter)
@@ -27,9 +30,9 @@ public function create(
2730
];
2831

2932
$user = $this->adapter->post('railguns', $query);
30-
$body = json_decode($user->getBody());
33+
$this->body = json_decode($user->getBody());
3134

32-
return $body;
35+
return $this->body;
3336
}
3437

3538
public function list(
@@ -47,27 +50,27 @@ public function list(
4750
}
4851

4952
$user = $this->adapter->get('railguns', $query);
50-
$body = json_decode($user->getBody());
53+
$this->body = json_decode($user->getBody());
5154

52-
return (object)['result' => $body->result, 'result_info' => $body->result_info];
55+
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
5356
}
5457

5558
public function get(
5659
string $railgunID
5760
): \stdClass {
5861
$user = $this->adapter->get('railguns/' . $railgunID);
59-
$body = json_decode($user->getBody());
62+
$this->body = json_decode($user->getBody());
6063

61-
return $body->result;
64+
return $this->body->result;
6265
}
6366

6467
public function getZones(
6568
string $railgunID
6669
): \stdClass {
6770
$user = $this->adapter->get('railguns/' . $railgunID . '/zones');
68-
$body = json_decode($user->getBody());
71+
$this->body = json_decode($user->getBody());
6972

70-
return (object)['result' => $body->result, 'result_info' => $body->result_info];
73+
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
7174
}
7275

7376
public function update(
@@ -79,18 +82,18 @@ public function update(
7982
];
8083

8184
$user = $this->adapter->patch('railguns/' . $railgunID, $query);
82-
$body = json_decode($user->getBody());
85+
$this->body = json_decode($user->getBody());
8386

84-
return $body->result;
87+
return $this->body->result;
8588
}
8689

8790
public function delete(
8891
string $railgunID
8992
): bool {
9093
$user = $this->adapter->delete('railguns/' . $railgunID);
91-
$body = json_decode($user->getBody());
94+
$this->body = json_decode($user->getBody());
9295

93-
if (isset($body->result->id)) {
96+
if (isset($this->body->result->id)) {
9497
return true;
9598
}
9699

0 commit comments

Comments
 (0)