1111use GuzzleHttp \Client ;
1212use GuzzleHttp \Exception \ConnectException ;
1313use GuzzleHttp \Exception \RequestException ;
14+ use GuzzleHttp \Psr7 \Response ;
1415use League \CLImate \CLImate ;
1516use League \CLImate \Util \Writer \File ;
1617use League \CLImate \Util \Writer \WriterInterface ;
@@ -20,6 +21,7 @@ class Api {
2021
2122 protected $ config ;
2223 protected $ http ;
24+ protected $ lastResponse ;
2325
2426 /**
2527 * @param $config array|string|\Fulfillment\Api\Contracts\ApiConfiguration|null
@@ -155,9 +157,12 @@ public function config()
155157
156158 protected function tryRequest ($ method , $ url , $ payload = null , $ queryString = null , $ firstTry = true )
157159 {
160+ $ this ->lastResponse = null ;
158161 try
159162 {
160- return $ this ->http ->makeRequest ($ method , $ url , $ payload , $ queryString );
163+ $ resultArr = $ this ->http ->makeRequest ($ method , $ url , $ payload , $ queryString );
164+ $ this ->lastResponse = $ resultArr ['response ' ];
165+ return $ resultArr ['result ' ];
161166 }
162167 catch (ConnectException $ c )
163168 {
@@ -274,4 +279,14 @@ public function delete($url, $queryString = null)
274279 {
275280 return $ this ->tryRequest ('delete ' , $ url , null , $ queryString );
276281 }
282+
283+ /**
284+ * Get the Response object from the last successful request
285+ *
286+ * @return Response|null
287+ */
288+ public function getLastResponse ()
289+ {
290+ return $ this ->lastResponse ;
291+ }
277292}
0 commit comments