Class | XMLRPC::Create
In: | xmlrpc/create.rb
Parent: | Object

### Methods

methodCall methodResponse new

### Public Class methods

new(xml_writer = nil)

[Source]

    # File xmlrpc/create.rb, line 105
        def initialize(xml_writer = nil)
          @writer = xml_writer || Config::DEFAULT_WRITER.new
        end

### Public Instance methods

methodCall(name, *params)

[Source]

    # File xmlrpc/create.rb, line 110
        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 do |param|
            @writer.ele("param", conv2value(param))
          end

          tree = @writer.document(
                   @writer.pi("xml", 'version="1.0"'),
                   @writer.ele("methodCall",
                     @writer.tag("methodName", name),
                     @writer.ele("params", *parameter)
                   )
                 )

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

methodResponse(is_ret, *params)

generates a XML-RPC methodResponse document

if is_ret == false then the params array must contain only one element, which is a structure of a fault return-value.

if is_ret == true then a normal return-value of all the given params is created.

[Source]

    # File xmlrpc/create.rb, line 144
        def methodResponse(is_ret, *params)

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

            resp = [@writer.ele("params", *resp)]
          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.pi("xml", 'version="1.0"'),
                   @writer.ele("methodResponse", resp)
                 )

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

[Validate]