Skip to content

Commit

Permalink
Add Browser Cache TTL endpoint (#127)
Browse files Browse the repository at this point in the history
Co-authored-by: bnalonezi <[email protected]>
  • Loading branch information
bnalonezi and bnalonezi authored Jul 7, 2020
1 parent afd332a commit fab493d
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Endpoints/ZoneSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,37 @@ public function getHotlinkProtectionSetting($zoneID)
return false;
}

public function getBrowserCacheTtlSetting($zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/browser_cache_ttl'
);
$body = json_decode($return->getBody());

if ($body->success) {
return $body->result->value;
}

return false;
}

public function updateBrowserCacheTtlSetting($zoneID, $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/browser_cache_ttl',
[
'value' => $value
]
);
$body = json_decode($return->getBody());

if ($body->success) {
return true;
}

return false;
}

public function updateMinifySetting($zoneID, $html, $css, $javascript)
{
$return = $this->adapter->patch(
Expand Down
30 changes: 30 additions & 0 deletions tests/Endpoints/ZoneSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,34 @@ public function testUpdateServerSideExcludeSetting()

$this->assertSame('on', $result);
}

public function testGetBrowserCacheTtlSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getBrowserCacheTtlSetting.json');

$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('get')->willReturn($response);

$mock->expects($this->once())->method('get');

$zones = new ZoneSettings($mock);
$result = $zones->getBrowserCacheTtlSetting('023e105f4ecef8ad9ca31a8372d0c353');

$this->assertSame(14400, $result);
}

public function testUpdateBrowserCacheTtlSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateBrowserCacheTtlSetting.json');

$mock = $this->getMockBuilder(Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);

$mock->expects($this->once())->method('patch');

$zones = new ZoneSettings($mock);
$result = $zones->updateBrowserCacheTtlSetting('023e105f4ecef8ad9ca31a8372d0c353', 16070400);

$this->assertTrue($result);
}
}
11 changes: 11 additions & 0 deletions tests/Fixtures/Endpoints/getBrowserCacheTtlSetting.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "browser_cache_ttl",
"value": 14400,
"editable": true,
"modified_on": "2014-01-01T05:20:00.12345Z"
}
}
11 changes: 11 additions & 0 deletions tests/Fixtures/Endpoints/updateBrowserCacheTtlSetting.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "browser_cache_ttl",
"value": 14400,
"editable": true,
"modified_on": "2014-01-01T05:20:00.12345Z"
}
}

0 comments on commit fab493d

Please sign in to comment.