Method: XMLRPC::Create#methodResponse

Defined in:
lib/xmpp4r/rpc/helper/xmlrpcaddons.rb

#methodResponse(is_ret, *params) ⇒ Object

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



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/xmpp4r/rpc/helper/xmlrpcaddons.rb', line 43

def methodResponse(is_ret, *params)

  if is_ret
    begin
      resp = params.collect do |param|
        @writer.ele("param", conv2value(param))
      end

      resp = [@writer.ele("params", *resp)]
    rescue Exception => e
      error = XMLRPC::FaultException.new(XMLRPC::BasicServer::ERR_UNCAUGHT_EXCEPTION, "Uncaught exception '#{e.message}' serialising params into response")
      resp = @writer.ele("fault", conv2value(error.to_h))
    end
  else
    if params.size != 1 or params[0] === XMLRPC::FaultException
      raise ArgumentError, "no valid fault-structure given"
    end
    resp = @writer.ele("fault", conv2value(params[0].to_h))
  end

  tree = @writer.document(@writer.ele("methodResponse", resp))
  @writer.document_to_str(tree) + "\n"
end