Skip to content

Commit fab493d

Browse files
bnalonezibnalonezi
andauthored
Add Browser Cache TTL endpoint (#127)
Co-authored-by: bnalonezi <[email protected]>
1 parent afd332a commit fab493d

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

src/Endpoints/ZoneSettings.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,37 @@ public function getHotlinkProtectionSetting($zoneID)
106106
return false;
107107
}
108108

109+
public function getBrowserCacheTtlSetting($zoneID)
110+
{
111+
$return = $this->adapter->get(
112+
'zones/' . $zoneID . '/settings/browser_cache_ttl'
113+
);
114+
$body = json_decode($return->getBody());
115+
116+
if ($body->success) {
117+
return $body->result->value;
118+
}
119+
120+
return false;
121+
}
122+
123+
public function updateBrowserCacheTtlSetting($zoneID, $value)
124+
{
125+
$return = $this->adapter->patch(
126+
'zones/' . $zoneID . '/settings/browser_cache_ttl',
127+
[
128+
'value' => $value
129+
]
130+
);
131+
$body = json_decode($return->getBody());
132+
133+
if ($body->success) {
134+
return true;
135+
}
136+
137+
return false;
138+
}
139+
109140
public function updateMinifySetting($zoneID, $html, $css, $javascript)
110141
{
111142
$return = $this->adapter->patch(

tests/Endpoints/ZoneSettingsTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,34 @@ public function testUpdateServerSideExcludeSetting()
3636

3737
$this->assertSame('on', $result);
3838
}
39+
40+
public function testGetBrowserCacheTtlSetting()
41+
{
42+
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getBrowserCacheTtlSetting.json');
43+
44+
$mock = $this->getMockBuilder(Adapter::class)->getMock();
45+
$mock->method('get')->willReturn($response);
46+
47+
$mock->expects($this->once())->method('get');
48+
49+
$zones = new ZoneSettings($mock);
50+
$result = $zones->getBrowserCacheTtlSetting('023e105f4ecef8ad9ca31a8372d0c353');
51+
52+
$this->assertSame(14400, $result);
53+
}
54+
55+
public function testUpdateBrowserCacheTtlSetting()
56+
{
57+
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateBrowserCacheTtlSetting.json');
58+
59+
$mock = $this->getMockBuilder(Adapter::class)->getMock();
60+
$mock->method('patch')->willReturn($response);
61+
62+
$mock->expects($this->once())->method('patch');
63+
64+
$zones = new ZoneSettings($mock);
65+
$result = $zones->updateBrowserCacheTtlSetting('023e105f4ecef8ad9ca31a8372d0c353', 16070400);
66+
67+
$this->assertTrue($result);
68+
}
3969
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"success": true,
3+
"errors": [],
4+
"messages": [],
5+
"result": {
6+
"id": "browser_cache_ttl",
7+
"value": 14400,
8+
"editable": true,
9+
"modified_on": "2014-01-01T05:20:00.12345Z"
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"success": true,
3+
"errors": [],
4+
"messages": [],
5+
"result": {
6+
"id": "browser_cache_ttl",
7+
"value": 14400,
8+
"editable": true,
9+
"modified_on": "2014-01-01T05:20:00.12345Z"
10+
}
11+
}

0 commit comments

Comments
 (0)