Created
June 17, 2015 17:16
-
-
Save sroller/3d04842ab763f52b6623 to your computer and use it in GitHub Desktop.
Savon 1.x example with WDSL
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
gem 'savon', "~>1.0" | |
require 'savon' | |
class GetXRate | |
def initialize | |
Savon.configure do |c| | |
c.log = false | |
end | |
HTTPI.log = false | |
@client = Savon::Client.new do | |
wsdl.document = "http://www.webservicex.com/CurrencyConvertor.asmx?wsdl" | |
end | |
@client.http.read_timeout = 300 | |
end | |
def get_x_rate(from_curr, to_curr) | |
response = @client.request :wsdl, :conversion_rate do | |
soap.body = { | |
"FromCurrency" => from_curr, | |
"ToCurrency" => to_curr | |
} | |
end | |
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