/** * pretty much a helper function to set up the request */ public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters = NULL) { /*{{{*/ @$parameters or $parameters = array(); $defaults = array("oauth_version" => doubanOAuthRequest::$version, "oauth_nonce" => doubanOAuthRequest::generate_nonce(), "oauth_timestamp" => doubanOAuthRequest::generate_timestamp(), "oauth_consumer_key" => $consumer->key); $parameters = array_merge($defaults, $parameters); if ($token) { $parameters['oauth_token'] = $token->key; } return new doubanOAuthRequest($http_method, $http_url, $parameters); }
/** * Format and sign an OAuth / API request */ function oAuthRequest($url, $args = array(), $method = NULL) { /*{{{*/ if (empty($method)) { $method = empty($args) ? "GET" : "POST"; } $req = doubanOAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $args); $req->sign_request($this->sha1_method, $this->consumer, $this->token); switch ($method) { case 'GET': return $this->http($req->to_url()); case 'POST': return $this->http($req->get_normalized_http_url(), $req->to_postdata()); } }