Overview

Namespaces

  • PipelinerSales
    • ApiClient
      • Http
      • Query
      • Repository
        • Rest

Classes

  • CreatedResponse
  • CurlHttpClient
  • Response

Interfaces

  • HttpInterface

Exceptions

  • PipelinerHttpException
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * This file is part of the Pipeliner API client library for PHP
 4:  *
 5:  * Copyright 2014 Pipelinersales, Inc. All Rights Reserved.
 6:  * For the full license information, see the attached LICENSE file.
 7:  */
 8: 
 9: namespace PipelinerSales\ApiClient\Http;
10: 
11: /**
12:  * Represents a HTTP response.
13:  */
14: class Response
15: {
16: 
17:     private $body;
18:     private $headers;
19:     private $statusCode;
20:     private $requestMethod;
21:     private $requestUrl;
22: 
23:     public function __construct($body, $headers, $statusCode, $requestUrl, $requestMethod)
24:     {
25:         $this->body = $body;
26:         $this->headers = $headers;
27:         $this->statusCode = $statusCode;
28:         $this->requestUrl = $requestUrl;
29:         $this->requestMethod = $requestMethod;
30:     }
31: 
32:     /**
33:      * @return string
34:      */
35:     public function getBody()
36:     {
37:         return $this->body;
38:     }
39: 
40:     /**
41:      * Returns the raw headers of the response in a single string
42:      * @return string
43:      */
44:     public function getHeaders()
45:     {
46:         return $this->headers;
47:     }
48: 
49:     public function getStatusCode()
50:     {
51:         return $this->statusCode;
52:     }
53: 
54:     public function getRequestMethod()
55:     {
56:         return $this->requestMethod;
57:     }
58: 
59:     public function getRequestUrl()
60:     {
61:         return $this->requestUrl;
62:     }
63: 
64:     /**
65:      * Decodes the response's body into an object.
66:      * @param boolean $assoc when true, returned objects will be converted into associative arrays.
67:      * @return \stdClass|array
68:      * @throws PipelinerHttpException on error while decoding the json string
69:      */
70:     public function decodeJson($assoc = false)
71:     {
72:         $result = json_decode($this->body, $assoc);
73: 
74:         if (json_last_error() !== JSON_ERROR_NONE) {
75:             throw new PipelinerHttpException($this, "Error while parsing returned JSON");
76:         }
77: 
78:         return $result;
79:     }
80: }
81: 
API documentation generated by ApiGen