Class: F5::Icontrol::API
- Inherits:
-
Object
- Object
- F5::Icontrol::API
- Defined in:
- lib/f5/icontrol/api.rb
Instance Attribute Summary collapse
-
#api_path ⇒ Object
Returns the value of attribute api_path.
Instance Method Summary collapse
-
#initialize(api_path = nil, **params) ⇒ API
constructor
A new instance of API.
- #method_missing(method, args = nil, &block) ⇒ Object
Constructor Details
#initialize(api_path = nil, **params) ⇒ API
Returns a new instance of API.
6 7 8 9 10 11 12 13 |
# File 'lib/f5/icontrol/api.rb', line 6 def initialize(api_path = nil, **params) @params = params.dup @username = params[:username] @password = params[:password] @hostname = params[:host] || params[:hostname] @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
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/f5/icontrol/api.rb', line 15 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 args end end response.to_hash[response_key][:return] elsif supported_path? append_path(method) self.class.new append_path(method), @params else raise NameError, "#{method} is not supported by #{@api_path}" end end |
Instance Attribute Details
#api_path ⇒ Object
Returns the value of attribute api_path.
4 5 6 |
# File 'lib/f5/icontrol/api.rb', line 4 def api_path @api_path end |