mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 20:15:22 +02:00
Use Synth for exchange rates (#514)
* Switch currency seeding over to Synth * Switch all exchange rates over to Synth
This commit is contained in:
parent
0f2c41477d
commit
4843cf22c6
4 changed files with 29 additions and 84 deletions
|
@ -3,18 +3,18 @@ namespace :currencies do
|
|||
task seed: :environment do
|
||||
currencies = ENV["CURRENCIES"].split(",")
|
||||
|
||||
if currencies.count > 1 && ENV["OPEN_EXCHANGE_APP_ID"].present?
|
||||
url = "https://openexchangerates.org/api/currencies.json"
|
||||
if currencies.count > 1 && ENV["SYNTH_API_KEY"].present?
|
||||
url = "https://api.synthfinance.com/currencies"
|
||||
|
||||
response = Faraday.get(url) do |req|
|
||||
req.params["app_id"] = ENV["OPEN_EXCHANGE_APP_ID"]
|
||||
req.headers["Authorization"] = "Bearer #{ENV["SYNTH_API_KEY"]}"
|
||||
end
|
||||
|
||||
oxr_currencies = JSON.parse(response.body)
|
||||
synth_currencies = JSON.parse(response.body)
|
||||
|
||||
currencies.each do |iso_code|
|
||||
Currency.find_or_create_by(iso_code: iso_code) do |c|
|
||||
c.name = oxr_currencies[iso_code]
|
||||
c.name = synth_currencies["data"].find { |currency| currency["iso_code"] == iso_code.downcase }["name"]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue