Example #1
0
 /**
  * Create a new response instance
  *
  * @param  string $response
  * @param  Curl   $httpClient
  */
 public function __construct($response, Curl $httpClient)
 {
     $this->response = $response;
     $this->http_code = $httpClient->getHttpCode();
     if (is_string($response)) {
         $this->response = $this->decodeString($response);
     }
 }
Example #2
0
 /**
  * Execute the http request
  *
  * @param  string $method
  * @param  string $url
  * @param  array  $parameters
  * @param  array  $headers
  *
  * @return Response
  *
  * @throws ApiException|HttpResponseException
  */
 public function execute($method, $url, array $parameters = [], $headers = [])
 {
     // Execute request and catch response
     list($response_data, $response_headers) = $this->httpClient->execute($method, $url, $parameters, $headers);
     // Check if we have a valid response
     if ($this->httpClient->hasErrors()) {
         throw new ApiException($this->httpClient->getErrors(), $this->httpClient->getHttpCode());
     }
     // Initiate the response
     $response = new Response($response_data, $this->httpClient);
     // Check the response code
     if ($response->getResponseCode() >= 400) {
         if ($response->getResponseCode() === 400) {
             $this->throwValidationException($response);
         }
         throw new ApiException($response->message, $response->getResponseCode());
     }
     // Set headers for later inspection
     $this->headers = $response_headers;
     // Return the response
     return $response;
 }