You are here

protected function Twitter::request in Twitter 6.3

Same name and namespace in other branches
  1. 6.5 twitter.lib.php \Twitter::request()
  2. 7.6 twitter.lib.php \Twitter::request()
  3. 7.3 twitter.lib.php \Twitter::request()
  4. 7.5 twitter.lib.php \Twitter::request()

Perform a request

3 calls to Twitter::request()
Twitter::auth_request in ./twitter.lib.php
Perform an authentication required request.
Twitter::call in ./twitter.lib.php
Calls a twitter api resource
TwitterOAuth::auth_request in ./twitter.lib.php
Perform an authentication required request.

File

./twitter.lib.php, line 278
Classes to implement the full Twitter API

Class

Twitter
Primary Twitter API implementation class Supports the full REST API for twitter.

Code

protected function request($url, $params = array(), $method = 'GET', $use_auth = FALSE) {
  $data = '';
  if (count($params) > 0) {
    if ($method == 'GET') {
      $url .= '?' . http_build_query($params, '', '&');
    }
    else {
      $data = http_build_query($params, '', '&');
    }
  }
  $headers = array();
  if ($use_auth) {
    $headers['Authorization'] = 'Basic ' . base64_encode($this->username . ':' . $this->password);
    $headers['Content-type'] = 'application/x-www-form-urlencoded';
  }
  $response = drupal_http_request($url, $headers, $method, $data);
  if (!property_exists($response, 'error')) {
    return $response->data;
  }
  else {
    $error = $response->error;
    $data = $this
      ->parse_response($response->data);
    if ($data['error']) {
      $error = $data['error'];
    }
    throw new TwitterException($error);
  }
}