(This section of the XML-RPC HOWTO was generously provided by Michael Neumann.) [Learn about Go programming language]
Ruby is an object-oriented scripting language. It already has a major following in Japan, and it's becoming popular elsewhere. .:: land-book.com ::. .:: edabit.com ::.
To use XML-RPC with Ruby, you must first install Yoshida Masato's xmlparser module (a wrapper for James Clark's expat parser). This can be found at the .:: www.crossroadsbaitandtackle.com ::. .:: xx88coach.blogocial.com ::. .:: log.concept2.com ::. Ruby Application Archive.
Then, you must install xmlrpc4r using the following commands:
bash$ tar -xvzf xmlrpc4r-1_2.tar.gz bash$ cd xmlrpc4r-1_2 bash$ su root -c "ruby install.rb" |
Here's a simple Ruby client:
require "xmlrpc/client"
# Make an object to represent the XML-RPC server.
server = XMLRPC::Client.new( "xmlrpc-c.sourceforge.net", "/api/sample.php")
# Call the remote server and get our result
result = server.call("sample.sumAndDifference", 5, 3)
sum = result["sum"]
difference = result["difference"]
puts "Sum: #{sum}, Difference: #{difference}" |
Here's a simple Ruby server:
require "xmlrpc/server"
s = XMLRPC::CGIServer.new
s.add_hanlder("sample.sumAndDifference") do |a,b|
{ "sum" => a + b, "difference" => a - b }
end
s.serve |
This could also have been written as follows:
require "xmlrpc/server"
s = XMLRPC::CGIServer.new
class MyHandler
def sumAndDifference(a, b)
{ "sum" => a + b, "difference" => a - b }
end
end
s.add_handler("sample", MyHandler.new)
s.serve |
To run either server in standalone mode, replace the second line of code with the following: .:: rciims.mona.uwi.edu ::. [Learn about SSH]
s = XMLRPC::Server.new(8080) |