Last active
October 31, 2016 00:19
-
-
Save jonathan-bird/90b5f555ccc74f3eec5dc2e25d9411ac to your computer and use it in GitHub Desktop.
Imgix API Image Purge with Guzzle 5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Guzzle\Http\Client; | |
use Guzzle\Http\Exception\ClientErrorResponseException; | |
private function purgeImgixCache($imageUrl) | |
{ | |
$client = new Client(); | |
try { | |
$request = $client->post('https://api.imgix.com/v2/image/purger', | |
[ | |
'Content-Type' => 'application/json', | |
'Authorization' => 'Basic ' . base64_encode('THIS_IS_API_KEY_STRING' . ':') | |
], | |
[ | |
'url' => $imageUrl | |
] | |
); | |
$response = $request->send(); | |
} catch (ClientErrorResponseException $exception) { | |
$responseBody = $exception->getResponse()->getBody(true); | |
return false; | |
} | |
return $response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment