Skip to content

Commit 2639331

Browse files
committed
Add BodyAccessorTrait to most classes
1 parent d871bdd commit 2639331

12 files changed

Lines changed: 99 additions & 55 deletions

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)
@@ -57,9 +60,9 @@ public function addRecord(
5760

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

60-
$body = json_decode($user->getBody());
63+
$this->body = json_decode($user->getBody());
6164

62-
if (isset($body->result->id)) {
65+
if (isset($this->body->result->id)) {
6366
return true;
6467
}
6568

@@ -104,31 +107,32 @@ public function listRecords(
104107
}
105108

106109
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records', $query);
107-
$body = json_decode($user->getBody());
110+
$this->body = json_decode($user->getBody());
108111

109-
return (object)['result' => $body->result, 'result_info' => $body->result_info];
112+
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
110113
}
111114

112115
public function getRecordDetails(string $zoneID, string $recordID): \stdClass
113116
{
114117
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records/' . $recordID);
115-
$body = json_decode($user->getBody());
116-
return $body->result;
118+
$this->body = json_decode($user->getBody());
119+
return $this->body->result;
117120
}
118121

119122
public function updateRecordDetails(string $zoneID, string $recordID, array $details): \stdClass
120123
{
121124
$response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, $details);
122-
return json_decode($response->getBody());
125+
$this->body = json_decode($response->getBody());
126+
return $this->body;
123127
}
124128

125129
public function deleteRecord(string $zoneID, string $recordID): bool
126130
{
127131
$user = $this->adapter->delete('zones/' . $zoneID . '/dns_records/' . $recordID);
128132

129-
$body = json_decode($user->getBody());
133+
$this->body = json_decode($user->getBody());
130134

131-
if (isset($body->result->id)) {
135+
if (isset($this->body->result->id)) {
132136
return true;
133137
}
134138

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

src/Endpoints/UARules.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010

1111
use Cloudflare\API\Configurations\Configurations;
1212
use Cloudflare\API\Adapter\Adapter;
13+
use Cloudflare\API\Traits\BodyAccessorTrait;
1314

1415
class UARules implements API
1516
{
17+
use BodyAccessorTrait;
18+
1619
private $adapter;
1720

1821
public function __construct(Adapter $adapter)
@@ -31,9 +34,9 @@ public function listRules(
3134
];
3235

3336
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules', $query);
34-
$body = json_decode($user->getBody());
37+
$this->body = json_decode($user->getBody());
3538

36-
return (object)['result' => $body->result, 'result_info' => $body->result_info];
39+
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
3740
}
3841

3942
public function createRule(
@@ -58,9 +61,9 @@ public function createRule(
5861

5962
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/ua_rules', $options);
6063

61-
$body = json_decode($user->getBody());
64+
$this->body = json_decode($user->getBody());
6265

63-
if (isset($body->result->id)) {
66+
if (isset($this->body->result->id)) {
6467
return true;
6568
}
6669

@@ -70,8 +73,8 @@ public function createRule(
7073
public function getRuleDetails(string $zoneID, string $blockID): \stdClass
7174
{
7275
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules/' . $blockID);
73-
$body = json_decode($user->getBody());
74-
return $body->result;
76+
$this->body = json_decode($user->getBody());
77+
return $this->body->result;
7578
}
7679

7780
public function updateRule(
@@ -93,9 +96,9 @@ public function updateRule(
9396

9497
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID, $options);
9598

96-
$body = json_decode($user->getBody());
99+
$this->body = json_decode($user->getBody());
97100

98-
if (isset($body->result->id)) {
101+
if (isset($this->body->result->id)) {
99102
return true;
100103
}
101104

@@ -106,9 +109,9 @@ public function deleteRule(string $zoneID, string $ruleID): bool
106109
{
107110
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID);
108111

109-
$body = json_decode($user->getBody());
112+
$this->body = json_decode($user->getBody());
110113

111-
if (isset($body->result->id)) {
114+
if (isset($this->body->result->id)) {
112115
return true;
113116
}
114117

0 commit comments

Comments
 (0)