1 | <?php |
||
20 | final class RetrofitResponse implements Response |
||
21 | { |
||
22 | /** |
||
23 | * The PSR-7 response |
||
24 | * |
||
25 | * @var ResponseInterface |
||
26 | */ |
||
27 | private $response; |
||
28 | |||
29 | /** |
||
30 | * Converted body on success |
||
31 | * |
||
32 | * @var mixed |
||
33 | */ |
||
34 | private $body; |
||
35 | |||
36 | /** |
||
37 | * Converted body on failure |
||
38 | * |
||
39 | * @var mixed |
||
40 | */ |
||
41 | private $errorBody; |
||
42 | |||
43 | /** |
||
44 | * Constructor |
||
45 | * |
||
46 | * @param ResponseInterface $response |
||
47 | * @param mixed $body |
||
48 | * @param mixed $errorBody |
||
49 | */ |
||
50 | 16 | public function __construct(ResponseInterface $response, $body, $errorBody) |
|
56 | |||
57 | /** |
||
58 | * Get the raw PSR-7 response |
||
59 | * |
||
60 | * @return ResponseInterface |
||
61 | */ |
||
62 | 6 | public function raw(): ResponseInterface |
|
66 | |||
67 | /** |
||
68 | * Get the response status code |
||
69 | * |
||
70 | * @return int |
||
71 | */ |
||
72 | 2 | public function code(): int |
|
76 | |||
77 | /** |
||
78 | * Get the response message |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | 2 | public function message(): string |
|
86 | |||
87 | /** |
||
88 | * Get response headers |
||
89 | * |
||
90 | * @return array |
||
91 | */ |
||
92 | 2 | public function headers(): array |
|
96 | |||
97 | /** |
||
98 | * Returns true if the response was successful |
||
99 | * |
||
100 | * @return bool |
||
101 | */ |
||
102 | 2 | public function isSuccessful(): bool |
|
106 | |||
107 | /** |
||
108 | * Get converted body |
||
109 | * |
||
110 | * @return mixed |
||
111 | */ |
||
112 | 7 | public function body() |
|
116 | |||
117 | /** |
||
118 | * Get converted body on errors |
||
119 | * |
||
120 | * @return mixed |
||
121 | */ |
||
122 | 6 | public function errorBody() |
|
126 | } |
||
127 |