Listing 4. xmlrpc-lookup-client.rb

#!/usr/bin/ruby

require 'xmlrpc/client'

# Get the ISBNs from the command line
isbns = ARGV

# Connect to the server
server = XMLRPC::Client.new2("http://127.0.0.1:8080/", nil, 120)

# Send the ISBNs, and catch any faults that we find
begin
  results = server.call("atf.books", isbns)
rescue XMLRPC::FaultException => e
  puts "Error:"
  puts e.faultCode
  puts e.faultString
end

# Display the results!
results.each do |result|
  result.each do |key, value|
    if key == "ISBN"
      puts "ISBN: #{value}\n"
    else
      puts "\t#{key}: #{value}\n"
    end
  end
end