AdditionalDomains.php
1 year ago
Base.php
8 months ago
Cache.php
1 year ago
ExcludedUrls.php
1 year ago
Excludes.php
1 year ago
Integration.php
1 year ago
RemoteConfigFetcher.php
1 year ago
RequestMaker.php
1 year ago
Response.php
1 year ago
ResponseStatus.php
1 year ago
SafeMode.php
1 year ago
SecureRequestMaker.php
1 year ago
SignedBase.php
1 year ago
Stats.php
1 year ago
Tagger.php
1 year ago
Url.php
1 year ago
VariationCookie.php
1 year ago
Varnish.php
1 year ago
Warmup.php
1 year ago
Webhook.php
1 year ago
Stats.php
70 lines
| 1 | <?php |
| 2 | namespace NitroPack\SDK\Api; |
| 3 | |
| 4 | class Stats extends SignedBase { |
| 5 | |
| 6 | protected $secret; |
| 7 | |
| 8 | public function __construct($siteId, $siteSecret) { |
| 9 | parent::__construct($siteId, $siteSecret); |
| 10 | $this->secret = $siteSecret; |
| 11 | } |
| 12 | |
| 13 | public function getSavings() { |
| 14 | $path = 'stats/savings/' . $this->siteId; |
| 15 | |
| 16 | $httpResponse = $this->makeRequest($path, array(), array(), 'GET'); |
| 17 | |
| 18 | $status = ResponseStatus::getStatus($httpResponse->getStatusCode()); |
| 19 | switch ($status) { |
| 20 | case ResponseStatus::OK: |
| 21 | return json_decode($httpResponse->getBody(), true); |
| 22 | default: |
| 23 | $this->throwException($httpResponse, 'Error while getting space savings information: %s'); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | public function getDiskUsage() { |
| 28 | $path = 'stats/diskusage/' . $this->siteId; |
| 29 | |
| 30 | $httpResponse = $this->makeRequest($path, array(), array(), 'GET'); |
| 31 | |
| 32 | $status = ResponseStatus::getStatus($httpResponse->getStatusCode()); |
| 33 | switch ($status) { |
| 34 | case ResponseStatus::OK: |
| 35 | return json_decode($httpResponse->getBody(), true); |
| 36 | default: |
| 37 | $this->throwException($httpResponse, 'Error while getting disk usage information: %s'); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | public function getRequestUsage() { |
| 42 | $path = 'stats/requestusage/' . $this->siteId; |
| 43 | |
| 44 | $httpResponse = $this->makeRequest($path, array(), array(), 'GET'); |
| 45 | |
| 46 | $status = ResponseStatus::getStatus($httpResponse->getStatusCode()); |
| 47 | switch ($status) { |
| 48 | case ResponseStatus::OK: |
| 49 | return json_decode($httpResponse->getBody(), true); |
| 50 | default: |
| 51 | $this->throwException($httpResponse, 'Error while getting request usage information: %s'); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | public function resetSavings() { |
| 56 | $path = 'stats/resetsavings/' . $this->siteId; |
| 57 | |
| 58 | $httpResponse = $this->makeRequest($path, array(), array(), 'GET'); |
| 59 | |
| 60 | $status = ResponseStatus::getStatus($httpResponse->getStatusCode()); |
| 61 | switch ($status) { |
| 62 | case ResponseStatus::OK: |
| 63 | return true; |
| 64 | default: |
| 65 | $this->throwException($httpResponse, 'Error while resetting stats: %s'); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | } |
| 70 |