Class: TestLink::ApiLink

Inherits:
Object
  • Object
show all
Defined in:
lib/test_link/api_link.rb

Constant Summary collapse

@@remote_methods =
{}
@@adapters =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, key) ⇒ ApiLink

Returns a new instance of ApiLink.



24
25
26
27
28
# File 'lib/test_link/api_link.rb', line 24

def initialize(url, key)
  @url = url
  @key = key
  @client = XMLRPC::Client.new2 self.api_url
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/test_link/api_link.rb', line 44

def method_missing(symbol, *args)
  command = @@remote_methods[symbol]
  adapter = @@adapters[symbol]
  return super(symbol, args) if command.nil?
  command_args = args.first || {}
  command.reset_arguments_hash command_args
  adapter.response = command.execute self
  adapter.adapt
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



21
22
23
# File 'lib/test_link/api_link.rb', line 21

def client
  @client
end

#keyObject

Returns the value of attribute key.



20
21
22
# File 'lib/test_link/api_link.rb', line 20

def key
  @key
end

#urlObject (readonly)

Returns the value of attribute url.



21
22
23
# File 'lib/test_link/api_link.rb', line 21

def url
  @url
end

Class Method Details

.adapter_for(command_name) ⇒ Object



58
59
60
# File 'lib/test_link/api_link.rb', line 58

def self.adapter_for(command_name)
  @@adapters[command_name.to_sym]
end

.remote_method(klass) ⇒ Object



34
35
36
37
# File 'lib/test_link/api_link.rb', line 34

def self.remote_method(klass)
  method_name = klass.command_name.to_sym
  @@remote_methods[method_name] = klass.new
end

.set_adapter_for(command_name, klass) ⇒ Object



54
55
56
# File 'lib/test_link/api_link.rb', line 54

def self.set_adapter_for command_name, klass
  @@adapters[command_name.to_sym] = klass.new
end

Instance Method Details

#api_urlObject



30
31
32
# File 'lib/test_link/api_link.rb', line 30

def api_url()
  @url + '/lib/api/xmlrpc.php'
end

#respond_to_missing?(symbol, include_private) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
# File 'lib/test_link/api_link.rb', line 39

def respond_to_missing?(symbol, include_private)
  return true if @@remote_methods.include? symbol
  super symbol, include_private
end