Exemple #1
0
 /**
  * Test the Account's getter methods.
  */
 public function testGetter()
 {
     $account = new Account('access-key', 'secret-key', 'api-host');
     $this->assertEquals('access-key', $account->getAccessKey());
     $this->assertEquals('secret-key', $account->getSecretKey());
     $this->assertEquals('api-host', $account->getApiHost());
 }
Exemple #2
0
 /**
  * {@inheritDoc}
  */
 protected function createHttpClient(Account $account, $cloudId)
 {
     $guzzleClient = new Client('https://' . $account->getApiHost() . '/v2');
     $httpClient = new HttpClient();
     $httpClient->setAccount($account);
     $httpClient->setCloudId($cloudId);
     $httpClient->setGuzzleClient($guzzleClient);
     return $httpClient;
 }
Exemple #3
0
 /**
  * Generates the signature for an API requests based on its parameters.
  *
  * @param string   $method The HTTP method
  * @param string   $path   The request path
  * @param string[] $params Request parameters
  *
  * @return string The generated signature
  */
 public function signature($method, $path, array $params = array())
 {
     $params = $this->completeParams($params);
     ksort($params);
     if (isset($params['file'])) {
         unset($params['file']);
     }
     $canonicalQueryString = str_replace(array('+', '%5B', '%5D'), array('%20', '[', ']'), http_build_query($params));
     $stringToSign = sprintf("%s\n%s\n%s\n%s", strtoupper($method), $this->account->getApiHost(), $path, $canonicalQueryString);
     $hmac = hash_hmac('sha256', $stringToSign, $this->account->getSecretKey(), true);
     return base64_encode($hmac);
 }