Class: XMLRPC::Client

Inherits:
Object show all
Includes:
ParseContentType, ParserWriterChooseMixin
Defined in:
lib/xmlrpc/client.rb

Defined Under Namespace

Classes: Proxy

Constant Summary

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

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from ParseContentType

#parse_content_type

Methods included from ParserWriterChooseMixin

#set_parser, #set_writer

Constructor Details

- (Client) initialize(host = nil, path = nil, port = nil, proxy_host = nil, proxy_port = nil, user = nil, password = nil, use_ssl = nil, timeout = nil)

Constructors -------------------------------------------------------------------



295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/xmlrpc/client.rb', line 295

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

Instance Attribute Details

Cookie support



386
387
388
# File 'lib/xmlrpc/client.rb', line 386

def cookie
  @cookie
end

- (Object) http_header_extra

add additional HTTP headers to the request



380
381
382
# File 'lib/xmlrpc/client.rb', line 380

def http_header_extra
  @http_header_extra
end

- (Object) http_last_response (readonly)

makes last HTTP response accessible



383
384
385
# File 'lib/xmlrpc/client.rb', line 383

def http_last_response
  @http_last_response
end

- (Object) password

Returns the value of attribute password



389
390
391
# File 'lib/xmlrpc/client.rb', line 389

def password
  @password
end

- (Object) timeout

Returns the value of attribute timeout



389
390
391
# File 'lib/xmlrpc/client.rb', line 389

def timeout
  @timeout
end

- (Object) user

Returns the value of attribute user



389
390
391
# File 'lib/xmlrpc/client.rb', line 389

def user
  @user
end

Class Method Details

+ (Object) new2(uri, proxy = nil, timeout = nil) Also known as: new_from_uri



340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/xmlrpc/client.rb', line 340

def 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

+ (Object) new3(hash = {}) Also known as: new_from_hash



362
363
364
365
366
367
368
369
370
# File 'lib/xmlrpc/client.rb', line 362

def 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

Instance Method Details

- (Object) call(method, *args)

Call methods --------------------------------------------------------------



409
410
411
412
413
414
415
416
# File 'lib/xmlrpc/client.rb', line 409

def call(method, *args)
  ok, param = call2(method, *args)
  if ok
    param
  else
    raise param
  end
end

- (Object) call2(method, *args)



418
419
420
421
422
# File 'lib/xmlrpc/client.rb', line 418

def call2(method, *args)
  request = create().methodCall(method, *args)
  data = do_rpc(request, false)
  parser().parseMethodResponse(data)
end

- (Object) call2_async(method, *args)



433
434
435
436
437
# File 'lib/xmlrpc/client.rb', line 433

def call2_async(method, *args)
  request = create().methodCall(method, *args)
  data = do_rpc(request, true)
  parser().parseMethodResponse(data)
end

- (Object) call_async(method, *args)



424
425
426
427
428
429
430
431
# File 'lib/xmlrpc/client.rb', line 424

def call_async(method, *args)
  ok, param = call2_async(method, *args)
  if ok
    param
  else
    raise param
  end
end

- (Object) multicall(*methods)

Multicall methods --------------------------------------------------------------



442
443
444
445
446
447
448
449
# File 'lib/xmlrpc/client.rb', line 442

def multicall(*methods)
  ok, params = multicall2(*methods)
  if ok
    params
  else
    raise params
  end
end

- (Object) multicall2(*methods)



451
452
453
# File 'lib/xmlrpc/client.rb', line 451

def multicall2(*methods)
  gen_multicall(methods, false)
end

- (Object) multicall2_async(*methods)



464
465
466
# File 'lib/xmlrpc/client.rb', line 464

def multicall2_async(*methods)
  gen_multicall(methods, true)
end

- (Object) multicall_async(*methods)



455
456
457
458
459
460
461
462
# File 'lib/xmlrpc/client.rb', line 455

def multicall_async(*methods)
  ok, params = multicall2_async(*methods)
  if ok
    params
  else
    raise params
  end
end

- (Object) proxy(prefix = nil, *args)

Proxy generating methods ------------------------------------------



471
472
473
# File 'lib/xmlrpc/client.rb', line 471

def proxy(prefix=nil, *args)
  Proxy.new(self, prefix, args, :call)
end

- (Object) proxy2(prefix = nil, *args)



475
476
477
# File 'lib/xmlrpc/client.rb', line 475

def proxy2(prefix=nil, *args)
  Proxy.new(self, prefix, args, :call2)
end

- (Object) proxy2_async(prefix = nil, *args)



483
484
485
# File 'lib/xmlrpc/client.rb', line 483

def proxy2_async(prefix=nil, *args)
  Proxy.new(self, prefix, args, :call2_async)
end

- (Object) proxy_async(prefix = nil, *args)



479
480
481
# File 'lib/xmlrpc/client.rb', line 479

def proxy_async(prefix=nil, *args)
  Proxy.new(self, prefix, args, :call_async)
end