Created
March 7, 2014 08:43
-
-
Save haganbt/9407809 to your computer and use it in GitHub Desktop.
This file contains 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 | |
ini_set('memory_limit', '-1'); | |
define('DATASIFT_USERNAME', '<DS_USERNAME>'); | |
define('DATASIFT_APIKEY', '<DS_API_KEY>'); | |
$csdl = file_get_contents('<MY_CSDL_FILE>'); | |
compile(trim($csdl)); | |
function compile($csdl) { | |
$url = 'https://api.datasift.com/v1/compile?username=' . DATASIFT_USERNAME . '&api_key=' . DATASIFT_APIKEY ; | |
$ch = curl_init(); | |
$post_body = urlencode ($csdl) ; | |
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch,CURLOPT_URL, $url); | |
curl_setopt($ch,CURLOPT_POST, 1); | |
curl_setopt($ch,CURLOPT_POSTFIELDS, 'csdl='.$post_body); | |
curl_setopt($ch,CURLOPT_HTTPHEADER, array('Content-Type : application/x-www-form-urlencoded')); | |
$result = curl_exec($ch); | |
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
if($http_status !== 200){ | |
echo "\n\nERROR - Response code: " . $http_status . "\n" . $result; | |
exit; | |
} | |
curl_close($ch); | |
$json = json_decode($result, true); | |
echo $result . "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment