Skip to content

Instantly share code, notes, and snippets.

@cecekpawon
Last active August 29, 2015 14:27
Show Gist options
  • Save cecekpawon/3747c820ba9b987d766e to your computer and use it in GitHub Desktop.
Save cecekpawon/3747c820ba9b987d766e to your computer and use it in GitHub Desktop.
<?php
/*
Clear Cloudflare cache API
@cecekpawon - Fri Aug 14 10:16:39 2015
*/
class cloudflare_yod {
private $api = "https://www.cloudflare.com/api_json.html";
private $params = array("tkn"=>"", "email"=>"", "z"=>"");
private $token;
private $email;
public function __construct()
{
$params = func_get_args();
foreach ($params[0] as $key => $value) {
if (array_key_exists($key, $this->params) && $value) {
$this->params[$key] = $value;
}
}
}
private function seek($fields=array())
{
$fields = array_merge($this->params, $fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->api);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
//$info = curl_getinfo($ch);
curl_close($ch);
return json_decode($result, true);
}
public function purge_file($url)
{
return $this->seek(
array(
"a" => "zone_file_purge",
"url" => $url
)
);
}
public function purge_all()
{
return $this->seek(
array(
"a" => "fpurge_ts",
"v" => 1
)
);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment