<?php
//function for making cURL requests function curl($url,$method,$data){
//cURL call $ch = curl_init();
if($method){ curl_setopt ($ch, CURLOPT_POST, true); if($data){ curl_setopt ($ch, CURLOPT_POSTFIELDS, $data); } }
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-API-TOKEN: YOUR-API-TOKEN"));
$output = curl_exec($ch);
if($output !== false || curl_error($ch)) {
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE); return array($status,$output);
curl_close($ch); }
}
//list of known variables $site_id = 130; $campaign_id = 159;
//call the discovery page $discovery = "http://admin1.sitespect.com/api"";
//Find the cachepurge resource URI from the discovery page, parse the URI template and create the cache purge job, and print the cache purge job resource on the screen $request = curl($discovery);
if ($request[0] == 200){ $json = json_decode($request[1],true);
$siteidentities = $json['_links']['siteidentities']["href"];
//URI Template parsing using a simple str_replace function instead of a URI Template parsing library $cachepurge = str_replace('{site-id}', $site_id, $cachepurge); $cachepurge = str_replace('{siteidentity-id}', $campaign_id, $cachepurge);
}
if($cachepurge){ $request = curl($cachepurge,"POST"," "); //POST request
//we expect to get a created cache purge job, meaning status code 201 if($request[0] == 201){ $json = json_decode($request[1],true);
//print the cache purge job URL on the screen echo $json['_links']['self']["href"];
}
}
?>
|