Skip to content

Instantly share code, notes, and snippets.

@vderyagin
Last active December 17, 2015 15:08
Show Gist options
  • Save vderyagin/5629163 to your computer and use it in GitHub Desktop.
Save vderyagin/5629163 to your computer and use it in GitHub Desktop.
#! /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