mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 15:49:39 +02:00
* 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>
28 lines
812 B
Ruby
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
|