Skip to content

Instantly share code, notes, and snippets.

@sroller
Created June 17, 2015 17:28
Show Gist options
  • Save sroller/7a54438428456ab799e9 to your computer and use it in GitHub Desktop.
Save sroller/7a54438428456ab799e9 to your computer and use it in GitHub Desktop.
Savon 2.x demo with WSDL
#!/usr/bin/env ruby
#
# demo of Savon 2.x interface with WSDL
#
# gem 'savon', "~>2.x"
require 'savon'
class GetXRate
def initialize
@client = Savon.client(
wsdl: "http://www.webservicex.com/CurrencyConvertor.asmx?wsdl",
# log: true,
log_level: :debug,
pretty_print_xml: true,
open_timeout: 300,
read_timeout: 300
)
end
def get_x_rate(from_curr, to_curr)
response = @client.call(:conversion_rate,
message: {
"FromCurrency" => from_curr,
"ToCurrency" => to_curr
}
)
response.to_hash[:conversion_rate_response][:conversion_rate_result];
end
end
xrate = GetXRate.new
print "USD to EUR=", xrate.get_x_rate('USD', 'EUR'), "\n"
print "EUR to USD=", xrate.get_x_rate('EUR', 'USD'), "\n"
print "CAD to USD=", xrate.get_x_rate('CAD', 'USD'), "\n"
print "EUR to CAD=", xrate.get_x_rate('EUR', 'CAD'), "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment