1 | <?php |
||
20 | class BattlenetHttpClient |
||
21 | { |
||
22 | /** |
||
23 | * @var Repository |
||
24 | */ |
||
25 | protected $cache; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $cacheKey = 'xklusive.battlenetapi.cache'; |
||
31 | |||
32 | /** |
||
33 | * Http client. |
||
34 | * |
||
35 | * @var object GuzzleHttp\Client |
||
36 | */ |
||
37 | protected $client; |
||
38 | |||
39 | /** |
||
40 | * Game name for url prefix. |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $gameParam; |
||
45 | |||
46 | /** |
||
47 | * Battle.net Connection Options. |
||
48 | * |
||
49 | * @var Collection |
||
50 | */ |
||
51 | protected $options; |
||
52 | |||
53 | /** |
||
54 | * API endpoint URL. |
||
55 | * |
||
56 | * @var string; |
||
57 | */ |
||
58 | protected $apiEndPoint; |
||
59 | |||
60 | /** |
||
61 | * BattlnetHttpClient constructor. |
||
62 | * |
||
63 | * @param $repository Illuminate\Contracts\Cache\Repository |
||
64 | */ |
||
65 | public function __construct(Repository $repository) |
||
72 | |||
73 | /** |
||
74 | * Creates a Mock Response based on the given array. |
||
75 | * Used to imitate API response from Blizzard, without calling the actual API. |
||
76 | * |
||
77 | * @param $responses array |
||
78 | */ |
||
79 | public function createMockResponse(array $responses = null) |
||
100 | |||
101 | /** |
||
102 | * Create a new client with the given handler. |
||
103 | * Right now only used for testing. |
||
104 | * |
||
105 | * @param $handler GuzzleHttp\HandlerStack |
||
106 | */ |
||
107 | protected function setGuzzHandler(HandlerStack $handler = null) |
||
116 | |||
117 | /** |
||
118 | * Make request with API url and specific URL suffix. |
||
119 | * |
||
120 | * @return Collection|ClientException |
||
121 | */ |
||
122 | protected function api() |
||
190 | |||
191 | /** |
||
192 | * Cache the api response data if cache set to true in config file. |
||
193 | * |
||
194 | * @param array $options Options |
||
195 | * @param string $method method name |
||
196 | * @param string $apiEndPoint |
||
197 | * @return Collection|ClientException |
||
198 | */ |
||
199 | public function cache($apiEndPoint, array $options, $method) |
||
222 | |||
223 | /** |
||
224 | * Get default query options from configuration file. |
||
225 | * |
||
226 | * @return Collection |
||
227 | */ |
||
228 | private function getDefaultOptions() |
||
235 | |||
236 | /** |
||
237 | * Set default option if a 'query' key is provided |
||
238 | * else create 'query' key with default options. |
||
239 | * |
||
240 | * @param Collection $options |
||
241 | * |
||
242 | * @return Collection api response |
||
243 | */ |
||
244 | private function getQueryOptions(Collection $options) |
||
259 | |||
260 | /** |
||
261 | * Get API domain provided in configuration. |
||
262 | * |
||
263 | * @return string |
||
264 | */ |
||
265 | private function getApiEndPoint() |
||
269 | |||
270 | /** |
||
271 | * Get API key provided in configuration. |
||
272 | * |
||
273 | * @return string |
||
274 | */ |
||
275 | private function getApiKey() |
||
279 | |||
280 | /** |
||
281 | * Get API locale provided in configuration. |
||
282 | * |
||
283 | * @return string |
||
284 | */ |
||
285 | private function getLocale() |
||
289 | |||
290 | /** |
||
291 | * This method wraps the given value in a collection when applicable. |
||
292 | * |
||
293 | * @return Collection |
||
294 | */ |
||
295 | public function wrapCollection($collection) |
||
303 | |||
304 | /** |
||
305 | * Build the cache configuration. |
||
306 | * |
||
307 | * @param string $method |
||
308 | */ |
||
309 | private function buildCahceOptions($method) |
||
324 | } |
||
325 |