Skip to content

Instantly share code, notes, and snippets.

@whatnickcodes
Created November 30, 2012 22:31
Show Gist options
  • Save whatnickcodes/4179175 to your computer and use it in GitHub Desktop.
Save whatnickcodes/4179175 to your computer and use it in GitHub Desktop.
curlk
private function curl($uri, $body = NULL, $verb = 'GET')
{
$url = (preg_match('#^www|^http|^//#', $uri)) ? $uri : $this->api_url.$uri.'?access_token='.$this->access_token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if (!is_null($body))
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
switch ($verb)
{
case 'POST' :
curl_setopt($ch, CURLOPT_POST, 1);
break;
case 'PATCH' :
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
break;
case 'PUT' :
curl_setopt($ch, CURLOPT_PUT, 1);
break;
case 'DELETE' :
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
break;
default :
break;
}
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
$output = curl_exec($ch);
curl_close($ch);
//add $this->_error handling for [message], 404, or whatever
return json_decode($output);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment