1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 15:49:39 +02:00
Maybe/lib/tasks/currencies.rake
Josh Pigford aa351ae616
Multi-currency support (#425)
* Initial foundational pass at multi-currency

* Default format currency

* More work on currency and exchanging

* Re-build currencies on change

* Currency import/setup

* Background job overhaul + cheaper OXR plan support

* Lint fixes

* Test fixes

* Multi-currency setup instructions

* Allow decimals in the balance field

* Spacing fix for form

---------

Signed-off-by: Josh Pigford <josh@joshpigford.com>
2024-02-10 16:18:56 -06:00

28 lines
812 B
Ruby

namespace :currencies do
desc "Seed Currencies"
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"
response = Faraday.get(url) do |req|
req.params["app_id"] = ENV["OPEN_EXCHANGE_APP_ID"]
end
oxr_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]
end
end
puts "Currencies created: #{Currency.count}"
elsif currencies.count == 1
Currency.find_or_create_by(iso_code: currencies.first)
else
puts "No currencies found in ENV['CURRENCIES']"
end
end
end