public function TwitterAPIExchange::performRequest in Heartbeat 8
Perform the actual data retrieval from the API
Parameters
boolean $return If true, returns data. This is left in for backward compatibility reasons:
array $curlOptions Additional Curl options for this request:
Return value
string json If $return param is true, returns json data.
Throws
\Exception
File
- modules/
statusmessage/ includes/ TwitterAPIExchange.php, line 274
Class
- TwitterAPIExchange
- Twitter-API-PHP : Simple PHP wrapper for the v1.1 API
Code
public function performRequest($return = true, $curlOptions = array()) {
if (!is_bool($return)) {
throw new Exception('performRequest parameter must be true or false');
}
$header = array(
$this
->buildAuthorizationHeader($this->oauth),
'Expect:',
);
$getfield = $this
->getGetfield();
$postfields = $this
->getPostfields();
if (in_array(strtolower($this->requestMethod), array(
'put',
'delete',
))) {
$curlOptions[CURLOPT_CUSTOMREQUEST] = $this->requestMethod;
}
$options = $curlOptions + array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_HEADER => false,
CURLOPT_URL => $this->url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
);
if (!is_null($postfields)) {
$options[CURLOPT_POSTFIELDS] = http_build_query($postfields, '', '&');
}
else {
if ($getfield !== '') {
$options[CURLOPT_URL] .= $getfield;
}
}
$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
$this->httpStatusCode = curl_getinfo($feed, CURLINFO_HTTP_CODE);
if (($error = curl_error($feed)) !== '') {
curl_close($feed);
throw new \Exception($error);
}
curl_close($feed);
return $json;
}