Class: XMLRPC::Create

Inherits:
Object show all
Defined in:
lib/gems/xmpp4r-0.4/lib/xmpp4r/rpc/helper/xmlrpcaddons.rb

Instance Method Summary collapse

Instance Method Details

#methodCall(name, *params) ⇒ Object

create a Method Call

name
String

name of the method

params
Array

params of the method as a array



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gems/xmpp4r-0.4/lib/xmpp4r/rpc/helper/xmlrpcaddons.rb', line 18

def methodCall(name, *params)
  name = name.to_s

  if name !~ /[a-zA-Z0-9_.:\/]+/
    raise ArgumentError, "Wrong XML-RPC method-name"
  end

  parameter = params.collect { |param|
    @writer.ele("param", conv2value(param))
  }

  tree = @writer.document(
           @writer.ele("methodCall",
             @writer.tag("methodName", name),
             @writer.ele("params", *parameter)
           )
         )

  @writer.document_to_str(tree) + "\n"
end

#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/gems/xmpp4r-0.4/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