Example #1
0
 /**
  * Execute the request and return a response.
  *
  * @param   string   request type: GET, POST, etc (NULL for header)
  * @param   array    additional cURL options
  * @return  string   request response body
  * @uses    OAuth_Request::check
  * @uses    Arr::get
  * @uses    Remote::get
  */
 public function execute(array $options = NULL)
 {
     // Check that all required fields are set
     $this->check();
     // Get the URL of the request
     $url = $this->url;
     if (!isset($options[CURLOPT_CONNECTTIMEOUT])) {
         // Use the request default timeout
         $options[CURLOPT_CONNECTTIMEOUT] = $this->timeout;
     }
     if ($this->send_header) {
         // Get the the current headers
         $headers = Arr::get($options, CURLOPT_HTTPHEADER, array());
         // Add the Authorization header
         $headers[] = 'Authorization: ' . $this->as_header();
         // Store the new headers
         $options[CURLOPT_HTTPHEADER] = $headers;
     } elseif ($query = $this->as_query()) {
         // Append the parameters to the query string
         $url = "{$url}?{$query}";
     }
     if ($this->method === 'POST') {
         // Send the request as a POST
         $options[CURLOPT_POST] = TRUE;
         if ($this->post) {
             // Attach the post fields to the request
             $options[CURLOPT_POSTFIELDS] = OAuth::normalize_post($this->post);
         }
     }
     return Remote::get($url, $options);
 }