| 1 |
<?php |
| 2 |
|
| 3 |
namespace BerqWP; |
| 4 |
use GuzzleHttp\Exception\RequestException; |
| 5 |
|
| 6 |
class CriticalCSS { |
| 7 |
protected $client = null; |
| 8 |
protected $license_key = null; |
| 9 |
|
| 10 |
function __construct($client, $license_key) { |
| 11 |
$this->client = $client; |
| 12 |
$this->license_key = $license_key; |
| 13 |
} |
| 14 |
|
| 15 |
function purge_url($page_url) { |
| 16 |
$post_data = ['page_url' => $page_url, 'license_key' => $this->license_key]; |
| 17 |
|
| 18 |
try { |
| 19 |
|
| 20 |
$response = $this->client->post('critical-css/flush-page', [ |
| 21 |
'form_params' => $post_data |
| 22 |
]); |
| 23 |
|
| 24 |
if ($response->getStatusCode() === 200) { |
| 25 |
return true; |
| 26 |
} |
| 27 |
|
| 28 |
} catch (RequestException $e) {} catch (\Throwable $e) {} |
| 29 |
|
| 30 |
|
| 31 |
return false; |
| 32 |
} |
| 33 |
|
| 34 |
function purge_all($domain) { |
| 35 |
$post_data = ['domain' => $domain, 'license_key' => $this->license_key]; |
| 36 |
|
| 37 |
try { |
| 38 |
|
| 39 |
$response = $this->client->post('critical-css/flush-all', [ |
| 40 |
'form_params' => $post_data |
| 41 |
]); |
| 42 |
|
| 43 |
if ($response->getStatusCode() === 200) { |
| 44 |
return true; |
| 45 |
} |
| 46 |
|
| 47 |
} catch (RequestException $e) {} catch (\Throwable $e) {} |
| 48 |
|
| 49 |
return false; |
| 50 |
} |
| 51 |
} |
| 52 |
|