Permalink
Browse files

MDL-34290 class oauth_helper, added API to pass options to curl (such…

… as timeout)
  • Loading branch information...
marinaglancy committed Jul 31, 2012
1 parent 26aaa7e commit 3af509d6d4dff37e7d602f0c1f7680bf292e2aa7
Showing with 15 additions and 3 deletions.
  1. +15 −3 lib/oauthlib.php
View
@@ -59,6 +59,8 @@ class oauth_helper {
protected $access_token_api;
/** @var curl */
protected $http;
+ /** @var array options to pass to the next curl request */
+ protected $http_options;
/**
* Contructor for oauth_helper.
@@ -106,6 +108,7 @@ function __construct($args) {
$this->access_token_secret = $args['access_token_secret'];
}
$this->http = new curl(array('debug'=>false));
+ $this->http_options = array();
}
/**
@@ -202,6 +205,15 @@ public function setup_oauth_http_header($params) {
$this->http->setHeader($str);
}
+ /**
+ * Sets the options for the next curl request
+ *
+ * @param array $options
+ */
+ public function setup_oauth_http_options($options) {
+ $this->http_options = $options;
+ }
+
/**
* Request token for authentication
* This is the first step to use OAuth, it will return oauth_token and oauth_token_secret
@@ -210,7 +222,7 @@ public function setup_oauth_http_header($params) {
public function request_token() {
$this->sign_secret = $this->consumer_secret.'&';
$params = $this->prepare_oauth_parameters($this->request_token_api, array(), 'GET');
- $content = $this->http->get($this->request_token_api, $params);
+ $content = $this->http->get($this->request_token_api, $params, $this->http_options);
// Including:
// oauth_token
// oauth_token_secret
@@ -252,7 +264,7 @@ public function get_access_token($token, $secret, $verifier='') {
$this->sign_secret = $this->consumer_secret.'&'.$secret;
$params = $this->prepare_oauth_parameters($this->access_token_api, array('oauth_token'=>$token, 'oauth_verifier'=>$verifier), 'POST');
$this->setup_oauth_http_header($params);
- $content = $this->http->post($this->access_token_api, $params);
+ $content = $this->http->post($this->access_token_api, $params, $this->http_options);
$keys = $this->parse_result($content);
$this->set_access_token($keys['oauth_token'], $keys['oauth_token_secret']);
return $keys;
@@ -276,7 +288,7 @@ public function request($method, $url, $params=array(), $token='', $secret='') {
$this->sign_secret = $this->consumer_secret.'&'.$secret;
$oauth_params = $this->prepare_oauth_parameters($url, array('oauth_token'=>$token), $method);
$this->setup_oauth_http_header($oauth_params);
- $content = call_user_func_array(array($this->http, strtolower($method)), array($url, $params));
+ $content = call_user_func_array(array($this->http, strtolower($method)), array($url, $params, $this->http_options));
return $content;
}

0 comments on commit 3af509d

Please sign in to comment.