Skip to content

Commit

Permalink
Merge pull request #102 from umbrellio/add_endpoints_zones_settings
Browse files Browse the repository at this point in the history
add endpoint for server-side exclude setting
  • Loading branch information
IcyApril authored Feb 3, 2020
2 parents 445bc30 + 39b2f2f commit 2a83d24
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Endpoints/ZoneSettings.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 ZoneSettings implements API
{
use BodyAccessorTrait;

private $adapter;

public function __construct(Adapter $adapter)
Expand Down Expand Up @@ -75,6 +78,20 @@ public function getEmailObfuscationSetting($zoneID)
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(
Expand Down Expand Up @@ -177,4 +194,21 @@ public function updateHotlinkProtectionSetting($zoneID, $value)

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;
}
}
39 changes: 39 additions & 0 deletions tests/Endpoints/ZoneSettingsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Endpoints\ZoneSettings;

class ZoneSettingsTest extends TestCase
{
public function testGetServerSideExcludeSetting()
{
$response = $this->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);
}
}
11 changes: 11 additions & 0 deletions tests/Fixtures/Endpoints/getServerSideExclude.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
11 changes: 11 additions & 0 deletions tests/Fixtures/Endpoints/updateServerSideExclude.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit 2a83d24

Please sign in to comment.