From 49bc38458b3987fdd2c0b88e1edf6c1ca594109c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9opold=20Gu=C3=A9rin?= Date: Thu, 1 Apr 2021 11:32:56 +0200 Subject: [PATCH 1/2] Add api key for exchangerateapi.io --- src/Console/Update.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Console/Update.php b/src/Console/Update.php index f7c42f3..bd46a55 100644 --- a/src/Console/Update.php +++ b/src/Console/Update.php @@ -65,8 +65,14 @@ public function handle() $defaultCurrency = $this->currency->config('default'); if ($this->input->getOption('exchangeratesapi')) { + if (!$api = $this->currency->config('api_key')) { + $this->error('An API key is needed from exchangeratesapi.io to continue.'); + + return; + } + // Get rates from exchangeratesapi - return $this->updateFromExchangeRatesApi($defaultCurrency); + return $this->updateFromExchangeRatesApi($defaultCurrency, $api); } if ($this->input->getOption('google')) { @@ -90,17 +96,18 @@ public function handle() * Fetch rates from the API * * @param $defaultCurrency + * @param $api */ - private function updateFromExchangeRatesApi($defaultCurrency) + private function updateFromExchangeRatesApi($defaultCurrency, $api) { $this->info('Updating currency exchange rates from ExchangeRatesApi.io...'); // Make request - $content = json_decode($this->request("https://api.exchangeratesapi.io/latest?base={$defaultCurrency}")); + $content = json_decode($this->request("https://api.exchangeratesapi.io/latest?access_key={$api}&base={$defaultCurrency}")); // Error getting content? if (isset($content->error)) { - $this->error($content->description); + $this->error($content->error->info); return; } From 9ecd400c411ff2c14744e1a9c629b396ce2b61e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9opold=20Gu=C3=A9rin?= Date: Tue, 17 Jan 2023 17:15:49 +0100 Subject: [PATCH 2/2] PR Review #148 --- src/Console/Update.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Console/Update.php b/src/Console/Update.php index b3aadea..1d9d63b 100644 --- a/src/Console/Update.php +++ b/src/Console/Update.php @@ -65,14 +65,13 @@ public function handle() $defaultCurrency = $this->currency->config('default'); if ($this->input->getOption('exchangeratesapi')) { - if (!$api = $this->currency->config('api_key')) { - $this->error('An API key is needed from exchangeratesapi.io to continue.'); - - return; + if ($access_key = $this->currency->config('api_key')) { + return $this->updateFromExchangeRatesApi($defaultCurrency, $access_key); } - // Get rates from exchangeratesapi - return $this->updateFromExchangeRatesApi($defaultCurrency, $api); + $this->error('An API key is needed from exchangeratesapi.io to continue.'); + + return; } if ($this->input->getOption('google')) {