22
33namespace Syntax \SteamApi ;
44
5+ use GuzzleHttp \Exception \GuzzleException ;
6+ use Illuminate \Support \Collection ;
7+ use Illuminate \Support \Facades \Config ;
58use stdClass ;
69use GuzzleHttp \Client as GuzzleClient ;
710use GuzzleHttp \Psr7 \Request ;
811use Exception ;
9- use GuzzleHttp \Exception \ClientErrorResponseException ;
10- use GuzzleHttp \Exception \ServerErrorResponseException ;
12+ use GuzzleHttp \Exception \ClientException ;
13+ use GuzzleHttp \Exception \ServerException ;
14+ use Syntax \SteamApi \Exceptions \ApiArgumentRequired ;
1115use Syntax \SteamApi \Exceptions \ApiCallFailedException ;
1216use Syntax \SteamApi \Exceptions \ClassNotFoundException ;
17+ use Syntax \SteamApi \Steam \App ;
18+ use Syntax \SteamApi \Steam \Group ;
19+ use Syntax \SteamApi \Steam \Item ;
20+ use Syntax \SteamApi \Steam \News ;
21+ use Syntax \Steamapi \Steam \Package ;
22+ use Syntax \SteamApi \Steam \Player ;
23+ use Syntax \SteamApi \Steam \User ;
24+ use Syntax \SteamApi \Steam \User \Stats ;
1325
1426/**
15- * @method \Syntax\SteamApi\Steam\ News news()
16- * @method \Syntax\SteamApi\Steam\ Player player($steamId)
17- * @method \Syntax\SteamApi\Steam\ User user($steamId)
18- * @method \Syntax\SteamApi\Steam\User\ Stats userStats($steamId)
19- * @method \Syntax\SteamApi\Steam\ App app()
20- * @method \Syntax\Steamapi\Steam\ Package package()
21- * @method \Syntax\SteamApi\Steam\ Group group()
22- * @method \Syntax\SteamApi\Steam\ Item item($appId)
27+ * @method News news()
28+ * @method Player player($steamId)
29+ * @method User user($steamId)
30+ * @method Stats userStats($steamId)
31+ * @method App app()
32+ * @method Package package()
33+ * @method Group group()
34+ * @method Item item($appId)
2335 */
2436class Client
2537{
@@ -45,12 +57,15 @@ class Client
4557
4658 protected $ isService = false ;
4759
60+ protected $ responseBody ;
61+
4862 public function __construct ()
4963 {
5064 $ apiKey = $ this ->getApiKey ();
5165
5266 $ this ->client = new GuzzleClient ();
5367 $ this ->apiKey = $ apiKey ;
68+ $ this ->responseBody = null ;
5469
5570 // Set up the Ids
5671 $ this ->setUpFormatted ();
@@ -73,6 +88,7 @@ public function getSteamId()
7388 *
7489 * @throws ApiArgumentRequired
7590 * @throws ApiCallFailedException
91+ * @throws GuzzleException
7692 */
7793 protected function setUpService ($ arguments = null )
7894 {
@@ -140,7 +156,6 @@ protected function setUpXml(array $arguments = [])
140156 $ parameters = http_build_query ($ arguments );
141157
142158 // Pass the results back
143- return simplexml_load_file ($ steamUrl . '? ' . $ parameters );
144159 libxml_use_internal_errors (true );
145160 $ result = simplexml_load_file ($ steamUrl . '? ' . $ parameters );
146161
@@ -165,10 +180,11 @@ public function getRedirectUrl()
165180 }
166181
167182 /**
168- * @param \GuzzleHttp\Psr7\ Request $request
183+ * @param Request $request
169184 *
170- * @return \stdClass
171- * @throws \Syntax\SteamApi\Exceptions\ApiCallFailedException
185+ * @return stdClass
186+ * @throws ApiCallFailedException
187+ * @throws GuzzleException
172188 */
173189 protected function sendRequest (Request $ request )
174190 {
@@ -179,9 +195,9 @@ protected function sendRequest(Request $request)
179195 $ result = new stdClass ();
180196 $ result ->code = $ response ->getStatusCode ();
181197 $ result ->body = json_decode ($ response ->getBody (true ));
182- } catch (ClientErrorResponseException $ e ) {
198+ } catch (ClientException $ e ) {
183199 throw new ApiCallFailedException ($ e ->getMessage (), $ e ->getResponse ()->getStatusCode (), $ e );
184- } catch (ServerErrorResponseException $ e ) {
200+ } catch (ServerException $ e ) {
185201 throw new ApiCallFailedException ('Api call failed to complete due to a server error. ' , $ e ->getResponse ()->getStatusCode (), $ e );
186202 } catch (Exception $ e ) {
187203 throw new ApiCallFailedException ($ e ->getMessage (), $ e ->getCode (), $ e );
@@ -236,7 +252,7 @@ public function __call($name, $arguments)
236252 /**
237253 * @param Collection $objects
238254 *
239- * @return $this
255+ * @return Collection
240256 */
241257 protected function sortObjects ($ objects )
242258 {
@@ -260,9 +276,7 @@ protected function getServiceResponse($arguments)
260276 $ arguments = json_encode ($ arguments );
261277
262278 // Get the client
263- $ client = $ this ->setUpService ($ arguments )->response ;
264-
265- return $ client ;
279+ return $ this ->setUpService ($ arguments )->response ;
266280 }
267281
268282 /**
@@ -271,7 +285,7 @@ protected function getServiceResponse($arguments)
271285 */
272286 protected function getApiKey ()
273287 {
274- $ apiKey = \ Config::get ('steam-api.steamApiKey ' );
288+ $ apiKey = Config::get ('steam-api.steamApiKey ' );
275289
276290 if ($ apiKey == 'YOUR-API-KEY ' ) {
277291 throw new Exceptions \InvalidApiKeyException ();
0 commit comments