diff --git a/src/BwtApi.php b/src/BwtApi.php index a65141c..726bbce 100755 --- a/src/BwtApi.php +++ b/src/BwtApi.php @@ -2,4 +2,7 @@ namespace AlwaysOpen\BwtApi; -class BwtApi {} +class BwtApi +{ + public const BWT_AMAZON_ENGINE = 'bwt_amazon_product'; +} diff --git a/src/BwtApiClient.php b/src/BwtApiClient.php index 5cd03f0..e70de09 100644 --- a/src/BwtApiClient.php +++ b/src/BwtApiClient.php @@ -4,6 +4,7 @@ use AlwaysOpen\BwtApi\DTOs\Amazon\AmazonRequestCreationResponse; use AlwaysOpen\BwtApi\DTOs\Amazon\AmazonResults; +use AlwaysOpen\BwtApi\DTOs\Amazon\AmazonSessionStatusResponse; use AlwaysOpen\BwtApi\DTOs\BatchRequest; use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Promise\PromiseInterface; @@ -24,7 +25,7 @@ public function __construct( ?string $apiKey = null, ) { $this->baseUrl = $baseUrl ?? config('bwt-api.base_url', 'https://bwt.com/api/'); - $this->apiKey = $apiKey ?? config('bwt-api.username') ?? ''; + $this->apiKey = $apiKey ?? config('bwt-api.api_key') ?? ''; } protected function getAuthHeader(): array @@ -61,6 +62,27 @@ protected function makeRequest( }, 2000); } + public function getAmazonSessionStatus( + string $id, + ): AmazonSessionStatusResponse { + try { + $response = $this->makeRequest( + 'get', + $this->baseUrl .= "/$id", + null, + 3, + ); + } catch (Throwable $e) { + throw new RuntimeException('API request failed: '.$e->getMessage(), $e->getCode(), $e); + } + + if (! $response->successful()) { + throw new RuntimeException('API request failed: '.$response->body(), $response->getStatusCode()); + } + + return AmazonSessionStatusResponse::from($response->json()); + } + public function getAmazonResults( string $id, int $limit = 1, @@ -69,7 +91,7 @@ public function getAmazonResults( try { $response = $this->makeRequest( 'get', - $this->baseUrl .= "$id/results?limit=$limit&offset=$offset", + $this->baseUrl .= "/$id/results?limit=$limit&offset=$offset", null, 3, ); diff --git a/src/DTOs/Amazon/AmazonSessionStatusResponse.php b/src/DTOs/Amazon/AmazonSessionStatusResponse.php new file mode 100644 index 0000000..a5e4dda --- /dev/null +++ b/src/DTOs/Amazon/AmazonSessionStatusResponse.php @@ -0,0 +1,20 @@ +value, public readonly ?int $max_offer_pages = null, ) {} } diff --git a/src/DTOs/BatchRequest.php b/src/DTOs/BatchRequest.php index 4bb5e63..419b623 100644 --- a/src/DTOs/BatchRequest.php +++ b/src/DTOs/BatchRequest.php @@ -2,6 +2,7 @@ namespace AlwaysOpen\BwtApi\DTOs; +use AlwaysOpen\BwtApi\DTOs\Amazon\ProductRequestItem; use Spatie\LaravelData\Data; class BatchRequest extends Data