| Class | XMLRPC::Create |
| In: |
lib/xmpp4r/rpc/helper/xmlrpcaddons.rb
|
| Parent: | Object |
create a Method Call
| name: | [String] name of the method |
| params: | [Array] params of the method as a array |
# File lib/xmpp4r/rpc/helper/xmlrpcaddons.rb, line 18
18: def methodCall(name, *params)
19: name = name.to_s
20:
21: if name !~ /[a-zA-Z0-9_.:\/]+/
22: raise ArgumentError, "Wrong XML-RPC method-name"
23: end
24:
25: parameter = params.collect { |param|
26: @writer.ele("param", conv2value(param))
27: }
28:
29: tree = @writer.document(
30: @writer.ele("methodCall",
31: @writer.tag("methodName", name),
32: @writer.ele("params", *parameter)
33: )
34: )
35:
36: @writer.document_to_str(tree) + "\n"
37: end
create a response to a method call
| is_ret: | [TrueClass] is this a return (true) or a error (false) |
| params: | [Array] a array of params |
# File lib/xmpp4r/rpc/helper/xmlrpcaddons.rb, line 43
43: def methodResponse(is_ret, *params)
44:
45: if is_ret
46: begin
47: resp = params.collect do |param|
48: @writer.ele("param", conv2value(param))
49: end
50:
51: resp = [@writer.ele("params", *resp)]
52: rescue Exception => e
53: error = XMLRPC::FaultException.new(XMLRPC::BasicServer::ERR_UNCAUGHT_EXCEPTION, "Uncaught exception '#{e.message}' serialising params into response")
54: resp = @writer.ele("fault", conv2value(error.to_h))
55: end
56: else
57: if params.size != 1 or params[0] === XMLRPC::FaultException
58: raise ArgumentError, "no valid fault-structure given"
59: end
60: resp = @writer.ele("fault", conv2value(params[0].to_h))
61: end
62:
63: tree = @writer.document(@writer.ele("methodResponse", resp))
64: @writer.document_to_str(tree) + "\n"
65: end