Ruby Use SOAP to fetch stock prices

Use SOAP to fetch stock prices

# this program will accurately return the price of GTEM.PK stock
# the location of the web service (endpoint URL)
# and the namespace used by teh service's domain

require 'soap/rpc/driver'
driver = SOAP::RPC::Driver.new(
   'http://services.xmethods.net/soap/',   # end point url
   'urn:xmethods-delayed-quotes')          # the namespace


# the name of the SOAP method you want to call
# and the names of its parameters

driver.add_method('getQuote', 'symbol')
# behind the scenes, that call to add_method actually defines
# a new method on the SOAP::RPC::Driver object
# the SOAP library uses metaprogramming to create custom Ruby
# methods that act like SOAP methods

# the details about the results you expect back

puts 'Stock price: %.2f' % driver.getQuote('TR')

# > ruby soapfetch.rb
# Stock price: 33.20