Moved mouser info provider config to settings-bundle

This commit is contained in:
Jan Böhmer 2024-05-05 23:34:06 +02:00
parent 5a4b7c525b
commit 5a563e4f8f
8 changed files with 621 additions and 509 deletions

View file

@ -37,6 +37,7 @@ use App\Services\InfoProviderSystem\DTOs\FileDTO;
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
use App\Services\InfoProviderSystem\DTOs\PriceDTO;
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
use App\Settings\InfoProviderSystem\MouserSettings;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
@ -50,10 +51,7 @@ class MouserProvider implements InfoProviderInterface
public function __construct(
private readonly HttpClientInterface $mouserClient,
private readonly string $api_key,
private readonly string $language,
private readonly string $options,
private readonly int $search_limit
private readonly MouserSettings $settings,
) {
}
@ -74,7 +72,7 @@ class MouserProvider implements InfoProviderInterface
public function isActive(): bool
{
return !empty($this->api_key);
return !empty($this->settings->apiKey);
}
public function searchByKeyword(string $keyword): array
@ -119,15 +117,15 @@ class MouserProvider implements InfoProviderInterface
$response = $this->mouserClient->request('POST', self::ENDPOINT_URL."/keyword", [
'query' => [
'apiKey' => $this->api_key,
'apiKey' => $this->settings->apiKey
],
'json' => [
'SearchByKeywordRequest' => [
'keyword' => $keyword,
'records' => $this->search_limit, //self::NUMBER_OF_RESULTS,
'records' => $this->settings->searchLimit, //self::NUMBER_OF_RESULTS,
'startingRecord' => 0,
'searchOptions' => $this->options,
'searchWithYourSignUpLanguage' => $this->language,
'searchOptions' => $this->settings->searchOption->value,
'searchWithYourSignUpLanguage' => $this->settings->searchWithSignUpLanguage ? 'true' : 'false',
]
],
]);
@ -160,7 +158,7 @@ class MouserProvider implements InfoProviderInterface
$response = $this->mouserClient->request('POST', self::ENDPOINT_URL."/partnumber", [
'query' => [
'apiKey' => $this->api_key,
'apiKey' => $this->settings->apiKey,
],
'json' => [
'SearchByPartRequest' => [