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
Warmup.php
157 lines
| 1 | <?php |
| 2 | namespace NitroPack\SDK\Api; |
| 3 | |
| 4 | class Warmup extends SignedBase { |
| 5 | public function enable() { |
| 6 | $path = 'warmup/enable/' . $this->siteId; |
| 7 | |
| 8 | $httpResponse = $this->makeRequest($path); |
| 9 | |
| 10 | $status = ResponseStatus::getStatus($httpResponse->getStatusCode()); |
| 11 | switch ($status) { |
| 12 | case ResponseStatus::OK: |
| 13 | return true; |
| 14 | default: |
| 15 | $this->throwException($httpResponse, 'Error while enabling cache warmup: %s'); |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | public function disable() { |
| 20 | $path = 'warmup/disable/' . $this->siteId; |
| 21 | |
| 22 | $httpResponse = $this->makeRequest($path); |
| 23 | |
| 24 | $status = ResponseStatus::getStatus($httpResponse->getStatusCode()); |
| 25 | switch ($status) { |
| 26 | case ResponseStatus::OK: |
| 27 | return true; |
| 28 | default: |
| 29 | $this->throwException($httpResponse, 'Error while disabling cache warmup: %s'); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | public function reset() { |
| 34 | $path = 'warmup/reset/' . $this->siteId; |
| 35 | |
| 36 | $httpResponse = $this->makeRequest($path); |
| 37 | |
| 38 | $status = ResponseStatus::getStatus($httpResponse->getStatusCode()); |
| 39 | switch ($status) { |
| 40 | case ResponseStatus::OK: |
| 41 | return true; |
| 42 | default: |
| 43 | $this->throwException($httpResponse, 'Error while resetting cache warmup: %s'); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | public function stats() { |
| 48 | $path = 'warmup/stats/' . $this->siteId; |
| 49 | |
| 50 | $httpResponse = $this->makeRequest($path); |
| 51 | |
| 52 | $status = ResponseStatus::getStatus($httpResponse->getStatusCode()); |
| 53 | switch ($status) { |
| 54 | case ResponseStatus::OK: |
| 55 | return json_decode($httpResponse->getBody(), true); |
| 56 | default: |
| 57 | $this->throwException($httpResponse, 'Error while fetching cache warmup stats: %s'); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | public function setSitemap($url = NULL) { |
| 62 | $path = 'warmup/setsitemap/' . $this->siteId; |
| 63 | |
| 64 | if (!empty($url)) { |
| 65 | // Set sitemap URL |
| 66 | $post = array( |
| 67 | 'url' => $url |
| 68 | ); |
| 69 | } else { |
| 70 | // Unset sitemap URL |
| 71 | $post = array(); |
| 72 | } |
| 73 | |
| 74 | $httpResponse = $this->makeRequest($path, array(), array(), 'POST', $post); |
| 75 | |
| 76 | $status = ResponseStatus::getStatus($httpResponse->getStatusCode()); |
| 77 | switch ($status) { |
| 78 | case ResponseStatus::OK: |
| 79 | return true; |
| 80 | default: |
| 81 | $this->throwException($httpResponse, 'Error while setting sitemap URL: %s'); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | public function setHomepage($url = NULL) { |
| 86 | $path = 'warmup/sethomepageurl/' . $this->siteId; |
| 87 | |
| 88 | if (!empty($url)) { |
| 89 | // Set sitemap URL |
| 90 | $post = array( |
| 91 | 'url' => $url |
| 92 | ); |
| 93 | } else { |
| 94 | // Unset sitemap URL |
| 95 | $post = array(); |
| 96 | } |
| 97 | |
| 98 | $httpResponse = $this->makeRequest($path, array(), array(), 'POST', $post); |
| 99 | |
| 100 | $status = ResponseStatus::getStatus($httpResponse->getStatusCode()); |
| 101 | switch ($status) { |
| 102 | case ResponseStatus::OK: |
| 103 | return true; |
| 104 | default: |
| 105 | $this->throwException($httpResponse, 'Error while setting sitemap URL: %s'); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | public function estimate($id = NULL, $urls = NULL) { |
| 110 | $path = 'warmup/estimate/' . $this->siteId; |
| 111 | |
| 112 | if ($id) { |
| 113 | $path .= '/' . $id; |
| 114 | } |
| 115 | |
| 116 | $post = array(); |
| 117 | if (!empty($urls)) { |
| 118 | $post = array( |
| 119 | 'urls' => is_array($urls) ? $urls : [$urls] |
| 120 | ); |
| 121 | } |
| 122 | |
| 123 | $httpResponse = $this->makeRequest($path, array(), array(), 'POST', $post); |
| 124 | |
| 125 | $status = ResponseStatus::getStatus($httpResponse->getStatusCode()); |
| 126 | switch ($status) { |
| 127 | case ResponseStatus::OK: |
| 128 | return json_decode($httpResponse->getBody(), true); |
| 129 | default: |
| 130 | $this->throwException($httpResponse, 'Error while setting sitemap URL: %s'); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | public function run($urls = NULL, $force = false) { |
| 135 | $path = 'warmup/run/' . $this->siteId; |
| 136 | |
| 137 | $post = array(); |
| 138 | if (!empty($urls)) { |
| 139 | $post['urls'] = is_array($urls) ? $urls : [$urls]; |
| 140 | } |
| 141 | |
| 142 | if ($force) { |
| 143 | $post['force'] = 1; |
| 144 | } |
| 145 | |
| 146 | $httpResponse = $this->makeRequest($path, array(), array(), 'POST', $post); |
| 147 | |
| 148 | $status = ResponseStatus::getStatus($httpResponse->getStatusCode()); |
| 149 | switch ($status) { |
| 150 | case ResponseStatus::OK: |
| 151 | return true; |
| 152 | default: |
| 153 | $this->throwException($httpResponse, 'Error while setting sitemap URL: %s'); |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 |