Class: F5::Icontrol::RAPI
- Inherits:
-
Object
- Object
- F5::Icontrol::RAPI
show all
- Includes:
- Enumerable
- Defined in:
- lib/f5/icontrol/rapi.rb,
lib/f5/icontrol/rapi/resource.rb
Defined Under Namespace
Classes: Resource
Instance Method Summary
collapse
Constructor Details
#initialize(method_chain = nil, **args) ⇒ RAPI
Returns a new instance of RAPI.
9
10
11
12
|
# File 'lib/f5/icontrol/rapi.rb', line 9
def initialize(method_chain = nil, **args)
@method_chain = method_chain || ''
@args = args
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
55
56
57
58
|
# File 'lib/f5/icontrol/rapi.rb', line 55
def method_missing(method, *args, &block)
new_method_chain = @method_chain == '/' ? '': "#{@method_chain}/"
F5::Icontrol::RAPI.new("#{new_method_chain}#{method}", @args)
end
|
Instance Method Details
#create(options = {}) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/f5/icontrol/rapi.rb', line 43
def create(options = {})
response = RestClient::Request.execute(method: :post,
url: url,
user: @args[:username],
password: @args[:password],
verify_ssl: OpenSSL::SSL::VERIFY_NONE,
payload: options.to_json,
headers: { "content-type" => "application/json" }
)
JSON.parse response.body
end
|
#each(&block) ⇒ Object
60
61
62
|
# File 'lib/f5/icontrol/rapi.rb', line 60
def each(&block)
get_collection.each &block
end
|
#get_collection ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/f5/icontrol/rapi.rb', line 31
def get_collection
response = RestClient::Request.execute(method: :get,
url: "#{url}/",
user: @args[:username],
password: @args[:password],
verify_ssl: OpenSSL::SSL::VERIFY_NONE
)
objects = JSON.parse response.body
objects['items'].map { |r| Resource.new r, @args }
end
|
#load(resource = nil) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/f5/icontrol/rapi.rb', line 14
def load(resource = nil)
tail = resource.nil? ? '' : "/#{resource}"
response = RestClient::Request.execute(method: :get,
url: "#{url}#{tail}",
user: @args[:username],
password: @args[:password],
verify_ssl: OpenSSL::SSL::VERIFY_NONE
)
object = JSON.parse response.body
if object.has_key? 'items'
object['items'].map { |r| Resource.new r, @args }
else
Resource.new object, @args
end
end
|