1 | <?php |
||
13 | abstract class AbstractAPI |
||
14 | { |
||
15 | /** |
||
16 | * @var Client |
||
17 | */ |
||
18 | protected $_client; |
||
19 | |||
20 | /** |
||
21 | * @var GuzzleHttp\Client |
||
22 | */ |
||
23 | protected $_httpClient; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $url; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $endpoint; |
||
34 | |||
35 | /** |
||
36 | * @var GuzzleHttp\Query |
||
37 | */ |
||
38 | protected $query; |
||
39 | |||
40 | /** |
||
41 | * @var GuzzleHttp\Message\ResponseInterface |
||
42 | */ |
||
43 | protected $response; |
||
44 | |||
45 | /** |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $headers = [ |
||
49 | 'Content-Type' => 'application/json; charset=utf-8', |
||
50 | 'Cache-Control' => 'no-cache', |
||
51 | ]; |
||
52 | |||
53 | /** |
||
54 | * AbstractAPI constructor. |
||
55 | * @param $endpoint |
||
56 | * @param Client|null $client |
||
57 | */ |
||
58 | protected function __construct($endpoint, Client $client = null) |
||
95 | |||
96 | /** |
||
97 | * Adiciona parâmetros mantendo os já inicializados como padrão |
||
98 | * |
||
99 | * @param array $params |
||
100 | * @return string |
||
101 | */ |
||
102 | protected function addQueryAdditionalParameters(array $params) |
||
114 | |||
115 | /** |
||
116 | * @return GuzzleHttp\Message\ResponseInterface |
||
117 | */ |
||
118 | public function getResponse() |
||
122 | |||
123 | /** |
||
124 | * @return array |
||
125 | */ |
||
126 | public function getQueryParameters() |
||
131 | |||
132 | /** |
||
133 | * @return array |
||
134 | */ |
||
135 | public function getHeaders() |
||
140 | |||
141 | /** |
||
142 | * @param GuzzleHttp\Exception\RequestException $ex |
||
143 | * @param string $message |
||
144 | * @throws \Exception |
||
145 | */ |
||
146 | protected function requestException(GuzzleHttp\Exception\RequestException $ex, $message = "Falha de requisição") |
||
155 | |||
156 | } |
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: