Class: F5::Icontrol::API

Inherits:
Object
  • Object
show all
Defined in:
lib/f5/icontrol/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_path = nil) ⇒ API

Returns a new instance of API.



6
7
8
9
10
11
12
# File 'lib/f5/icontrol/api.rb', line 6

def initialize(api_path = nil)
  @username="a"
  @password="b"
  @hostname="xxx"
  @client_cache = {}
  @api_path = api_path
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, args = nil, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/f5/icontrol/api.rb', line 14

def method_missing(method, args = nil, &block)
  if terminal_node? && supported_method?(method)
      response_key = "#{method.to_s}_response".to_sym

      response = client.call(method) do
        if args
          message args
        end
      end

      response.to_hash[response_key][:return]

  elsif supported_path? append_path(method)
    self.class.new append_path(method)
  else
    raise NameError, "#{method} is not supported by #{@api_path}"
  end
end

Instance Attribute Details

#api_pathObject

Returns the value of attribute api_path.



4
5
6
# File 'lib/f5/icontrol/api.rb', line 4

def api_path
  @api_path
end