Exemple #1
0
 public function testEmptyRequestURIArrayQueryString()
 {
     $url = URL::build('http://example.com', null, array('key' => 'value'));
     $this->assertSame('http://example.com/?key=value', $url);
 }
 /**
  * Fetches a signed API resource
  *
  * @param string $method Request method
  * @param string $resource Resource URI
  * @param string|array $data Request payload/query string
  *
  * @return string
  *
  * @throws Exception\InvalidMethod
  * @throws Exception\InvalidFormat
  * @throws Exception\InvalidResponse
  * @throws Exception\APIError
  * @throws \Veridu\Signature\Exception\NonceMismatch
  */
 protected function signedFetch($method, $resource, array $data = null)
 {
     $sign = $this->signature->sign($this->key, $this->secret, $this->version, $method, URL::build(self::BASE_URL, array($this->version, $resource)));
     if (empty($data)) {
         $json = $this->fetch($method, $resource, $sign);
     } else {
         $json = $this->fetch($method, $resource, array_merge($data, $sign));
     }
     if (empty($json['nonce']) || strcmp($json['nonce'], $this->signature->lastNonce()) != 0) {
         throw new \Veridu\Signature\Exception\NonceMismatch();
     }
     unset($json['nonce']);
     return $json;
 }