示例#1
0
 public function testClearCredentials()
 {
     $this->assertEquals('-', $this->api->getConsumerKey());
     $this->api->clearCredentials();
     $this->assertEquals(null, $this->api->getConsumerKey());
     $this->assertEquals(null, $this->api->getConsumerSecret());
     $this->assertEquals(null, $this->api->getAccessTokenKey());
     $this->assertEquals(null, $this->api->getAccessTokenSecret());
 }
示例#2
0
 /**
  * @param $apiResourceUrl
  * @return mixed
  * @throws \OAuthException
  * @todo Replace this Oauth class from the BuzzStream docs (https://api.buzzstream.com/docs/api_doc.html#auth) with a newer Oauth component that we can composer in.
  */
 protected function _request($apiResourceUrl)
 {
     $consumer_key = Api::getConsumerKey();
     $consumer_secret = Api::getConsumerSecret();
     $consumer = new \OAuthConsumer($consumer_key, $consumer_secret);
     $request = \OAuthRequest::from_consumer_and_token($consumer, NULL, "GET", $apiResourceUrl);
     $sig_method = new \OAuthSignatureMethod_HMAC_SHA1();
     $request->sign_request($sig_method, $consumer, NULL);
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $request->to_url());
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_HTTPHEADER, array($request->to_header()));
     $response = curl_exec($curl);
     curl_close($curl);
     $json_response = json_decode($response, true);
     if (!is_array($json_response)) {
         throw new \Exception("JSON response is not an array as expected");
     }
     if (isset($json_response['message'])) {
         throw new \Exception($json_response['message']);
     }
     return $json_response;
 }