Ejemplo n.º 1
0
 public function testAuthorization()
 {
     $agency_id = mt_rand();
     $public_key = mt_rand();
     $secret_key = mt_rand();
     $authorization = new Authorization($agency_id, $public_key, $secret_key);
     $client = $this->getMock('Goutte\\Client');
     $client->expects($this->at(0))->method('request')->with($this->equalTo('GET'), $this->equalTo('http://example.com'), $this->equalTo(array()), $this->equalTo(array()), $this->equalTo(array('HTTP_Auth' => $authorization->toHTTPHeader(), 'HTTP_Content_Type' => 'application/vnd.bpi.api+xml')))->will($this->returnValue(new Crawler(file_get_contents(__DIR__ . '/Fixtures/Node.bpi'))));
     $client->expects($this->once())->method('getResponse')->will($this->returnValue(new Response()));
     $doc = new Document($client, $authorization);
     $doc->loadEndpoint('http://example.com');
 }
Ejemplo n.º 2
0
 /**
  * Gateway to make direct requests to API
  *
  * @param string $method
  * @param string $uri
  * @param array $params
  *
  * @return \Bpi\Sdk\Document same instance
  */
 public function request($method, $uri, array $params = array())
 {
     $headers = array('HTTP_Auth' => $this->authorization->toHTTPHeader(), 'HTTP_Content_Type' => 'application/vnd.bpi.api+xml');
     $this->crawler = $this->http_client->request($method, $uri, $params, array(), $headers);
     $this->crawler = $this->crawler->filter('bpi > item');
     $this->crawler->rewind();
     if ($this->status()->isError()) {
         if ($this->status()->isClientError()) {
             throw new Exception\HTTP\ClientError($this->http_client->getResponse()->getContent(), $this->status()->getCode());
         }
         if ($this->status()->isServerError()) {
             throw new Exception\HTTP\ServerError($this->http_client->getResponse()->getContent(), $this->status()->getCode());
         }
         throw new Exception\HTTP\Error($this->http_client->getResponse()->getContent(), $this->status()->getCode());
     }
     return $this;
 }