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