44
55use AlwaysOpen \BwtApi \DTOs \Amazon \AmazonRequestCreationResponse ;
66use AlwaysOpen \BwtApi \DTOs \Amazon \AmazonResults ;
7+ use AlwaysOpen \BwtApi \DTOs \Amazon \AmazonSessionStatusResponse ;
78use AlwaysOpen \BwtApi \DTOs \BatchRequest ;
89use GuzzleHttp \Exception \GuzzleException ;
910use GuzzleHttp \Promise \PromiseInterface ;
@@ -24,14 +25,14 @@ public function __construct(
2425 ?string $ apiKey = null ,
2526 ) {
2627 $ this ->baseUrl = $ baseUrl ?? config ('bwt-api.base_url ' , 'https://bwt.com/api/ ' );
27- $ this ->apiKey = $ apiKey ?? config ('bwt-api.username ' ) ?? '' ;
28+ $ this ->apiKey = $ apiKey ?? config ('bwt-api.api_key ' ) ?? '' ;
2829 }
2930
3031 protected function getAuthHeader (): array
3132 {
3233 return [
3334 'Authorization ' => 'Bearer ' .$ this ->apiKey ,
34- ];
35+ ];
3536 }
3637
3738 /**
@@ -61,6 +62,27 @@ protected function makeRequest(
6162 }, 2000 );
6263 }
6364
65+ public function getAmazonSessionStatus (
66+ string $ id ,
67+ ): AmazonSessionStatusResponse {
68+ try {
69+ $ response = $ this ->makeRequest (
70+ 'get ' ,
71+ $ this ->baseUrl .= "/ $ id " ,
72+ null ,
73+ 3 ,
74+ );
75+ } catch (Throwable $ e ) {
76+ throw new RuntimeException ('API request failed: ' .$ e ->getMessage (), $ e ->getCode (), $ e );
77+ }
78+
79+ if (! $ response ->successful ()) {
80+ throw new RuntimeException ('API request failed: ' .$ response ->body (), $ response ->getStatusCode ());
81+ }
82+
83+ return AmazonSessionStatusResponse::from ($ response ->json ());
84+ }
85+
6486 public function getAmazonResults (
6587 string $ id ,
6688 int $ limit = 1 ,
@@ -69,7 +91,7 @@ public function getAmazonResults(
6991 try {
7092 $ response = $ this ->makeRequest (
7193 'get ' ,
72- $ this ->baseUrl .= "$ id/results?limit= $ limit&offset= $ offset " ,
94+ $ this ->baseUrl .= "/ $ id/results?limit= $ limit&offset= $ offset " ,
7395 null ,
7496 3 ,
7597 );
0 commit comments