Added more env variables to configure providers

This commit is contained in:
Jan Böhmer 2023-07-17 00:19:02 +02:00
parent 4c1c6701b3
commit 7b61cb3163
6 changed files with 72 additions and 24 deletions

View file

@ -46,15 +46,17 @@ class DigikeyProvider implements InfoProviderInterface
private readonly HttpClientInterface $digikeyClient;
public function __construct(HttpClientInterface $httpClient, private readonly OAuthTokenManager $authTokenManager, private readonly string $currency, private readonly string $clientId)
public function __construct(HttpClientInterface $httpClient, private readonly OAuthTokenManager $authTokenManager,
private readonly string $currency, private readonly string $clientId,
private readonly string $language, private readonly string $country)
{
//Create the HTTP client with some default options
$this->digikeyClient = $httpClient->withOptions([
"base_uri" => self::BASE_URI,
"headers" => [
"X-DIGIKEY-Client-Id" => $clientId,
"X-DIGIKEY-Locale-Site" => 'DE',
"X-DIGIKEY-Locale-Language" => 'de',
"X-DIGIKEY-Locale-Site" => $this->country,
"X-DIGIKEY-Locale-Language" => $this->language,
"X-DIGIKEY-Locale-Currency" => $this->currency,
"X-DIGIKEY-Customer-Id" => 0,
]
@ -68,6 +70,7 @@ class DigikeyProvider implements InfoProviderInterface
'description' => 'This provider uses the DigiKey API to search for parts.',
'url' => 'https://www.digikey.com/',
'oauth_app_name' => self::OAUTH_APP_NAME,
'disabled_help' => 'Set the PROVIDER_DIGIKEY_CLIENT_ID and PROVIDER_DIGIKEY_SECRET env option and connect OAuth to enable.'
];
}

View file

@ -37,7 +37,6 @@ class Element14Provider implements InfoProviderInterface
{
private const ENDPOINT_URL = 'https://api.element14.com/catalog/products';
private const FARNELL_STORE_ID = 'de.farnell.com';
private const API_VERSION_NUMBER = '1.2';
private const NUMBER_OF_RESULTS = 20;
@ -46,7 +45,7 @@ class Element14Provider implements InfoProviderInterface
private const COMPLIANCE_ATTRIBUTES = ['euEccn', 'hazardous', 'MSL', 'productTraceability', 'rohsCompliant',
'rohsPhthalatesCompliant', 'SVHC', 'tariffCode', 'usEccn', 'hazardCode'];
public function __construct(private readonly HttpClientInterface $element14Client, private readonly string $api_key)
public function __construct(private readonly HttpClientInterface $element14Client, private readonly string $api_key, private readonly string $store_id)
{
}
@ -57,6 +56,7 @@ class Element14Provider implements InfoProviderInterface
'name' => 'Farnell element14',
'description' => 'This provider uses the Farnell element14 API to search for parts.',
'url' => 'https://www.element14.com/',
'disabled_help' => 'Configure the API key in the PROVIDER_ELEMENT14_KEY environment variable to enable.'
];
}
@ -79,7 +79,7 @@ class Element14Provider implements InfoProviderInterface
$response = $this->element14Client->request('GET', self::ENDPOINT_URL, [
'query' => [
'term' => $term,
'storeInfo.id' => self::FARNELL_STORE_ID,
'storeInfo.id' => $this->store_id,
'resultsSettings.offset' => 0,
'resultsSettings.numberOfResults' => self::NUMBER_OF_RESULTS,
'resultsSettings.responseGroup' => 'large',
@ -121,7 +121,7 @@ class Element14Provider implements InfoProviderInterface
private function generateProductURL($sku): string
{
return 'https://' . self::FARNELL_STORE_ID . '/' . $sku;
return 'https://' . $this->store_id . '/' . $sku;
}
/**
@ -154,7 +154,7 @@ class Element14Provider implements InfoProviderInterface
$locale = 'en_US';
}
return 'https://' . self::FARNELL_STORE_ID . '/productimages/standard/' . $locale . $image['baseName'];
return 'https://' . $this->store_id . '/productimages/standard/' . $locale . $image['baseName'];
}
/**
@ -189,7 +189,7 @@ class Element14Provider implements InfoProviderInterface
public function getUsedCurrency(): string
{
//Decide based on the shop ID
return match (self::FARNELL_STORE_ID) {
return match ($this->store_id) {
'bg.farnell.com' => 'EUR',
'cz.farnell.com' => 'CZK',
'dk.farnell.com' => 'DKK',
@ -237,7 +237,7 @@ class Element14Provider implements InfoProviderInterface
'tw.element14.com' => 'TWD',
'kr.element14.com' => 'KRW',
'vn.element14.com' => 'VND',
default => throw new \RuntimeException('Unknown store ID: ' . self::FARNELL_STORE_ID)
default => throw new \RuntimeException('Unknown store ID: ' . $this->store_id)
};
}

View file

@ -38,15 +38,10 @@ class TMEProvider implements InfoProviderInterface
private const VENDOR_NAME = 'TME';
private string $country = 'DE';
private string $language = 'en';
private string $currency = 'EUR';
/**
* @var bool If true, the prices are gross prices. If false, the prices are net prices.
*/
private bool $get_gross_prices = true;
public function __construct(private readonly TMEClient $tmeClient)
public function __construct(private readonly TMEClient $tmeClient, private readonly string $country,
private readonly string $language, private readonly string $currency,
/** @var bool If true, the prices are gross prices. If false, the prices are net prices. */
private readonly string $get_gross_prices)
{
}
@ -57,6 +52,7 @@ class TMEProvider implements InfoProviderInterface
'name' => 'TME',
'description' => 'This provider uses the API of TME (Transfer Multipart).',
'url' => 'https://tme.eu/',
'disabled_help' => 'Configure the PROVIDER_TME_KEY and PROVIDER_TME_SECRET environment variables to use this provider.'
];
}