Exemplo n.º 1
0
 /**
  * Retrieves a resource information.
  *
  * @param  string $resource The name of the resource. Should be a key in $resources.
  * @return array
  * @throws InvalidArgumentException If the requested resource is not in the list of valid ones.
  */
 public function get($resource)
 {
     if (!isset($this->resources[$resource])) {
         throw new InvalidArgumentException('The requested resource is not in the list');
     }
     return ResponseMediator::getContent($this->client->get($this->resources[$resource]));
 }
Exemplo n.º 2
0
 /**
  * @return Guzzle\Http\Message\Response
  */
 public function getLastResponse($force = false)
 {
     $lastResponse = parent::getLastResponse();
     if (304 != $lastResponse->getStatusCode()) {
         $force = true;
     }
     return $force ? $lastResponse : $this->lastCachedResponse;
 }
 /**
  * Create requests with If-Modified-Since headers
  *
  * {@inheritdoc}
  */
 protected function createRequest($httpMethod, $url)
 {
     $request = parent::createRequest($httpMethod, $url);
     if ($modifiedAt = $this->getCache()->getModifiedSince($url)) {
         $modifiedAt = new \DateTime('@' . $modifiedAt);
         $modifiedAt->setTimezone(new \DateTimeZone('GMT'));
         $request->addHeader(sprintf('If-Modified-Since: %s GMT', $modifiedAt->format('l, d-M-y H:i:s')));
     }
     return $request;
 }
Exemplo n.º 4
0
 /**
  * Create requests with If-Modified-Since headers
  *
  * {@inheritdoc}
  */
 protected function createRequest($httpMethod, $path, $body = null, array $headers = array(), array $options = array())
 {
     $request = parent::createRequest($httpMethod, $path, $body, $headers = array(), $options);
     if ($modifiedAt = $this->getCache()->getModifiedSince($path)) {
         $modifiedAt = new \DateTime('@' . $modifiedAt);
         $modifiedAt->setTimezone(new \DateTimeZone('GMT'));
         $request->addHeader('If-Modified-Since', sprintf('%s GMT', $modifiedAt->format('l, d-M-y H:i:s')));
     }
     if ($etag = $this->getCache()->getETag($path)) {
         $request->addHeader('If-None-Match', $etag);
     }
     return $request;
 }
 /**
  * @test
  */
 public function shouldHandlePagination()
 {
     $path = '/some/path';
     $parameters = array('a' => 'b');
     $headers = array('c' => 'd');
     $response = new Response();
     $response->addHeader("Link:<page1>; rel=\"page2\", \n<page3>; rel=\"page4\"");
     $client = $this->getBrowserMock();
     $httpClient = new HttpClient(array(), $client);
     $httpClient->request($path, $parameters, 'HEAD', $headers);
     $this->assertEquals(array('page2' => 'page1', 'page4' => 'page3'), $response->getPagination());
 }
Exemplo n.º 6
0
 /**
  * @test
  */
 public function shouldHandlePagination()
 {
     $path = '/some/path';
     $body = 'a = b';
     $headers = array('c' => 'd');
     $response = new Response(200);
     $response->addHeader('Link', "<page1>; rel=\"page2\", \n<page3>; rel=\"page4\"");
     $client = $this->getBrowserMock();
     $httpClient = new HttpClient(array(), $client);
     $httpClient->request($path, $body, 'HEAD', $headers);
     $this->assertEquals(array('page2' => 'page1', 'page4' => 'page3'), ResponseMediator::getPagination($response));
 }
Exemplo n.º 7
0
 /**
  * @param array $headers
  */
 public function setHeaders(array $headers)
 {
     $this->httpClient->setHeaders($headers);
 }