| Class | Jabber::RPC::Client |
| In: |
lib/xmpp4r/rpc/helper/client.rb
|
| Parent: | Object |
| my_jid | [RW] |
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
28: def initialize(stream,jid)
29: @jid = JID.new(jid)
30: @my_jid = stream.jid
31: @stream = stream
32: @parser = nil
33: @create = XMLRPC::Create.new
34: end
# File lib/xmpp4r/rpc/helper/client.rb, line 36
36: def call(method, *args)
37: ok, param = call2(method, *args)
38: if ok
39: param
40: else
41: raise param
42: end
43: end
# File lib/xmpp4r/rpc/helper/client.rb, line 45
45: def call2(method, *args)
46: request = @create.methodCall(method, *args)
47: data = do_rpc(request)
48: parser().parseMethodResponse(data)
49: end
# File lib/xmpp4r/rpc/helper/client.rb, line 70
70: def do_rpc(xmlrpc)
71: iq = Iq.new(:set, @jid)
72: iq.from = @my_jid
73: iq.id = IdGenerator::generate_id
74: rpcquery = iq.add(IqQueryRPC.new)
75: rpcquery.typed_add(xmlrpc)
76:
77: result = nil
78: @stream.send_with_id(iq) { |iqreply|
79: if iqreply.type == :result and iqreply.query.kind_of?(IqQueryRPC)
80: result = iqreply.query.to_s
81: true
82: else
83: false
84: end
85: }
86:
87: result
88: end
adds multi rpcalls to the query
| methods: | [Array] |
# File lib/xmpp4r/rpc/helper/client.rb, line 54
54: def multicall(*methods)
55: ok, params = multicall2(*methods)
56: if ok
57: params
58: else
59: raise params
60: end
61: end
# File lib/xmpp4r/rpc/helper/client.rb, line 92
92: def gen_multicall(methods=[])
93: ok, params = call2("system.multicall",
94: methods.collect { |m| {'methodName' => m[0], 'params' => m[1..-1]} }
95: )
96:
97: if ok
98: params = params.collect{ |param|
99: if param.is_a? Array
100: param[0]
101: elsif param.is_a? Hash
102: XMLRPC::FaultException.new(param["faultCode"], param["faultString"])
103: else
104: raise "Wrong multicall return value"
105: end
106: }
107: end
108:
109: return ok, params
110: end