private function doOAuthCall($url, array $parameters = null, $method = 'POST', $expectJSON = true)
{
// redefine
$url = (string) $url;
// append default parameters
$parameters['oauth_consumer_key'] = $this->getApplicationKey();
$parameters['oauth_signature_method'] = 'PLAINTEXT';
$parameters['oauth_version'] = '1.0';
$parameters['oauth_signature'] = $this->getApplicationSecret() . '&' . $this->getOAuthTokenSecret();
if ($method == 'POST') {
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = $parameters;
} else {
// reset post
$options[CURLOPT_POST] = 0;
unset($options[CURLOPT_POSTFIELDS]);
// add the parameters into the querystring
if (!empty($parameters)) {
$url .= '?' . $this->buildQuery($parameters);
}
}
// set options
$options[CURLOPT_URL] = self::API_URL . '/' . $url;
$options[CURLOPT_PORT] = self::API_PORT;
$options[CURLOPT_USERAGENT] = $this->getUserAgent();
if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {
$options[CURLOPT_FOLLOWLOCATION] = true;
}
$options[CURLOPT_RETURNTRANSFER] = true;
$options[CURLOPT_TIMEOUT] = (int) $this->getTimeOut();
$options[CURLOPT_SSL_VERIFYPEER] = false;
$options[CURLOPT_SSL_VERIFYHOST] = false;
$options[CURLOPT_HTTPHEADER] = array('Expect:');
// init
$this->curl = curl_init();
// set options
curl_setopt_array($this->curl, $options);
// execute
$response = curl_exec($this->curl);
$headers = curl_getinfo($this->curl);
// fetch errors
$errorNumber = curl_errno($this->curl);
$errorMessage = curl_error($this->curl);
// error?
if ($errorNumber != '') {
throw new Exception($errorMessage, $errorNumber);
}
// return
if ($expectJSON) {
return json_decode($response, true);
}
// fallback
return $response;
}