-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Volodymyr Saakian
committed
Mar 6, 2020
1 parent
5a9cf02
commit 72e4f16
Showing
9 changed files
with
197 additions
and
74 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const Http = require('../utils/http'); | ||
|
||
class FinanceApi { | ||
generateMessageTemplate() { | ||
const banks = ['ПриватБанк', 'Укрсиббанк']; | ||
const currencyIgnore = ['RUB']; | ||
|
||
const findedBanks = this.data.organizations.reduce((acc, val) => { | ||
if (banks.includes(val.title)) { | ||
return [...acc, val]; | ||
} | ||
return [...acc]; | ||
}, []); | ||
|
||
return findedBanks | ||
.map(bank => { | ||
const firstLine = `${bank.title}: \n`; | ||
const nextLines = Object.keys(bank.currencies).reduce((acc, key) => { | ||
const currency = bank.currencies[key]; | ||
if (currencyIgnore.includes(key)) { | ||
return [...acc]; | ||
} | ||
return [ | ||
...acc, | ||
`${key}: ${parseInt(currency.ask).toFixed(2)}/${parseInt( | ||
currency.bid | ||
).toFixed(2)}` | ||
]; | ||
}, []); | ||
return firstLine + nextLines.join('\n'); | ||
}) | ||
.join('\n\n'); | ||
} | ||
|
||
async getData() { | ||
this.data = await Http.get( | ||
'http://resources.finance.ua/ru/public/currency-cash.json' | ||
); | ||
return this.data; | ||
} | ||
} | ||
|
||
module.exports = FinanceApi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const Http = require('../utils/http'); | ||
|
||
class MinfinApi { | ||
static async get() { | ||
return Http.get('http://resources.finance.ua/ru/public/currency-cash.json'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const got = require('got'); | ||
|
||
const get = async url => { | ||
try { | ||
const response = await got.get(url).json(); | ||
return response; | ||
} catch (error) { | ||
throw error; | ||
} | ||
}; | ||
|
||
module.exports = { get }; |