Friday, December 1, 2006

A minimal Ruby Web Service client

Five lines of code are enough to write a Web Service client in Ruby:

require 'soap/wsdlDriver'

wsdl = 'http://www.webservicex.com/CurrencyConvertor.asmx?wsdl'
driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
input = {:FromCurrency => 'USD', :ToCurrency => 'EUR' }
print driver.ConversionRate(input).conversionRateResult


Save this file as "currency.rb" and run it from command line with:

ruby currency.rb