Last active
December 21, 2021 17:52
-
-
Save nejdetkadir/b8b559c223f8a5b434cb73880fdf3474 to your computer and use it in GitHub Desktop.
fixer.io task for currencies rates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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