Ruby 调用 XML RPC 服务

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

def lookup_upc(upc)
  server = XMLRPC::Client.new2('http://www.upcdatabase.com/rpc')
  begin
    response = server.call('lookupUPC', upc)
    return response['found'] ? response : nil
  rescue XMLRPC::FaultException => e
    puts "Error: "
    puts e.faultCode
    puts e.faultString
  end
end

product = lookup_upc('018787765654')
product['description']              
product['size']                     

lookup_upc('no such UPC')