PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.6.0
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.6.0
1.19.8 1.19.7 1.19.6 1.19.5 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.12.0 1.13.0 1.14.0 1.15.0 1.15.1 1.15.2 1.15.3 1.16.0 1.16.1 1.16.2 1.16.3 1.16.4 1.16.5 1.16.6 1.16.7 1.16.8 1.17.0 1.17.6 1.17.7 1.17.8 1.17.9 1.18.0 1.18.1 1.18.2 1.18.3 1.18.4 1.18.5 1.18.6 1.18.7 1.18.8 1.18.9 1.19.0 1.19.1 1.19.2 1.19.3 1.19.4 1.3.19 1.3.20 1.4.0 1.4.1 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.16 1.5.17 1.5.18 1.5.19 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.8.1 1.8.3 1.9.0 1.9.1 1.9.2
nitropack / nitropack-sdk / NitroPack / SDK / Api.php
nitropack / nitropack-sdk / NitroPack / SDK Last commit date
Api 3 years ago Integrations 3 years ago StorageDriver 4 years ago Url 3 years ago data 6 years ago Api.php 3 years ago Backlog.php 4 years ago BacklogReplayTimeoutException.php 4 years ago ChallengeProcessingException.php 4 years ago ChallengeVerificationException.php 4 years ago ConfigFetcherException.php 4 years ago Crypto.php 3 years ago Device.php 6 years ago DeviceType.php 6 years ago ElementRevision.php 3 years ago EmptyConfigException.php 6 years ago FileHandle.php 5 years ago Filesystem.php 4 years ago HealthStatus.php 5 years ago IntegrationUrl.php 6 years ago NitroPack.php 3 years ago NoConfigException.php 5 years ago Pagecache.php 3 years ago PurgeType.php 3 years ago ServiceDownException.php 5 years ago StorageException.php 6 years ago VariationCookieException.php 5 years ago WebhookException.php 5 years ago Website.php 6 years ago
Api.php
344 lines
1 <?php
2 namespace NitroPack\SDK;
3
4 use \NitroPack\SDK\Website as Website;
5
6 class Api {
7 private $allowedWebhooks = array('config', 'cache_clear', 'cache_ready', 'sitemap');
8 private $children;
9 private $varnish;
10 private $excludedurls;
11 private $additionaldomains;
12
13 public function __construct($siteId, $siteSecret) {
14 $this->children = [];
15 $this->children["cache"] = new Api\Cache($siteId, $siteSecret);
16 $this->children["tagger"] = new Api\Tagger($siteId, $siteSecret);
17 $this->children["url"] = new Api\Url($siteId, $siteSecret);
18 $this->children["stats"] = new Api\Stats($siteId, $siteSecret);
19 $this->children["webhook"] = new Api\Webhook($siteId, $siteSecret);
20 $this->children["warmup"] = new Api\Warmup($siteId, $siteSecret);
21 $this->children["integration"] = new Api\Integration($siteId, $siteSecret);
22 $this->children["variation_cookie"] = new Api\VariationCookie($siteId, $siteSecret);
23 $this->children["safe_mode"] = new Api\SafeMode($siteId, $siteSecret);
24 $this->children["request_maker"] = new Api\RequestMaker($siteId);
25 $this->children["secure_request_maker"] = new Api\SecureRequestMaker($siteId, $siteSecret);
26 $this->children["varnish"] = new Api\Varnish($siteId, $siteSecret);
27 $this->children["excludedurls"] = new Api\ExcludedUrls($siteId, $siteSecret);
28 $this->children["additionaldomains"] = new Api\AdditionalDomains($siteId, $siteSecret);
29 }
30
31 public function __get($prop) {
32 return !empty($this->children[$prop]) ? $this->children[$prop] : NULL;
33 }
34
35 public function setBacklog($backlog) {
36 foreach ($this->children as $child) {
37 $child->setBacklog($backlog);
38 }
39 }
40
41 public function setNitroPack($nitropack) {
42 foreach ($this->children as $child) {
43 $child->setNitroPack($nitropack);
44 }
45 }
46
47 public function getCache($url, $userAgent, $cookies, $isAjax, $layout, $referer) {
48 return $this->cache->get($url, $userAgent, $cookies, $isAjax, $layout, NULL, $referer);
49 }
50
51 public function getLastCachePurge() {
52 return $this->cache->getLastPurge();
53 }
54
55 public function purgeCache($url = NULL, $pagecacheOnly = false, $reason = NULL, $lightPurge = false) {
56 return $this->cache->purge($url, $pagecacheOnly, $reason, $lightPurge);
57 }
58
59 public function purgeCacheByTag($tag, $reason = NULL, $lightPurge = false) {
60 return $this->cache->purgeByTag($tag, $reason, $lightPurge);
61 }
62
63 public function getUrls($page = 1, $limit = 250, $search = NULL, $deviceType = NULL, $status = NULL) {
64 return $this->url->get($page, $limit, $search, $deviceType, $status);
65 }
66
67 public function getUrlsCount($search = NULL, $deviceType = NULL, $status = NULL) {
68 $resp = $this->url->count($search, $deviceType, $status);
69 return (int)$resp["count"];
70 }
71
72 public function getPendingUrls($page = 1, $limit = 250, $priority = NULL) {
73 return $this->url->getpending($page, $limit, $priority);
74 }
75
76 public function getPendingUrlsCount($priority = NULL) {
77 $resp = $this->url->pendingCount($priority);
78 return (int)$resp["count"];
79 }
80
81 public function tagUrl($url, $tag) {
82 $resp = @json_decode($this->tagger->tag($url, $tag)->getBody());
83 if ($resp && !$resp->success) {
84 $msg = $resp->error ? $resp->error : "Unable to tag URL";
85 throw new \RuntimeException($msg);
86 }
87
88 return true;
89 }
90
91 public function untagUrl($url, $tag) {
92 $resp = json_decode($this->tagger->remove($url, $tag)->getBody(), true);
93 return $resp['removed'];
94 }
95
96 public function getTaggedUrls($tag, $page = 1, $limit = 250) {
97 return $this->tagger->getUrls($tag, $page, $limit);
98 }
99
100 public function getTaggedUrlsCount($tag) {
101 $resp = $this->tagger->getUrlsCount($tag);
102 return (int)$resp["count"];
103 }
104
105 public function getTags($url = NULL, $page = 1, $limit = 250) {
106 return $this->tagger->getTags($url, $page, $limit);
107 }
108
109 public function getSavings() {
110 return $this->stats->getSavings();
111 }
112
113 public function getDiskUsage() {
114 return $this->stats->getDiskUsage();
115 }
116
117 public function getRequestUsage() {
118 return $this->stats->getRequestUsage();
119 }
120
121 public function resetSavingsStats() {
122 return $this->stats->resetSavings();
123 }
124
125 public function enableWarmup() {
126 return $this->warmup->enable();
127 }
128
129 public function disableWarmup() {
130 return $this->warmup->disable();
131 }
132
133 public function resetWarmup() {
134 return $this->warmup->reset();
135 }
136
137 public function setWarmupSitemap($url) {
138 return $this->warmup->setSitemap($url);
139 }
140
141 public function unsetWarmupSitemap() {
142 return $this->warmup->setSitemap(NULL);
143 }
144
145 public function setWarmupHomepage($url) {
146 return $this->warmup->setHomepage($url);
147 }
148
149 public function unsetWarmupHomepage() {
150 return $this->warmup->setHomepage(NULL);
151 }
152
153 public function estimateWarmup($id = NULL, $urls = NULL) {
154 $resp = $this->warmup->estimate($id, $urls);
155 if ($id) {
156 return (int)$resp["count"];
157 } else {
158 return $resp["id"];
159 }
160 }
161
162 public function runWarmup($urls = NULL, $force = false) {
163 return $this->warmup->run($urls, $force);
164 }
165
166 public function getWarmupStats() {
167 return $this->warmup->stats();
168 }
169
170 public function unsetWebhook($type) {
171 if (!in_array($type, $this->allowedWebhooks)) {
172 throw new WebhookException("The webhook type '$type' is not supported!");
173 }
174
175 try {
176 $this->webhook->set($type, null);
177 } catch (\RuntimeException $e) {
178 throw new WebhookException($e->getMessage());
179 }
180 }
181
182 public function setWebhook($type, \NitroPack\Url\Url $url) {
183 if (!in_array($type, $this->allowedWebhooks)) {
184 throw new WebhookException("The webhook type '$type' is not supported!");
185 }
186
187 if (!filter_var($url->getUrl(), FILTER_VALIDATE_URL)) {
188 throw new WebhookException(sprintf("The webhook URL '%s' is invalid!", $url->getUrl()));
189 }
190
191 try {
192 $this->webhook->set($type, $url->getUrl());
193 } catch (\RuntimeException $e) {
194 throw new WebhookException($e->getMessage());
195 }
196 }
197
198 public function getWebhook($type) {
199 if (!in_array($type, $this->allowedWebhooks)) {
200 throw new WebhookException("The webhook type '$type' is not supported!");
201 }
202
203 try {
204 $resp = $this->webhook->get($type);
205 return $resp["url"];
206 } catch (\RuntimeException $e) {
207 throw new WebhookException($e->getMessage());
208 }
209 }
210
211 public function setVariationCookie($name, $values = array(), $group = null) {
212 if (!is_array($values) && !is_string($values)) {
213 throw new VariationCookieException("The provided values is not an array or a string.");
214 } else if (is_array($values)) {
215 foreach ($values as $value) {
216 if (!is_string($value)) {
217 throw new VariationCookieException("A non-string cookie value has been detected.");
218 }
219 }
220 }
221
222 if (!is_string($name) || trim($name) == "") {
223 throw new VariationCookieException("The provided cookie name is not a string or is empty.");
224 }
225
226 if (null !== $group && !filter_var($group, FILTER_VALIDATE_INT)) {
227 throw new VariationCookieException("The provided group is not null, and it is not a positive integer.");
228 }
229
230 try {
231 return $this->variation_cookie->set($name, $values, $group);
232 } catch (\RuntimeException $e) {
233 throw new VariationCookieException($e->getMessage());
234 }
235 }
236
237 public function unsetVariationCookie($name) {
238 if (!is_string($name) || trim($name) == "") {
239 throw new VariationCookieException("The provided cookie name is not a string or is empty.");
240 }
241
242 try {
243 return $this->variation_cookie->delete($name);
244 } catch (\RuntimeException $e) {
245 throw new VariationCookieException($e->getMessage());
246 }
247 }
248
249 public function getVariationCookies() {
250 try {
251 return $this->variation_cookie->get();
252 } catch (\RuntimeException $e) {
253 throw new VariationCookieException($e->getMessage());
254 }
255 }
256
257 public function createWebsite(Website $website) {
258 return $this->integration->create($website);
259 }
260
261 public function updateWebsite(Website $website) {
262 return $this->integration->update($website);
263 }
264
265 public function removeWebsite($apikey) {
266 return $this->integration->remove($apikey);
267 }
268
269 // Get a single website via API key
270 public function getWebsiteByAPIKey($apikey) {
271 return $this->integration->readByAPIKey($apikey);
272 }
273
274 // Get all websites, along with a corresponding pagination
275 public function getWebsitesPaginated($page, $limit = 250) {
276 return $this->integration->readPaginated($page, $limit);
277 }
278
279 public function isSafeModeEnabled() {
280 $status = $this->safe_mode->status();
281 return !empty($status->isEnabled);
282 }
283
284 public function enableCartCache() {
285 $this->cache->enableCartCache();
286 }
287
288 public function disableCartCache() {
289 $this->cache->disableCartCache();
290 }
291
292 public function enableVarnishIntegration() {
293 $this->varnish->enable();
294 }
295
296 public function disableVarnishIntegration() {
297 $this->varnish->disable();
298 }
299
300 public function configureVarnishIntegration($settings) {
301 $this->varnish->configure($settings);
302 }
303
304 public function enableExcludedUrls()
305 {
306 $this->excludedurls->enable();
307 }
308
309 public function disableExcludedUrls()
310 {
311 $this->excludedurls->disable();
312 }
313
314 public function addExcludedUrl($urlPattern)
315 {
316 $this->excludedurls->add($urlPattern);
317 }
318
319 public function removeExcludedUrl($urlPattern)
320 {
321 $this->excludedurls->remove($urlPattern);
322 }
323
324 public function enableAdditionalDomains()
325 {
326 $this->additionaldomains->enable();
327 }
328
329 public function disableAdditionalDomains()
330 {
331 $this->additionaldomains->disable();
332 }
333
334 public function addAdditionalDomain($domain)
335 {
336 $this->additionaldomains->add($domain);
337 }
338
339 public function removeAdditionalDomain($domain)
340 {
341 $this->additionaldomains->remove($domain);
342 }
343 }
344