Skip to content
Browse files

http info is now saved at $this->http_info including x-ratelimit info…

… thanks to @navarr, added a useragent and cleaned up some text.
  • Loading branch information...
1 parent 35fa109 commit 441e1fb5549e80c40d8f12838357994060550f45 @abraham abraham committed Dec 2, 2009
Showing with 32 additions and 10 deletions.
  1. +32 −10 twitteroauth/twitteroauth.php
View
42 twitteroauth/twitteroauth.php
@@ -17,22 +17,26 @@
* Twitter OAuth class
*/
class TwitterOAuth {
- /* Contains the last HTTP status code returned */
+ /* Contains the last HTTP status code returned. */
public $http_code;
- /* Contains the last API call */
- public $last_api_call;
- /* Set up the API root URL */
+ /* Contains the last API call. */
+ public $url;
+ /* Set up the API root URL. */
public $host = "https://api.twitter.com/1/";
- /* Set timeout default */
+ /* Set timeout default. */
public $timeout = 30;
- /* Set connect timeout */
+ /* Set connect timeout. */
public $connecttimeout = 30;
- /* Verify SSL Cert */
+ /* Verify SSL Cert. */
public $ssl_verifypeer = FALSE;
- /* Respons format */
+ /* Respons format. */
public $format = 'json';
- /* Decode returne json data */
+ /* Decode returned json data. */
public $decode_json = TRUE;
+ /* Contains the last HTTP headers returned. */
+ public $http_info;
+ /* Set the useragnet. */
+ public $useragent = 'TwitterOAuth v0.2.0-beta2';
/* Immediately retry the API call if the response was not successful. */
//public $retry = TRUE;
@@ -173,13 +177,17 @@ function oAuthRequest($url, $method, $parameters) {
* @return API results
*/
function http($url, $method, $postfields = NULL) {
+ $this->http_info = array();
$ci = curl_init();
/* Curl settings */
+ curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
+ curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
+ curl_setopt($ci, CURLOPT_HEADER, FALSE);
switch ($method) {
case 'POST':
@@ -198,8 +206,22 @@ function http($url, $method, $postfields = NULL) {
curl_setopt($ci, CURLOPT_URL, $url);
$response = curl_exec($ci);
$this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
- $this->last_api_call = $url;
+ $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
+ $this->url = $url;
curl_close ($ci);
return $response;
}
+
+ /**
+ * Get the header info to store.
+ */
+ function getHeader($ch, $header) {
+ $i = strpos($header, ':');
+ if (!empty($i)) {
+ $key = str_replace('-', '_', strtolower(substr($header, 0, $i)));
+ $value = trim(substr($header, $i + 2));
+ $this->http_header[$key] = $value;
+ }
+ return strlen($header);
+ }
}

0 comments on commit 441e1fb

Please sign in to comment.
Something went wrong with that request. Please try again.