dfdsf
This commit is contained in:
@@ -414,12 +414,25 @@ final class FxRatesService
|
||||
|
||||
private function fetchCurrenciesPayload(): array
|
||||
{
|
||||
$request = $this->buildCurrenciesRequest();
|
||||
if ($request === null) {
|
||||
$requests = $this->buildCurrenciesRequests();
|
||||
if ($requests === []) {
|
||||
throw new \RuntimeException('FX-API-Key fehlt.');
|
||||
}
|
||||
|
||||
$payload = null;
|
||||
$lastError = null;
|
||||
foreach ($requests as $request) {
|
||||
try {
|
||||
$payload = $this->requestJson($request['url'], $request['headers'] ?? [], 'Waehrungskatalog konnte nicht geladen werden.');
|
||||
break;
|
||||
} catch (\RuntimeException $exception) {
|
||||
$lastError = $exception;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_array($payload)) {
|
||||
throw $lastError ?? new \RuntimeException('Waehrungskatalog konnte nicht geladen werden.');
|
||||
}
|
||||
|
||||
if ($this->isCurrencyApiCom()) {
|
||||
return $this->normalizeCurrencyApiComCurrenciesPayload($payload);
|
||||
@@ -482,30 +495,40 @@ final class FxRatesService
|
||||
];
|
||||
}
|
||||
|
||||
private function buildCurrenciesRequest(): ?array
|
||||
private function buildCurrenciesRequests(): array
|
||||
{
|
||||
$apiKey = $this->apiKey();
|
||||
if ($apiKey === '') {
|
||||
return null;
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($this->isCurrencyApiCom()) {
|
||||
return [
|
||||
return [[
|
||||
'url' => $this->currenciesApiUrl() . '/v3/currencies',
|
||||
'headers' => [
|
||||
'Accept: application/json',
|
||||
'apikey: ' . $apiKey,
|
||||
],
|
||||
];
|
||||
]];
|
||||
}
|
||||
|
||||
return [
|
||||
[
|
||||
'url' => sprintf(
|
||||
'%s/api/v1/currencies?output=json&key=%s',
|
||||
$this->currenciesApiUrl(),
|
||||
rawurlencode($apiKey)
|
||||
),
|
||||
'headers' => ['Accept: application/json'],
|
||||
],
|
||||
[
|
||||
'url' => sprintf(
|
||||
'%s/api/v2/currencies?output=json&key=%s',
|
||||
$this->currenciesApiUrl(),
|
||||
rawurlencode($apiKey)
|
||||
),
|
||||
'headers' => ['Accept: application/json'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user