class Jabber::RPC::Client

XMLRPC Client

Attributes

my_jid[RW]

Public Class Methods

new(stream,jid) click to toggle source

xmppstream

stream
Stream

jid where you want to send the rpc requests to

jid
JID

rpcserver@jabberserver/ressource

# File lib/xmpp4r/rpc/helper/client.rb, line 28
def initialize(stream,jid)
  @jid    = JID.new(jid)
  @my_jid = stream.jid
  @stream =  stream
  @parser = nil
  @create = XMLRPC::Create.new
end

Public Instance Methods

call(method, *args) click to toggle source
# File lib/xmpp4r/rpc/helper/client.rb, line 44
def call(method, *args)
  ok, param = call2(method, *args)
  if ok
    param
  else
    raise param
  end
end
call2(method, *args) click to toggle source
# File lib/xmpp4r/rpc/helper/client.rb, line 53
def call2(method, *args)
  request = @create.methodCall(method, *args)
  data = do_rpc(request)
  parser().parseMethodResponse(data)
end
do_rpc(xmlrpc) click to toggle source
# File lib/xmpp4r/rpc/helper/client.rb, line 78
def do_rpc(xmlrpc)
  iq = Iq.new(:set, @jid)
  iq.from = @my_jid
  iq.id = IdGenerator::generate_id
  rpcquery = iq.add(IqQueryRPC.new)
  rpcquery.typed_add(xmlrpc)

  result = nil
  @stream.send_with_id(iq) do |iqreply|
    if iqreply.query.kind_of?(IqQueryRPC)
      result = iqreply.query.to_s
    end
  end

  result
end
method_missing(methodname, *args) click to toggle source

automatically trys to find a method thanx to eric cestari :)

# File lib/xmpp4r/rpc/helper/client.rb, line 39
def method_missing(methodname, *args)
  send("call", methodname,*args)
end
multicall(*methods) click to toggle source

adds multi rpcalls to the query

methods
Array
# File lib/xmpp4r/rpc/helper/client.rb, line 62
def multicall(*methods)
  ok, params = multicall2(*methods)
  if ok
    params
  else
    raise params
  end
end
multicall2(*methods) click to toggle source

generate a multicall

methods
Array
# File lib/xmpp4r/rpc/helper/client.rb, line 74
def multicall2(*methods)
  gen_multicall(methods)
end

Private Instance Methods

gen_multicall(methods=[]) click to toggle source
# File lib/xmpp4r/rpc/helper/client.rb, line 97
def gen_multicall(methods=[])
  ok, params = call2("system.multicall",
    methods.collect { |m|
      {
        'methodName' => m[0],
        'params' => m[1..-1]
      }
    }
  )

  if ok
    params = params.collect{ |param|
      if param.is_a? Array
        param[0]
      elsif param.is_a? Hash
        XMLRPC::FaultException.new(param["faultCode"], param["faultString"])
      else
        raise "Wrong multicall return value"
      end
    }
  end

  return ok, params
end