/**
  * Perform a request (via GuzzleClient)
  * @todo   convert to WP http API
  *
  * @since  0.2.3
  *
  * @param  string           $uri   URI to request
  * @param  TokenCredentials $creds Request method. Defaults to GET
  * @param  array            $args  Array of data to send in request.
  *
  * @return array                   Array of response data, or WP_Error
  */
 public function request($uri, TokenCredentials $creds, $args = array())
 {
     $args = wp_parse_args($args, array('request_args' => array(), 'options' => array(), 'method' => 'GET'));
     $headers = $this->getHeaders($creds, $args['method'], $uri, $args['request_args']);
     $this->get_response($uri, array('method' => $args['method'], 'headers' => $headers, 'request_args' => $args['request_args'], 'options' => $args['options']));
     $this->response_code = $this->response->getStatusCode();
     $headers = array();
     foreach ($this->response->getHeaders() as $header) {
         $headers[strtolower($header->getName())] = (string) $header;
     }
     $request_response = array('headers' => $headers, 'body' => $this->response->getBody(true), 'response' => array('code' => $this->response_code, 'message' => $this->response->getReasonPhrase()));
     return $request_response;
 }
Ejemplo n.º 2
0
 /**
  * @Then /^the response status code should be (\d+)$/
  * @param int $httpStatus
  * @return void
  * @throws \Exception
  */
 public function theResponseStatusCodeShouldBe($httpStatus)
 {
     if ((string) $this->response->getStatusCode() !== $httpStatus) {
         throw new \Exception(sprintf('HTTP code does not match %s (actual: %s)', $httpStatus, $this->response->getStatusCode()));
     }
 }