public function make()
{
$ch = curl_init();
$options = [CURLOPT_URL => $this->getUrl(), CURLOPT_RETURNTRANSFER => true, CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_TIMEOUT => 60, CURLOPT_USERAGENT => 'Fuss/' . self::AGENT_VERSION];
if ($this->getMethod() === 'POST') {
$options[CURLOPT_POST] = true;
if ($this->body !== null) {
$body = $this->body;
// @see http://stackoverflow.com/a/7979981/368691
foreach ($body as $k => $v) {
if (is_array($v)) {
$body[$k] = json_encode($v);
}
}
$options[CURLOPT_POSTFIELDS] = $body;
}
}
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
if ($result === false) {
throw new Exception\RequestException('[' . curl_errno($ch) . '] ' . curl_error($ch));
}
curl_close($ch);
$json = json_decode($result, true);
if (json_last_error() == JSON_ERROR_NONE) {
$result = $json;
} else {
// The "oauth/access_token" endpoint will return string encoded data:
// "access_token=CAALpZBF9favMBALi6KuwmoXXo3gEoZCAKniV5xzdwZAUjCNZCZB0NyfZC76BcZCvLqcJyTWBwzj44VNep38uwiXiZBg7VJxwZAxE2uc9ORZA3ZCYbtMtddPdsTDUEtvCA7iAM0EFsmZBynTwZCw7a0mUBUuAddA3Es36p78VJrswdlvhpArVe2VWz14vO&expires=5184000"
parse_str($result, $result);
}
if (isset($result['error'])) {
throw new Exception\RequestException('[' . $result['error']['type'] . '] ' . $result['error']['message'], empty($result['error']['code']) ? null : $result['error']['code']);
}
return $result;
}