Class: XmlRPCBase

Inherits:
Object
  • Object
show all
Defined in:
lib/o3d3xx/xml_rpc_base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ XmlRPCBase

Initializes XMLRPC connection. Needs connection and Request parameters via given settings hash

Parameters:

  • settings (defaults to: {})

    hash of settings: :host, :port, :path



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/o3d3xx/xml_rpc_base.rb', line 26

def initialize(settings={})
  raise 'No host name given !' if settings[:host].nil?
  raise 'No port given !' if settings[:port].nil?
  raise 'No endpoint given !' if settings[:path].nil?
  @config = {
    :host => settings[:host],
    :port => settings[:port],
    :path => '/api/rpc/v1/' + settings[:path]
  }

  @rpc_cl = XMLRPC::Client.new(@config[:host],
                               @config[:path],
                               @config[:port], nil, nil,
                               nil, nil, nil, 20)   # 20 seconds connection timeout
  #dump
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object

Calls any method via xmlrpc



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/o3d3xx/xml_rpc_base.rb', line 45

def method_missing(meth, *args)
  arg = args
  begin
    @rpc_cl.call_async(meth.to_s, *arg)
  rescue XMLRPC::FaultException => e
    if e.message.include? 'method not found'
      super
    else
      raise
    end
  end
end

Instance Attribute Details

#rpc_clObject (readonly)

Returns the value of attribute rpc_cl.



19
20
21
# File 'lib/o3d3xx/xml_rpc_base.rb', line 19

def rpc_cl
  @rpc_cl
end

Instance Method Details

#dumpObject

Dumps configuration



66
67
68
69
70
# File 'lib/o3d3xx/xml_rpc_base.rb', line 66

def dump
  puts "Host: #{@config[:host]}"
  puts "Port: #{@config[:port]}"
  puts "URL : #{@config[:path]}"
end

#getConfigObject

Returns configuration object



60
61
62
# File 'lib/o3d3xx/xml_rpc_base.rb', line 60

def getConfig
  return @config
end