Added changeDevelopmentMode & getAnalyticsDashboard to Zones (#32)
* Added toggleDevelopmentMode to Zones * Improved success checking Added PHPUnit test (I think?) * Fixed success checking * Fixed test * Ran PHP CS Fixer * Added getAnalyticsDashboard to Zones Renamed toggleDevelopmentMode to changeDevelopmentMode to be uniform * Fixed test (hopefully) * Trying it a different way * Another attempt * Lol I guess we are just supressing errors for this one?
This commit is contained in:
@@ -109,6 +109,43 @@ class Zones implements API
|
|||||||
return $zones->result[0]->id;
|
return $zones->result[0]->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||||
|
*
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $since
|
||||||
|
* @param string $until
|
||||||
|
* @param bool $continuous
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
|
public function getAnalyticsDashboard(string $zoneID, string $since = "-10080", string $until = "0", bool $continuous = true): \stdClass
|
||||||
|
{
|
||||||
|
$response = $this->adapter->get('zones/' . $zoneID . '/analytics/dashboard', [], ["since" => $since, "until" => $until, "continuous" => $continuous]);
|
||||||
|
|
||||||
|
return json_decode($response->getBody())->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||||
|
*
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param bool $enable
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function changeDevelopmentMode(string $zoneID, bool $enable = false): bool
|
||||||
|
{
|
||||||
|
$response = $this->adapter->patch('zones/' . $zoneID . '/settings/development_mode', [], ["value" => ($enable ? "on" : "off")]);
|
||||||
|
|
||||||
|
$body = json_decode($response->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Purge Everything
|
* Purge Everything
|
||||||
* @param string $zoneID
|
* @param string $zoneID
|
||||||
|
|||||||
@@ -129,6 +129,49 @@ class ZonesTest extends TestCase
|
|||||||
$this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result);
|
$this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetAnalyticsDashboard()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getAnalyticsDashboard.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/analytics/dashboard'),
|
||||||
|
$this->equalTo([]),
|
||||||
|
$this->equalTo(["since" => "-10080", "until" => "0", "continuous" => true])
|
||||||
|
);
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
|
$analytics = $zones->getAnalyticsDashboard("c2547eb745079dac9320b638f5e225cf483cc5cfdda41");
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute("since", $analytics->totals);
|
||||||
|
$this->assertObjectHasAttribute("since", $analytics->timeseries[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testChangeDevelopmentMode()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/changeDevelopmentMode.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/development_mode'),
|
||||||
|
$this->equalTo([]),
|
||||||
|
$this->equalTo(["value" => "on"])
|
||||||
|
);
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
|
$result = $zones->changeDevelopmentMode("c2547eb745079dac9320b638f5e225cf483cc5cfdda41", true);
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
public function testCachePurgeEverything()
|
public function testCachePurgeEverything()
|
||||||
{
|
{
|
||||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeEverything.json');
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeEverything.json');
|
||||||
|
|||||||
12
tests/Fixtures/Endpoints/changeDevelopmentMode.json
Normal file
12
tests/Fixtures/Endpoints/changeDevelopmentMode.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"result": {
|
||||||
|
"id": "development_mode",
|
||||||
|
"value": "on",
|
||||||
|
"modified_on": "2017-11-06T05:16:42.864300Z",
|
||||||
|
"time_remaining": 10800,
|
||||||
|
"editable": true
|
||||||
|
},
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": []
|
||||||
|
}
|
||||||
176
tests/Fixtures/Endpoints/getAnalyticsDashboard.json
Normal file
176
tests/Fixtures/Endpoints/getAnalyticsDashboard.json
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"totals": {
|
||||||
|
"since": "2015-01-01T12:23:00Z",
|
||||||
|
"until": "2015-01-02T12:23:00Z",
|
||||||
|
"requests": {
|
||||||
|
"all": 1234085328,
|
||||||
|
"cached": 1234085328,
|
||||||
|
"uncached": 13876154,
|
||||||
|
"content_type": {
|
||||||
|
"css": 15343,
|
||||||
|
"html": 1234213,
|
||||||
|
"javascript": 318236,
|
||||||
|
"gif": 23178,
|
||||||
|
"jpeg": 1982048
|
||||||
|
},
|
||||||
|
"country": {
|
||||||
|
"US": 4181364,
|
||||||
|
"AG": 37298,
|
||||||
|
"GI": 293846
|
||||||
|
},
|
||||||
|
"ssl": {
|
||||||
|
"encrypted": 12978361,
|
||||||
|
"unencrypted": 781263
|
||||||
|
},
|
||||||
|
"http_status": {
|
||||||
|
"200": 13496983,
|
||||||
|
"301": 283,
|
||||||
|
"400": 187936,
|
||||||
|
"402": 1828,
|
||||||
|
"404": 1293
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"bandwidth": {
|
||||||
|
"all": 213867451,
|
||||||
|
"cached": 113205063,
|
||||||
|
"uncached": 113205063,
|
||||||
|
"content_type": {
|
||||||
|
"css": 237421,
|
||||||
|
"html": 1231290,
|
||||||
|
"javascript": 123245,
|
||||||
|
"gif": 1234242,
|
||||||
|
"jpeg": 784278
|
||||||
|
},
|
||||||
|
"country": {
|
||||||
|
"US": 123145433,
|
||||||
|
"AG": 2342483,
|
||||||
|
"GI": 984753
|
||||||
|
},
|
||||||
|
"ssl": {
|
||||||
|
"encrypted": 37592942,
|
||||||
|
"unencrypted": 237654192
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"threats": {
|
||||||
|
"all": 23423873,
|
||||||
|
"country": {
|
||||||
|
"US": 123,
|
||||||
|
"CN": 523423,
|
||||||
|
"AU": 91
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"user.ban.ip": 123,
|
||||||
|
"hot.ban.unknown": 5324,
|
||||||
|
"macro.chl.captchaErr": 1341,
|
||||||
|
"macro.chl.jschlErr": 5323
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pageviews": {
|
||||||
|
"all": 5724723,
|
||||||
|
"search_engines": {
|
||||||
|
"googlebot": 35272,
|
||||||
|
"pingdom": 13435,
|
||||||
|
"bingbot": 5372,
|
||||||
|
"baidubot": 1345
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"uniques": {
|
||||||
|
"all": 12343
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"timeseries": [
|
||||||
|
{
|
||||||
|
"since": "2015-01-01T12:23:00Z",
|
||||||
|
"until": "2015-01-02T12:23:00Z",
|
||||||
|
"requests": {
|
||||||
|
"all": 1234085328,
|
||||||
|
"cached": 1234085328,
|
||||||
|
"uncached": 13876154,
|
||||||
|
"content_type": {
|
||||||
|
"css": 15343,
|
||||||
|
"html": 1234213,
|
||||||
|
"javascript": 318236,
|
||||||
|
"gif": 23178,
|
||||||
|
"jpeg": 1982048
|
||||||
|
},
|
||||||
|
"country": {
|
||||||
|
"US": 4181364,
|
||||||
|
"AG": 37298,
|
||||||
|
"GI": 293846
|
||||||
|
},
|
||||||
|
"ssl": {
|
||||||
|
"encrypted": 12978361,
|
||||||
|
"unencrypted": 781263
|
||||||
|
},
|
||||||
|
"http_status": {
|
||||||
|
"200": 13496983,
|
||||||
|
"301": 283,
|
||||||
|
"400": 187936,
|
||||||
|
"402": 1828,
|
||||||
|
"404": 1293
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"bandwidth": {
|
||||||
|
"all": 213867451,
|
||||||
|
"cached": 113205063,
|
||||||
|
"uncached": 113205063,
|
||||||
|
"content_type": {
|
||||||
|
"css": 237421,
|
||||||
|
"html": 1231290,
|
||||||
|
"javascript": 123245,
|
||||||
|
"gif": 1234242,
|
||||||
|
"jpeg": 784278
|
||||||
|
},
|
||||||
|
"country": {
|
||||||
|
"US": 123145433,
|
||||||
|
"AG": 2342483,
|
||||||
|
"GI": 984753
|
||||||
|
},
|
||||||
|
"ssl": {
|
||||||
|
"encrypted": 37592942,
|
||||||
|
"unencrypted": 237654192
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"threats": {
|
||||||
|
"all": 23423873,
|
||||||
|
"country": {
|
||||||
|
"US": 123,
|
||||||
|
"CN": 523423,
|
||||||
|
"AU": 91
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"user.ban.ip": 123,
|
||||||
|
"hot.ban.unknown": 5324,
|
||||||
|
"macro.chl.captchaErr": 1341,
|
||||||
|
"macro.chl.jschlErr": 5323
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pageviews": {
|
||||||
|
"all": 5724723,
|
||||||
|
"search_engines": {
|
||||||
|
"googlebot": 35272,
|
||||||
|
"pingdom": 13435,
|
||||||
|
"bingbot": 5372,
|
||||||
|
"baidubot": 1345
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"uniques": {
|
||||||
|
"all": 12343
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"query": {
|
||||||
|
"since": "2015-01-01T12:23:00Z",
|
||||||
|
"until": "2015-01-02T12:23:00Z",
|
||||||
|
"time_delta": 60
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user