Skip to content

Commit

Permalink
Replace no more accessible currency API
Browse files Browse the repository at this point in the history
  • Loading branch information
Calyhre committed May 19, 2017
1 parent a8e2b0a commit fea5fc9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/tasks/currencies.rake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'httparty'

API_URL = 'http://rate-exchange-1.appspot.com/currency'.freeze
API_URL = 'http://api.fixer.io/latest'.freeze

namespace :currencies do
desc 'Get all currencies exchange rates'
Expand All @@ -9,11 +9,12 @@ namespace :currencies do

currencies.each do |from|
puts "Retieving #{currencies.count} rates for #{from} currency..."
currencies.each do |to|
response = HTTParty.get(API_URL, query: { from: from, to: to})
rate = JSON.parse(response.body, symbolize_names: true)[:rate]
response = HTTParty.get(API_URL, query: { base: from, symbols: currencies.join(',')})
rates = JSON.parse(response.body, symbolize_names: true)[:rates]
rates.each do |to, rate|
Money.add_rate(from, to, rate)
end
Money.add_rate(from, from, 1.0)
end
end
end

0 comments on commit fea5fc9

Please sign in to comment.