# XMLRPC::Client (Class)

In: | xmlrpc/client.rb
Parent: | Object

## Methods

call call2 call2_async call_async multicall multicall2 multicall2_async multicall_async new new2 new3 password= proxy proxy2 proxy2_async proxy_async timeout= user=

## Constants

USER_AGENT | = | "XMLRPC::Client (Ruby #{RUBY_VERSION})"

## Attributes

cookie | [RW] | Cookie support
http_header_extra | [RW] | add additional HTTP headers to the request
http_last_response | [R] | makes last HTTP response accessible
password | [R] |
timeout | [R] |
user | [R] |

## Classes and Modules

Class XMLRPC::Client::Proxy

## Included Modules

ParserWriterChooseMixin ParseContentType

## Public Class methods

new(host=nil, path=nil, port=nil, proxy_host=nil, proxy_port=nil, user=nil, password=nil, use_ssl=nil, timeout=nil)

Constructors ——————————————————————-

[Source]

    # File xmlrpc/client.rb, line 291
        def initialize(host=nil, path=nil, port=nil, proxy_host=nil, proxy_port=nil,
                       user=nil, password=nil, use_ssl=nil, timeout=nil)

          @http_header_extra = nil
          @http_last_response = nil
          @cookie = nil

          @host       = host || "localhost"
          @path       = path || "/RPC2"
          @proxy_host = proxy_host
          @proxy_port = proxy_port
          @proxy_host ||= 'localhost' if @proxy_port != nil
          @proxy_port ||= 8080 if @proxy_host != nil
          @use_ssl    = use_ssl || false
          @timeout    = timeout || 30

          if use_ssl
            require "net/https"
            @port = port || 443
          else
            @port = port || 80
          end

          @user, @password = user, password

          set_auth

          # convert ports to integers

          @port = @port.to_i if @port != nil
          @proxy_port = @proxy_port.to_i if @proxy_port != nil

          # HTTP object for synchronous calls

          Net::HTTP.version_1_2
          @http = Net::HTTP.new(@host, @port, @proxy_host, @proxy_port)
          @http.use_ssl = @use_ssl if @use_ssl
          @http.read_timeout = @timeout
          @http.open_timeout = @timeout

          @parser = nil
          @create = nil
        end

new2(uri, proxy=nil, timeout=nil)

[Source]

    # File xmlrpc/client.rb, line 334
        def self.new2(uri, proxy=nil, timeout=nil)
          if match = /^([^:]+):\/\/(([^@]+)@)?([^\/]+)(\/.*)?$/.match(uri)
            proto = match[1]
            user, passwd = (match[3] || "").split(":")
            host, port = match[4].split(":")
            path = match[5]

            if proto != "http" and proto != "https"
              raise "Wrong protocol specified. Only http or https allowed!"
            end

          else
            raise "Wrong URI as parameter!"
          end

          proxy_host, proxy_port = (proxy || "").split(":")

          self.new(host, path, port, proxy_host, proxy_port, user, passwd, (proto == "https"), timeout)
        end

new3(hash={})

[Source]

    # File xmlrpc/client.rb, line 355
        def self.new3(hash={})

          # convert all keys into lowercase strings

          h = {}
          hash.each { |k,v| h[k.to_s.downcase] = v }

          self.new(h['host'], h['path'], h['port'], h['proxy_host'], h['proxy_port'], h['user'], h['password'],
                   h['use_ssl'], h['timeout'])
        end

## Public Instance methods

timeout=(new_timeout)

[Source]

    # File xmlrpc/client.rb, line 380
        def timeout=(new_timeout)
          @timeout = new_timeout
          @http.read_timeout = @timeout
          @http.open_timeout = @timeout
        end

user=(new_user)

[Source]

    # File xmlrpc/client.rb, line 386
        def user=(new_user)
          @user = new_user
          set_auth
        end

password=(new_password)

[Source]

    # File xmlrpc/client.rb, line 391
        def password=(new_password)
          @password = new_password
          set_auth
        end

call(method, *args)

Call methods —————————————————————

[Source]

    # File xmlrpc/client.rb, line 398
        def call(method, *args)
          ok, param = call2(method, *args)
          if ok
            param
          else
            raise param
          end
        end

call2(method, *args)

[Source]

    # File xmlrpc/client.rb, line 407
        def call2(method, *args)
          request = create().methodCall(method, *args)
          data = do_rpc(request, false)
          parser().parseMethodResponse(data)
        end

call_async(method, *args)

[Source]

    # File xmlrpc/client.rb, line 413
        def call_async(method, *args)
          ok, param = call2_async(method, *args)
          if ok
            param
          else
            raise param
          end
        end

call2_async(method, *args)

[Source]

    # File xmlrpc/client.rb, line 422
        def call2_async(method, *args)
          request = create().methodCall(method, *args)
          data = do_rpc(request, true)
          parser().parseMethodResponse(data)
        end

multicall(*methods)

Multicall methods —————————————————————

[Source]

    # File xmlrpc/client.rb, line 431
        def multicall(*methods)
          ok, params = multicall2(*methods)
          if ok
            params
          else
            raise params
          end
        end

multicall2(*methods)

[Source]

    # File xmlrpc/client.rb, line 440
        def multicall2(*methods)
          gen_multicall(methods, false)
        end

multicall_async(*methods)

[Source]

    # File xmlrpc/client.rb, line 444
        def multicall_async(*methods)
          ok, params = multicall2_async(*methods)
          if ok
            params
          else
            raise params
          end
        end

multicall2_async(*methods)

[Source]

    # File xmlrpc/client.rb, line 453
        def multicall2_async(*methods)
          gen_multicall(methods, true)
        end

proxy(prefix, *args)

Proxy generating methods ——————————————

[Source]

    # File xmlrpc/client.rb, line 460
        def proxy(prefix, *args)
          Proxy.new(self, prefix, args, :call)
        end

proxy2(prefix, *args)

[Source]

    # File xmlrpc/client.rb, line 464
        def proxy2(prefix, *args)
          Proxy.new(self, prefix, args, :call2)
        end

proxy_async(prefix, *args)

[Source]

    # File xmlrpc/client.rb, line 468
        def proxy_async(prefix, *args)
          Proxy.new(self, prefix, args, :call_async)
        end

proxy2_async(prefix, *args)

[Source]

    # File xmlrpc/client.rb, line 472
        def proxy2_async(prefix, *args)
          Proxy.new(self, prefix, args, :call2_async)
        end

[Validate]