Created
June 17, 2015 17:28
-
-
Save sroller/7a54438428456ab799e9 to your computer and use it in GitHub Desktop.
Savon 2.x demo with WSDL
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 | |
# | |
# 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