1 | <?PHP |
||
25 | class RestClient |
||
26 | { |
||
27 | /** |
||
28 | * Your API key. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | private $apiKey; |
||
33 | |||
34 | /** |
||
35 | * @var HttpClient |
||
36 | */ |
||
37 | protected $httpClient; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $apiHost; |
||
43 | |||
44 | /** |
||
45 | * @var null |
||
46 | */ |
||
47 | protected $cache; |
||
48 | |||
49 | /** |
||
50 | * @param string $apiKey |
||
51 | * @param string $apiHost |
||
52 | * @param HttpClient $httpClient |
||
53 | */ |
||
54 | public function __construct($apiKey, $apiHost, HttpClient $httpClient = null, $cache = null) |
||
61 | |||
62 | /** |
||
63 | * @return HttpClient |
||
64 | */ |
||
65 | protected function getHttpClient() |
||
79 | |||
80 | /** |
||
81 | * Sends the API request if cache not hit |
||
82 | * |
||
83 | * @param string $method |
||
84 | * @param string $uri |
||
85 | * @param null $body |
||
86 | * @param array $headers |
||
87 | * @param string $cacheKey |
||
88 | * @param integer $ttl |
||
89 | * |
||
90 | * @return Response |
||
91 | */ |
||
92 | public function send($method, $uri, $body = null, array $headers = [], $cacheKey = null, $ttl = null) |
||
120 | |||
121 | /** |
||
122 | * Process the API response, provides error handling |
||
123 | * |
||
124 | * @param ResponseInterface $response |
||
125 | * |
||
126 | * @throws \Exception |
||
127 | * |
||
128 | * @return array |
||
129 | */ |
||
130 | public function processResponse(ResponseInterface $response) |
||
156 | |||
157 | /** |
||
158 | * @param string $endpointUrl |
||
159 | * @param array $queryString |
||
160 | * @param string|null $cacheKey |
||
161 | * @param integer|null $ttl |
||
162 | * |
||
163 | * @return ResponseInterface |
||
164 | */ |
||
165 | public function get($endpointUrl, $queryString = [], $cacheKey = null, $ttl = null) |
||
169 | |||
170 | /** |
||
171 | * @param string $endpointUrl |
||
172 | * @param array $postData |
||
173 | * |
||
174 | * @return \stdClass |
||
175 | */ |
||
176 | public function post($endpointUrl, array $postData = []) |
||
198 | |||
199 | /** |
||
200 | * @param $uri |
||
201 | * |
||
202 | * @return string |
||
203 | */ |
||
204 | private function getApiUrl($uri) |
||
208 | |||
209 | /** |
||
210 | * @param string $apiEndpoint |
||
211 | * |
||
212 | * @return string |
||
213 | */ |
||
214 | private function generateEndpoint($apiEndpoint) |
||
218 | } |
||
219 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: