Re-namespacing a bit to clear out some fairly old stuff from the top level
This commit is contained in:
12
oldstuff/RubyFun/cookbook/016/03.rb
Normal file
12
oldstuff/RubyFun/cookbook/016/03.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
require 'xmlrpc/client'
|
||||
|
||||
server = XMLRPC::Client.new2('http://betty.userland.com/RPC2')
|
||||
puts server.call('examples.getStateName', 5)
|
||||
|
||||
|
||||
begin
|
||||
server.call('noSuchMethod')
|
||||
rescue XMLRPC::FaultException => e
|
||||
puts "Error: fault code #{e.faultCode}"
|
||||
puts e.faultString
|
||||
end
|
25
oldstuff/RubyFun/cookbook/016/03b.rb
Normal file
25
oldstuff/RubyFun/cookbook/016/03b.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
require 'xmlrpc/client'
|
||||
|
||||
|
||||
def lookup_upc(upc, rpc_key)
|
||||
server = XMLRPC::Client.new2('http://www.upcdatabase.com/xmlrpc')
|
||||
begin
|
||||
response = server.call('lookup', :upc => upc, :rpc_key => rpc_key)
|
||||
return response['found'] ? response : nil
|
||||
rescue XMLRPC::FaultException => e
|
||||
puts "Error: "
|
||||
puts e.faultCode
|
||||
puts e.faultString
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
['018787765654', 'no such UPC'].each do |upc|
|
||||
product = lookup_upc(upc, ARGV.first.strip)
|
||||
if product
|
||||
puts product['description']
|
||||
puts product['size']
|
||||
else
|
||||
puts "Oh no! product with upc='#{upc}' is #{product.inspect}"
|
||||
end
|
||||
end
|
10
oldstuff/RubyFun/cookbook/016/04.rb
Normal file
10
oldstuff/RubyFun/cookbook/016/04.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
require 'soap/rpc/driver'
|
||||
|
||||
# doesn't work (service no longer available?)
|
||||
driver = SOAP::RPC::Driver.new(
|
||||
'http://services.xmethods.net/soap/', 'url:xmethods-delayed-quotes'
|
||||
)
|
||||
|
||||
driver.add_method('getQuote', 'symbol')
|
||||
|
||||
puts 'Stock price: %.2f' % driver.getQuote(ARGV.first)
|
Reference in New Issue
Block a user