1 | <?php |
||
24 | class Client |
||
25 | { |
||
26 | use SteamId; |
||
27 | |||
28 | public $validFormats = ['json', 'xml', 'vdf']; |
||
29 | |||
30 | protected $url = 'http://api.steampowered.com/'; |
||
31 | |||
32 | protected $client; |
||
33 | |||
34 | protected $interface; |
||
35 | |||
36 | protected $method; |
||
37 | |||
38 | protected $version = 'v0002'; |
||
39 | |||
40 | protected $apiKey; |
||
41 | |||
42 | protected $apiFormat = 'json'; |
||
43 | |||
44 | protected $steamId; |
||
45 | |||
46 | protected $isService = false; |
||
47 | |||
48 | 37 | public function __construct() |
|
49 | { |
||
50 | 37 | $apiKey = $this->getApiKey(); |
|
51 | |||
52 | 37 | $this->client = new GuzzleClient(); |
|
53 | 37 | $this->apiKey = $apiKey; |
|
54 | |||
55 | // Set up the Ids |
||
56 | 37 | $this->setUpFormatted(); |
|
57 | 37 | } |
|
58 | |||
59 | public function get() |
||
60 | { |
||
61 | return $this; |
||
62 | } |
||
63 | |||
64 | 1 | public function getSteamId() |
|
65 | { |
||
66 | 1 | return $this->steamId; |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * @param string $arguments |
||
71 | * |
||
72 | * @return string |
||
73 | * |
||
74 | * @throws ApiArgumentRequired |
||
75 | * @throws ApiCallFailedException |
||
76 | */ |
||
77 | 3 | protected function setUpService($arguments = null) |
|
102 | |||
103 | 15 | protected function setUpClient(array $arguments = []) |
|
104 | { |
||
105 | 15 | $versionFlag = ! is_null($this->version); |
|
134 | |||
135 | 4 | protected function setUpXml(array $arguments = []) |
|
153 | |||
154 | 1 | public function getRedirectUrl() |
|
166 | |||
167 | /** |
||
168 | * @param \GuzzleHttp\Psr7\Request $request |
||
169 | * |
||
170 | * @return \stdClass |
||
171 | * @throws \Syntax\SteamApi\Exceptions\ApiCallFailedException |
||
172 | */ |
||
173 | 18 | protected function sendRequest(Request $request) |
|
174 | { |
||
175 | // Try to get the result. Handle the possible exceptions that can arise |
||
176 | try { |
||
177 | 18 | $response = $this->client->send($request); |
|
178 | |||
179 | 16 | $result = new stdClass(); |
|
180 | 16 | $result->code = $response->getStatusCode(); |
|
181 | 16 | $result->body = json_decode($response->getBody(true)); |
|
182 | 2 | } catch (ClientErrorResponseException $e) { |
|
183 | throw new ApiCallFailedException($e->getMessage(), $e->getResponse()->getStatusCode(), $e); |
||
184 | 2 | } catch (ServerErrorResponseException $e) { |
|
185 | throw new ApiCallFailedException('Api call failed to complete due to a server error.', $e->getResponse()->getStatusCode(), $e); |
||
186 | 2 | } catch (Exception $e) { |
|
187 | 2 | throw new ApiCallFailedException($e->getMessage(), $e->getCode(), $e); |
|
188 | } |
||
189 | |||
190 | // If all worked out, return the result |
||
191 | 16 | return $result; |
|
192 | } |
||
193 | |||
194 | 22 | private function buildUrl($version = false) |
|
206 | |||
207 | 25 | public function __call($name, $arguments) |
|
235 | |||
236 | /** |
||
237 | * @param Collection $objects |
||
238 | * |
||
239 | * @return $this |
||
240 | */ |
||
241 | 3 | protected function sortObjects($objects) |
|
247 | |||
248 | /** |
||
249 | * @param string $method |
||
250 | * @param string $version |
||
251 | */ |
||
252 | 3 | protected function setApiDetails($method, $version) |
|
257 | |||
258 | 3 | protected function getServiceResponse($arguments) |
|
267 | |||
268 | /** |
||
269 | * @return string |
||
270 | * @throws Exceptions\InvalidApiKeyException |
||
271 | */ |
||
272 | 37 | protected function getApiKey() |
|
285 | |||
286 | 18 | private function convertSteamIdTo64() |
|
298 | } |
||
299 |