Skip to content

Instantly share code, notes, and snippets.

@nejdetkadir
Last active December 21, 2021 17:52
Show Gist options
  • Save nejdetkadir/b8b559c223f8a5b434cb73880fdf3474 to your computer and use it in GitHub Desktop.
Save nejdetkadir/b8b559c223f8a5b434cb73880fdf3474 to your computer and use it in GitHub Desktop.
fixer.io task for currencies rates
namespace :currency do
task :update do
uri = URI("http://data.fixer.io/api/latest")
params = { :access_key => ENV['FIXERIO_ACCESS_KEY'] }
uri.query = URI.encode_www_form(params)
res = Net::HTTP.get_response(uri)
if res.is_a?(Net::HTTPSuccess)
body = JSON.parse(res.body)
body["rates"].each do |currency, rate|
puts "#{currency} ==>>> #{rate}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment