public function send()
{
//Sign the request - this just sets the Authorization header
$this->app->getOAuthClient()->sign($this);
// configure curl
$ch = curl_init();
curl_setopt_array($ch, $this->app->getConfig('curl'));
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->getMethod());
if (isset($this->body)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->body);
}
//build header array. Don't provide glue so it'll return the array itself.
//Maybe could be a but cleaner but nice to reuse code.
$header_array = Helpers::flattenAssocArray($this->getHeaders(), '%s: %s');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header_array);
$full_uri = $this->getUrl()->getFullURL();
//build parameter array - the only time there's a post body is with the XML,
//only escape at this point
$query_string = Helpers::flattenAssocArray($this->getParameters(), '%s=%s', '&', true);
if (strlen($query_string) > 0) {
$full_uri .= "?{$query_string}";
}
curl_setopt($ch, CURLOPT_URL, $full_uri);
if ($this->method === self::METHOD_POST || $this->method === self::METHOD_PUT) {
curl_setopt($ch, CURLOPT_POST, true);
}
$response = curl_exec($ch);
$info = curl_getinfo($ch);
if ($response === false) {
throw new Exception('Curl error: ' . curl_error($ch));
}
$this->response = new Response($this, $response, $info);
$this->response->parse();
return $this->response;
}