Skip to content

Commit

Permalink
Merge pull request #69 from levidurfee/body-accessor
Browse files Browse the repository at this point in the history
Added a `body` property to the endpoint classes with an accessor
  • Loading branch information
IcyApril authored Jan 2, 2019
2 parents 7e3e367 + 57318b2 commit 4694904
Show file tree
Hide file tree
Showing 24 changed files with 244 additions and 106 deletions.
19 changes: 11 additions & 8 deletions src/Endpoints/AccessRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Configurations\Configurations;
use Cloudflare\API\Traits\BodyAccessorTrait;

class AccessRules implements API
{
use BodyAccessorTrait;

private $adapter;

public function __construct(Adapter $adapter)
Expand Down Expand Up @@ -78,9 +81,9 @@ public function listRules(
}

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

return (object)['result' => $body->result, 'result_info' => $body->result_info];
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
}

public function createRule(
Expand All @@ -100,9 +103,9 @@ public function createRule(

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

$body = json_decode($query->getBody());
$this->body = json_decode($query->getBody());

if (isset($body->result->id)) {
if (isset($this->body->result->id)) {
return true;
}

Expand All @@ -125,9 +128,9 @@ public function updateRule(

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

$body = json_decode($query->getBody());
$this->body = json_decode($query->getBody());

if (isset($body->result->id)) {
if (isset($this->body->result->id)) {
return true;
}

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

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

$body = json_decode($data->getBody());
$this->body = json_decode($data->getBody());

if (isset($body->result->id)) {
if (isset($this->body->result->id)) {
return true;
}

Expand Down
23 changes: 13 additions & 10 deletions src/Endpoints/CustomHostnames.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
namespace Cloudflare\API\Endpoints;

use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;

class CustomHostnames implements API
{
use BodyAccessorTrait;

private $adapter;

public function __construct(Adapter $adapter)
Expand Down Expand Up @@ -40,8 +43,8 @@ public function addHostname(string $zoneID, string $hostname, string $sslMethod
];

$zone = $this->adapter->post('zones/'.$zoneID.'/custom_hostnames', $options);
$body = json_decode($zone->getBody());
return $body->result;
$this->body = json_decode($zone->getBody());
return $this->body->result;
}

/**
Expand Down Expand Up @@ -88,9 +91,9 @@ public function listHostnames(
}

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

return (object)['result' => $body->result, 'result_info' => $body->result_info];
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
}

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

return $body->result;
return $this->body->result;
}

/**
Expand Down Expand Up @@ -132,8 +135,8 @@ public function updateHostname(string $zoneID, string $hostnameID, string $sslMe
];

$zone = $this->adapter->patch('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID, $options);
$body = json_decode($zone->getBody());
return $body->result;
$this->body = json_decode($zone->getBody());
return $this->body->result;
}

/**
Expand All @@ -144,7 +147,7 @@ public function updateHostname(string $zoneID, string $hostnameID, string $sslMe
public function deleteHostname(string $zoneID, string $hostnameID): \stdClass
{
$zone = $this->adapter->delete('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID);
$body = json_decode($zone->getBody());
return $body;
$this->body = json_decode($zone->getBody());
return $this->body;
}
}
22 changes: 13 additions & 9 deletions src/Endpoints/DNS.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
namespace Cloudflare\API\Endpoints;

use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;

class DNS implements API
{
use BodyAccessorTrait;

private $adapter;

public function __construct(Adapter $adapter)
Expand Down Expand Up @@ -63,9 +66,9 @@ public function addRecord(

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

$body = json_decode($user->getBody());
$this->body = json_decode($user->getBody());

if (isset($body->result->id)) {
if (isset($this->body->result->id)) {
return true;
}

Expand Down Expand Up @@ -110,31 +113,32 @@ public function listRecords(
}

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

return (object)['result' => $body->result, 'result_info' => $body->result_info];
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
}

public function getRecordDetails(string $zoneID, string $recordID): \stdClass
{
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records/' . $recordID);
$body = json_decode($user->getBody());
return $body->result;
$this->body = json_decode($user->getBody());
return $this->body->result;
}

public function updateRecordDetails(string $zoneID, string $recordID, array $details): \stdClass
{
$response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, $details);
return json_decode($response->getBody());
$this->body = json_decode($response->getBody());
return $this->body;
}

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

$body = json_decode($user->getBody());
$this->body = json_decode($user->getBody());

if (isset($body->result->id)) {
if (isset($this->body->result->id)) {
return true;
}

Expand Down
7 changes: 5 additions & 2 deletions src/Endpoints/IPs.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
namespace Cloudflare\API\Endpoints;

use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;

class IPs implements API
{
use BodyAccessorTrait;

private $adapter;

public function __construct(Adapter $adapter)
Expand All @@ -22,8 +25,8 @@ public function __construct(Adapter $adapter)
public function listIPs(): \stdClass
{
$ips = $this->adapter->get('ips');
$body = json_decode($ips->getBody());
$this->body = json_decode($ips->getBody());

return $body->result;
return $this->body->result;
}
}
23 changes: 13 additions & 10 deletions src/Endpoints/PageRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Configurations\PageRulesActions;
use Cloudflare\API\Configurations\PageRulesTargets;
use Cloudflare\API\Traits\BodyAccessorTrait;

class PageRules implements API
{
use BodyAccessorTrait;

private $adapter;

public function __construct(Adapter $adapter)
Expand Down Expand Up @@ -54,9 +57,9 @@ public function createPageRule(

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

$body = json_decode($query->getBody());
$this->body = json_decode($query->getBody());

if (isset($body->result->id)) {
if (isset($this->body->result->id)) {
return true;
}

Expand Down Expand Up @@ -94,16 +97,16 @@ public function listPageRules(
];

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

return $body->result;
return $this->body->result;
}

public function getPageRuleDetails(string $zoneID, string $ruleID): \stdClass
{
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID);
$body = json_decode($user->getBody());
return $body->result;
$this->body = json_decode($user->getBody());
return $this->body->result;
}

public function updatePageRule(
Expand Down Expand Up @@ -134,9 +137,9 @@ public function updatePageRule(

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

$body = json_decode($query->getBody());
$this->body = json_decode($query->getBody());

if (isset($body->result->id)) {
if (isset($this->body->result->id)) {
return true;
}

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

$body = json_decode($user->getBody());
$this->body = json_decode($user->getBody());

if (isset($body->result->id)) {
if (isset($this->body->result->id)) {
return true;
}

Expand Down
27 changes: 15 additions & 12 deletions src/Endpoints/Railgun.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
namespace Cloudflare\API\Endpoints;

use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Traits\BodyAccessorTrait;

class Railgun implements API
{
use BodyAccessorTrait;

private $adapter;

public function __construct(Adapter $adapter)
Expand All @@ -27,9 +30,9 @@ public function create(
];

$user = $this->adapter->post('railguns', $query);
$body = json_decode($user->getBody());
$this->body = json_decode($user->getBody());

return $body;
return $this->body;
}

public function list(
Expand All @@ -47,27 +50,27 @@ public function list(
}

$user = $this->adapter->get('railguns', $query);
$body = json_decode($user->getBody());
$this->body = json_decode($user->getBody());

return (object)['result' => $body->result, 'result_info' => $body->result_info];
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
}

public function get(
string $railgunID
): \stdClass {
$user = $this->adapter->get('railguns/' . $railgunID);
$body = json_decode($user->getBody());
$this->body = json_decode($user->getBody());

return $body->result;
return $this->body->result;
}

public function getZones(
string $railgunID
): \stdClass {
$user = $this->adapter->get('railguns/' . $railgunID . '/zones');
$body = json_decode($user->getBody());
$this->body = json_decode($user->getBody());

return (object)['result' => $body->result, 'result_info' => $body->result_info];
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
}

public function update(
Expand All @@ -79,18 +82,18 @@ public function update(
];

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

return $body->result;
return $this->body->result;
}

public function delete(
string $railgunID
): bool {
$user = $this->adapter->delete('railguns/' . $railgunID);
$body = json_decode($user->getBody());
$this->body = json_decode($user->getBody());

if (isset($body->result->id)) {
if (isset($this->body->result->id)) {
return true;
}

Expand Down
Loading

0 comments on commit 4694904

Please sign in to comment.