123456789_123456789_123456789_123456789_123456789_

Class: XMLRPC::Client::Proxy

Relationships & Source Files
Inherits: Object
Defined in: lib/xmlrpc/client.rb

Overview

XML-RPC calls look nicer!

You can call any method onto objects of that class - the object handles #method_missing and will forward the method call to a XML-RPC server.

Don’t use this class directly, instead use the public instance method #proxy or #proxy2.

require "xmlrpc/client"

server = XMLRPC::Client.new("www.ruby-lang.org", "/RPC2", 80)

michael  = server.proxy("michael")
michael2 = server.proxy("michael", 4)

# both calls should return the same value '9'.
p michael.add(4,5)
p michael2.add(5)

Class Method Summary

Instance Method Summary

Constructor Details

.new(server, prefix, args = [], meth = :call, delim = ".") ⇒ Proxy

Creates an object which provides #method_missing.

The given server must be an instance of ::XMLRPC::Client, which is the XML-RPC server to be used for a XML-RPC call.

prefix and delim will be prepended to the method name called onto this object.

An optional parameter meth is the method to use for a RPC. It can be either, call, call2, call_async, call2_async

args are arguments which are automatically given to every XML-RPC call before being provided through #method_missing.

[ GitHub ]

  
# File 'lib/xmlrpc/client.rb', line 607

def initialize(server, prefix, args=[], meth=:call, delim=".")
  @server = server
  @prefix = prefix ? prefix + delim : ""
  @args   = args
  @meth   = meth
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(mid, *args)

Every method call is forwarded to the XML-RPC server defined in XMLRPC::Client::Proxy#new.

Note: Inherited methods from class Object cannot be used as XML-RPC names, because they get around method_missing.

[ GitHub ]

  
# File 'lib/xmlrpc/client.rb', line 619

def method_missing(mid, *args)
  pre = @prefix + mid.to_s
  arg = @args + args
  @server.send(@meth, pre, *arg)
end