From 42742bb050358f844e3bd553455ce60c1c0c48d5 Mon Sep 17 00:00:00 2001 From: Alexander Yakovlev Date: Sat, 7 Jul 2018 04:39:14 +0700 Subject: [PATCH] namespace and api call --- Config.php | 6 +++--- Helper/Config.php | 8 ++++---- Model/Currency/Import/Fcc.php | 19 ++++++++----------- README.md | 8 +++----- composer.json | 11 +++++++---- etc/adminhtml/system.xml | 6 +++--- etc/config.xml | 6 +++--- etc/di.xml | 8 ++++---- etc/module.xml | 4 ++-- registration.php | 4 ++-- 10 files changed, 39 insertions(+), 41 deletions(-) diff --git a/Config.php b/Config.php index 9ff6d01..421ce58 100644 --- a/Config.php +++ b/Config.php @@ -4,8 +4,8 @@ * Since: 2018 */ -namespace Flancer32\FreeRates; +namespace Oreolek\MagentoLym; class Config { - const MODULE = 'Flancer32_FreeRates'; -} \ No newline at end of file + const MODULE = 'Oreolek_MagentoLym'; +} diff --git a/Helper/Config.php b/Helper/Config.php index 29337fa..8566a5c 100644 --- a/Helper/Config.php +++ b/Helper/Config.php @@ -4,7 +4,7 @@ * Since: 2018 */ -namespace Flancer32\FreeRates\Helper; +namespace Oreolek\MagentoLym\Helper; class Config @@ -24,7 +24,7 @@ class Config */ public function getDelay() { - $result = (int)$this->scopeConfig->getValue('currency/fcc/delay'); + $result = (int)$this->scopeConfig->getValue('currency/lym/delay'); return $result; } @@ -33,7 +33,7 @@ class Config */ public function getTimeout() { - $result = (int)$this->scopeConfig->getValue('currency/fcc/timeout'); + $result = (int)$this->scopeConfig->getValue('currency/lym/timeout'); return $result; } -} \ No newline at end of file +} diff --git a/Model/Currency/Import/Fcc.php b/Model/Currency/Import/Fcc.php index 1159314..e0dfba2 100644 --- a/Model/Currency/Import/Fcc.php +++ b/Model/Currency/Import/Fcc.php @@ -6,7 +6,7 @@ * Since: 2018 */ -namespace Flancer32\FreeRates\Model\Currency\Import; +namespace Oreolek\MagentoLym\Model\Currency\Import; class Fcc @@ -15,9 +15,9 @@ class Fcc /** * @var string */ - const CURRENCY_CONVERTER_URL = 'https://free.currencyconverterapi.com/api/v3/convert?q={{CURRENCY_FROM}}_{{CURRENCY_TO}}'; + const CURRENCY_CONVERTER_URL = 'https://coindata.lympo.io/etherspy/public/api/fetch/currency/market_data?currency=lympo&ticker_symbol=lym'; - /** @var \Flancer32\FreeRates\Helper\Config */ + /** @var \Oreolek\MagentoLym\Helper\Config */ private $hlpCfg; /** @var \Magento\Framework\HTTP\ZendClient */ private $httpClient; @@ -31,7 +31,7 @@ class Fcc \Magento\Framework\HTTP\ZendClient $httpClient, \Magento\Directory\Model\CurrencyFactory $currencyFactory, \Magento\Framework\Json\Helper\Data $jsonHelper, - \Flancer32\FreeRates\Helper\Config $hlpCfg + \Oreolek\MagentoLym\Helper\Config $hlpCfg ) { parent::__construct($currencyFactory); $this->logger = $logger; @@ -49,8 +49,7 @@ class Fcc protected function _convert($currencyFrom, $currencyTo, $retry = 0) { $result = null; - $url = str_replace('{{CURRENCY_FROM}}', $currencyFrom, self::CURRENCY_CONVERTER_URL); - $url = str_replace('{{CURRENCY_TO}}', $currencyTo, $url); + $url = self::CURRENCY_CONVERTER_URL; $this->logger->info("Currency rates request: $url"); $delay = $this->hlpCfg->getDelay(); $timeout = $this->hlpCfg->getTimeout(); @@ -60,14 +59,12 @@ class Fcc $this->httpClient->setConfig(['timeout' => $timeout,]); $response = $this->httpClient->request('GET'); $body = $response->getBody(); - $resultKey = $currencyFrom . '_' . $currencyTo; $data = $this->jsonHelper->jsonDecode($body); - $results = $data['results'][$resultKey]; - $queryCount = $data['query']['count']; - if (!$queryCount && !isset($results)) { + $results = $data['results']['currency_market_data']; + if (!isset($results)) { $this->_messages[] = __('We can\'t retrieve a rate from %1.', $url); } else { - $result = (float)$results['val']; + $result = (float)$results[$currencyFrom]['current_price']; } } catch (\Exception $e) { if ($retry == 0) { diff --git a/README.md b/README.md index bf7b8c8..ecd79bf 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,9 @@ -# mage2_ext_free_rates +# LYM currency -Magento 2: Currency converter to get rates from https://free.currencyconverterapi.com/ - -[Based on "krybbio" code](https://magento.stackexchange.com/a/228671/33058). +Magento 2: LYM Currency ``` -$ composer require flancer32/mage2_ext_free_rates +$ composer require oreolek/magentolym $ ./bin/magento setup:upgrade $ ./bin/magento deploy:mode:set developer $ ./bin/magento deploy:mode:set production diff --git a/composer.json b/composer.json index 85d195c..edb33d4 100644 --- a/composer.json +++ b/composer.json @@ -1,13 +1,16 @@ { - "name": "flancer32/mage2_ext_free_rates", - "description": "Magento 2: Currency converter to get rates from https://free.currencyconverterapi.com/", + "name": "oreolek/magentolym", + "description": "Magento 2: LYM Currency", "type": "magento2-module", - "homepage": "https://github.com/flancer32/mage2_ext_free_rates", "license": "GPL-3.0-only", "authors": [ { "name": "Alex Gusev", "email": "alex@flancer64.com" + }, + { + "name": "Alex Yakovlev", + "email": "keloero@oreolek.ru" } ], "require": {}, @@ -16,7 +19,7 @@ "registration.php" ], "psr-4": { - "Flancer32\\FreeRates\\": "" + "Oreolek\\MagentoLym\\": "" } } } diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 220d45e..25e3621 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -3,9 +3,9 @@ xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
- - + @@ -17,4 +17,4 @@
- \ No newline at end of file + diff --git a/etc/config.xml b/etc/config.xml index 801ee0d..d523857 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -3,10 +3,10 @@ xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd"> - + 100 1 - + - \ No newline at end of file + diff --git a/etc/di.xml b/etc/di.xml index 241262b..e0d99bf 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -5,12 +5,12 @@ - - Free Currency Converter - Flancer32\FreeRates\Model\Currency\Import\Fcc + + LYM Currency + Oreolek\MagentoLym\Model\Currency\Import\Fcc - \ No newline at end of file + diff --git a/etc/module.xml b/etc/module.xml index 32660bb..b90ca55 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -2,9 +2,9 @@ - + - \ No newline at end of file + diff --git a/registration.php b/registration.php index cb14044..006ab9c 100644 --- a/registration.php +++ b/registration.php @@ -5,6 +5,6 @@ */ \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, - \Flancer32\FreeRates\Config::MODULE, + \Oreolek\MagentoLym\Config::MODULE, __DIR__ -); \ No newline at end of file +);