Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function getLatestResponseHeaders()
 {
     if (null === ($response = $this->browser->getLastResponse())) {
         return;
     }
     return ['reset' => (int) $response->getHeader('RateLimit-Reset'), 'remaining' => (int) $response->getHeader('RateLimit-Remaining'), 'limit' => (int) $response->getHeader('RateLimit-Limit')];
 }
 protected function getResponseStatus()
 {
     $headers = $this->browser->getLastResponse()->getHeaders();
     foreach ($headers as $header) {
         if (substr($header, 0, 6) == 'Status') {
             return (int) substr($header, 8, 3);
         }
     }
 }
Exemple #3
0
 public function getLastResponse()
 {
     if ($this->fromCache) {
         return $this->data['response'];
     }
     return parent::getLastResponse();
 }
 /**
  * Common delete request for all API calls
  *
  * @param string $resource The path to the resource wanted. For example v2/room
  *
  * @return array Decoded array containing response
  * @throws Exception\RequestException
  */
 public function delete($resource)
 {
     $url = $this->baseUrl . $resource;
     $headers = array('Authorization' => $this->auth->getCredential());
     $response = $this->browser->delete($url, $headers);
     if ($this->browser->getLastResponse()->getStatusCode() > 299) {
         throw new RequestException(json_decode($this->browser->getLastResponse()->getContent(), true));
     }
     return json_decode($response->getContent(), true);
 }
 /**
  * @When /^I submit "([^"]*)" data to "([^"]*)"$/
  * @param  string     $pageUrl
  * @return void
  * @throws \Exception
  */
 public function iSubmitDataTo($dataKey, $pageUrl)
 {
     $this->responseData = $this->responseDecodeException = null;
     $this->responseIsJson = false;
     if ($this->access_token) {
         $this->headers['Authorization'] = 'Bearer ' . $this->access_token;
     }
     $this->client->submit($this->processPageUrl($pageUrl), array($dataKey => $this->collectedData[$dataKey]), strtolower($this->requestMethod), $this->headers);
     $this->response = $this->client->getLastResponse();
 }
 public function put($resource, $content)
 {
     $curl = new Curl();
     $browser = new Browser($curl);
     $url = $this->baseUrl . $resource;
     $headers = array('Content-Type' => 'application/json', 'Authorization' => $this->auth->getCredential());
     $response = $browser->put($url, $headers, json_encode($content));
     if ($browser->getLastResponse()->getStatusCode() > 299) {
         throw new BadRequestException($response);
     }
     return json_decode($response->getContent(), true);
 }
 /**
  * @Then /^echo last response$/
  *
  * Echos the last response for debugging purposes
  * -
  * Example:
  * And echo last response
  */
 public function echoLastResponse()
 {
     $response = $this->client->getLastResponse();
     $headerString = '';
     foreach ($response->getHeaders() as $header) {
         $headerString = sprintf("%s%s\n", $headerString, $header);
     }
     echo rtrim($headerString, "\n");
     if (empty($response->getContent()) === false) {
         echo sprintf("\nContent: %s", $response->getContent());
     }
 }
 /**
  * Checks that response body contains JSON from PyString.
  *
  * @param PyStringNode $jsonString
  *
  * @Then /^(?:the )?response should contain json:$/
  */
 public function theResponseShouldContainJson(PyStringNode $jsonString)
 {
     $etalon = json_decode($this->replacePlaceHolder($jsonString->getRaw()), true);
     $actual = json_decode($this->browser->getLastResponse()->getContent(), true);
     if (null === $etalon) {
         throw new \RuntimeException("Can not convert etalon to json:\n" . $this->replacePlaceHolder($jsonString->getRaw()));
     }
     assertCount(count($etalon), $actual);
     foreach ($actual as $key => $needle) {
         assertArrayHasKey($key, $etalon);
         assertEquals($etalon[$key], $actual[$key]);
     }
 }
 /**
  * Base method for the api requests of library.
  *
  * @param string   $request The request that can be 'get', 'post', 'put', 'patch' and 'delete'
  * @param string   $method  The api method
  * @param array    $query   QueryString that filters the response
  * @param string[] $content The content that contains the payload of the the request
  *
  * @throws Error when the status code is higher than 226. According to the Wikipedia:
  *               http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#2xx_Success
  *
  * @return mixed Decoded array containing response
  */
 private function baseRequest($request, $method, $query = [], $content = [])
 {
     $curl = new Curl();
     $browser = new Browser($curl);
     $url = $this->baseUrl . '/' . $this->version . $method;
     if (count($query) > 0) {
         $url .= '?';
     }
     foreach ($query as $key => $value) {
         $url .= $key . '=' . $value . '&';
     }
     if ($this->authentication === null) {
         $response = $browser->{$request}($url, $this->headers);
     } elseif (count($content) === 0) {
         $response = $browser->{$request}($url . $this->authentication->getAuthAsString());
     } else {
         $response = $browser->{$request}($url, $this->headers, array_merge($content, $this->authentication->getAuth()));
     }
     if ($browser->getLastResponse()->getStatusCode() > 226) {
         throw new Error(json_decode(gzdecode($browser->getLastResponse()->getContent()), true));
     }
     return json_decode(gzdecode($response->getContent()), true);
 }