diff --git a/src/Endpoints/ZoneSettings.php b/src/Endpoints/ZoneSettings.php index a32b84f..b7baf48 100644 --- a/src/Endpoints/ZoneSettings.php +++ b/src/Endpoints/ZoneSettings.php @@ -9,9 +9,12 @@ namespace Cloudflare\API\Endpoints; use Cloudflare\API\Adapter\Adapter; +use Cloudflare\API\Traits\BodyAccessorTrait; class ZoneSettings implements API { + use BodyAccessorTrait; + private $adapter; public function __construct(Adapter $adapter) @@ -75,6 +78,20 @@ class ZoneSettings implements API return false; } + public function getServerSideExcludeSetting($zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/server_side_exclude' + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return $body->result->value; + } + + return false; + } + public function getHotlinkProtectionSetting($zoneID) { $return = $this->adapter->get( @@ -177,4 +194,21 @@ class ZoneSettings implements API return false; } + + public function updateServerSideExcludeSetting($zoneID, $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/server_side_exclude', + [ + 'value' => $value + ] + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return $body->result->value; + } + + return false; + } } diff --git a/tests/Endpoints/ZoneSettingsTest.php b/tests/Endpoints/ZoneSettingsTest.php new file mode 100644 index 0000000..05bc2a7 --- /dev/null +++ b/tests/Endpoints/ZoneSettingsTest.php @@ -0,0 +1,39 @@ +getPsr7JsonResponseForFixture('Endpoints/getServerSideExclude.json'); + + $mock = $this->getMockBuilder(Adapter::class)->getMock(); + $mock->method('get')->willReturn($response); + + $mock->expects($this->once())->method('get'); + + $zones = new ZoneSettings($mock); + $result = $zones->getServerSideExcludeSetting('023e105f4ecef8ad9ca31a8372d0c353'); + + $this->assertSame('on', $result); + } + + public function testUpdateServerSideExcludeSetting() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateServerSideExclude.json'); + + $mock = $this->getMockBuilder(Adapter::class)->getMock(); + $mock->method('patch')->willReturn($response); + + $mock->expects($this->once())->method('patch'); + + $zones = new ZoneSettings($mock); + $result = $zones->updateServerSideExcludeSetting('023e105f4ecef8ad9ca31a8372d0c353', 'on'); + + $this->assertSame('on', $result); + } +} diff --git a/tests/Fixtures/Endpoints/getServerSideExclude.json b/tests/Fixtures/Endpoints/getServerSideExclude.json new file mode 100644 index 0000000..8da6ab1 --- /dev/null +++ b/tests/Fixtures/Endpoints/getServerSideExclude.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "server_side_exclude", + "value": "on", + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +} diff --git a/tests/Fixtures/Endpoints/updateServerSideExclude.json b/tests/Fixtures/Endpoints/updateServerSideExclude.json new file mode 100644 index 0000000..8da6ab1 --- /dev/null +++ b/tests/Fixtures/Endpoints/updateServerSideExclude.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "server_side_exclude", + "value": "on", + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +}