public function testUnsetParameter() { $request = new OAuthRequest('', ''); $this->assertEquals(NULL, $request->get_parameter('test')); $request->set_parameter('test', 'foo'); $this->assertEquals('foo', $request->get_parameter('test')); $request->unset_parameter('test'); $this->assertEquals(NULL, $request->get_parameter('test'), 'Failed to unset parameter'); }
/** * Sign the request using OAuth. This uses the consumer token and key * but 2 legged oauth doesn't require an access token and key. In situations where you want to * do a 'reverse phone home' (aka: gadget does a makeRequest to your server * and your server wants to retrieve more social information) this is the prefered * method. * * @param string $method the method (get/put/delete/post) * @param string $url the url to sign (http://site/social/rest/people/1/@me) * @param array $params the params that should be appended to the url (count=20 fields=foo, etc) * @param string $postBody for POST/PUT requests, the postBody is included in the signature * @return string the signed url */ public function sign($method, $url, $params = array(), $postBody = false, &$headers = array()) { $oauthRequest = new OAuthRequest($method, $url, $params); $params = $this->mergeParameters($params); foreach ($params as $key => $val) { if (is_array($val)) { $val = implode(',', $val); } $oauthRequest->set_parameter($key, $val); } if ($postBody && strlen($postBody)) { if ($this->useBodyHash) { $bodyHash = base64_encode(sha1($postBody, true)); $oauthRequest->set_parameter("oauth_body_hash", $bodyHash); } if ($this->useBodyHack) { $oauthRequest->set_parameter($postBody, ''); } } $oauthRequest->sign_request($this->signatureMethod, $this->consumerToken, $this->accessToken); if ($postBody && $this->useBodyHack) { unset($oauthRequest->parameters[$postBody]); } $signedUrl = $oauthRequest->to_url(); return $signedUrl; }