You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
605 B

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