22
33use GuzzleHttp \Client ;
44use GuzzleHttp \Exception \RequestException ;
5- use GuzzleHttp \Message \Response ;
5+ use GuzzleHttp \Psr7 \Request ;
6+ use GuzzleHttp \Psr7 \Response ;
67
78class Connection {
89
@@ -64,23 +65,20 @@ public function client()
6465 {
6566 if ($ this ->client ) return $ this ->client ;
6667
67-
6868 $ this ->client = new Client ([
69- 'base_url ' => $ this ->apiUrl ()
70- ]);
71- $ this ->client ->setDefaultOption ('headers/Accept ' , 'application/json ' );
72- $ this ->client ->setDefaultOption ('headers/Content-Type ' , 'application/json ' );
73- $ this ->client ->setDefaultOption ('auth ' , [
74- $ this ->apiKey ,
75- $ this ->apiSecret
69+ 'base_uri ' => $ this ->apiUrl (),
70+ 'headers ' => [
71+ 'Accept ' => 'application/json ' ,
72+ 'Content-Type ' => 'application/json '
73+ ],
74+ 'auth ' => [$ this ->apiKey , $ this ->apiSecret ]
7675 ]);
7776
7877 return $ this ->client ;
7978 }
8079
8180 public function setDebug ($ handle )
8281 {
83- $ this ->client ()->setDefaultOption ('debug ' , $ handle );
8482 }
8583
8684 /**
@@ -96,23 +94,13 @@ public function apiUrl()
9694 /**
9795 * Perform a GET request
9896 * @param string $url
99- * @param array $params
100- * @return string
97+ * @return array
10198 * @throws SendCloudApiException
10299 */
103- public function get ($ url, array $ params = [] )
100+ public function get ($ url )
104101 {
105- $ request = $ this ->client ()->createRequest ('GET ' , $ url );
106-
107- $ query = $ request ->getQuery ();
108-
109- foreach ($ params as $ paramName => $ paramValue )
110- {
111- $ query ->set ($ paramName , $ paramValue );
112- }
113-
114102 try {
115- $ result = $ this ->client ()->send ( $ request );
103+ $ result = $ this ->client ()->get ( $ url );
116104 } catch (RequestException $ e ) {
117105 if ($ e ->hasResponse ())
118106 $ this ->parseResponse ($ e ->getResponse ());
@@ -193,7 +181,7 @@ public function delete($url)
193181 public function parseResponse (Response $ response )
194182 {
195183 try {
196- $ resultArray = $ response ->json ( );
184+ $ resultArray = json_decode ( $ response ->getBody ()-> getContents (), true );
197185
198186 if (array_key_exists ('error ' , $ resultArray )
199187 && is_array ($ resultArray ['error ' ])
0 commit comments