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