Last active
December 17, 2015 15:08
-
-
Save vderyagin/5629163 to your computer and use it in GitHub Desktop.
This file contains 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
#! /usr/bin/env ruby | |
require 'json' | |
require 'net/http' | |
require 'uri' | |
def rate_converter(from, to) | |
uri = URI('http://rate-exchange.appspot.com/currency') | |
uri.query = URI.encode_www_form(from: from, to: to) | |
JSON.parse(Net::HTTP.get(uri))['rate'] | |
end | |
rate_converter('USD', 'CHF') # => 0.969600127 | |
rate_converter('USD', 'GBP') # => 0.662295516 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment