XML-RPC (Remote Procedure Calls)


/ Published in: Ruby
Save to your folder(s)

RPC is an alternative to SOAP or REST. If you find a webservice that has an implementation, here is are a few ways to make it work using Ruby


Copy this code and paste it in your HTML
  1. #Example 1: Find a State in a Specific Sort Order
  2. #A. Import the XMLPRC Library (Thanx Michael Nuemann)
  3. require 'xmlrpc/client'
  4. #B. You have to define the web address that will run the RPC against
  5. server = XMLRPC::Client.new2('http://betty.userland.com/RPC2')
  6. puts server.call('examples.getStateName', 1)
  7.  
  8. #Example 2: Find product information based on a UPC number
  9. #C. You have to define the web address that will run the RPC against
  10. server = XMLRPC::Client.new2('http://dev.upcdatabase.com/rpc')
  11. #D. lookupUPC is a method, the number is a product UPC
  12. @item = server.call('lookupUPC', '720642442524')
  13. #E. Store the result in an array
  14. p @item
  15. puts "Description :: " + @item["description"]
  16. puts "Type :: " + @item["size"]

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.