Class: Infoblox::Resource
- Inherits:
-
Object
- Object
- Infoblox::Resource
show all
- Defined in:
- lib/infoblox/resource.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attrs = {}) ⇒ Resource
Returns a new instance of Resource.
98
99
100
101
102
|
# File 'lib/infoblox/resource.rb', line 98
def initialize(attrs={})
attrs.each do |k,v|
self.send("#{k}=", v)
end
end
|
Instance Attribute Details
#_ref ⇒ Object
Returns the value of attribute _ref.
3
4
5
|
# File 'lib/infoblox/resource.rb', line 3
def _ref
@_ref
end
|
Class Method Details
._return_fields ⇒ Object
53
54
55
|
# File 'lib/infoblox/resource.rb', line 53
def self._return_fields
self.remote_attrs.join(",")
end
|
.all ⇒ Object
Return an array of all records for this resource.
64
65
66
67
68
|
# File 'lib/infoblox/resource.rb', line 64
def self.all
JSON.parse(connection.get(resource_uri, default_params).body).map do |item|
new(item)
end
end
|
.connection ⇒ Object
86
87
88
|
# File 'lib/infoblox/resource.rb', line 86
def self.connection
@@connection
end
|
.connection=(con) ⇒ Object
90
91
92
|
# File 'lib/infoblox/resource.rb', line 90
def self.connection=(con)
@@connection = con
end
|
.default_params ⇒ Object
57
58
59
|
# File 'lib/infoblox/resource.rb', line 57
def self.default_params
{:_return_fields => self._return_fields}
end
|
.find(params) ⇒ Object
Find resources with query parameters.
Example: return extensible attributes for every resource.
{"_return_fields" => "extensible_attributes"}
Example: filter resources by name.
{"name~" => "foo.*bar"}
79
80
81
82
83
84
|
# File 'lib/infoblox/resource.rb', line 79
def self.find(params)
params = default_params.merge(params)
JSON.parse(connection.get(resource_uri, params).body).map do |item|
new(item)
end
end
|
.remote_attr_accessor(*args) ⇒ Object
Define a writeable remote attribute, i.e. one that should show up in post / put operations.
13
14
15
16
17
18
|
# File 'lib/infoblox/resource.rb', line 13
def self.remote_attr_accessor(*args)
args.each do |a|
attr_accessor a
remote_attrs << a
end
end
|
.remote_attr_writer(*args) ⇒ Object
Define a remote attribute that is write-only
34
35
36
37
38
39
|
# File 'lib/infoblox/resource.rb', line 34
def self.remote_attr_writer(*args)
args.each do |a|
attr_accessor a
remote_write_only_attrs << a
end
end
|
.remote_attrs ⇒ Object
41
42
43
|
# File 'lib/infoblox/resource.rb', line 41
def self.remote_attrs
@remote_attrs ||= []
end
|
.remote_post_accessor(*args) ⇒ Object
Define a remote attribute that can only be sent during a POST operation.
24
25
26
27
28
29
|
# File 'lib/infoblox/resource.rb', line 24
def self.remote_post_accessor(*args)
args.each do |a|
attr_accessor a
remote_post_attrs << a
end
end
|
.remote_post_attrs ⇒ Object
49
50
51
|
# File 'lib/infoblox/resource.rb', line 49
def self.remote_post_attrs
@remote_post_attrs ||= []
end
|
.remote_write_only_attrs ⇒ Object
45
46
47
|
# File 'lib/infoblox/resource.rb', line 45
def self.remote_write_only_attrs
@remote_write_only_attrs ||= []
end
|
.resource_uri ⇒ Object
94
95
96
|
# File 'lib/infoblox/resource.rb', line 94
def self.resource_uri
BASE_PATH + self.wapi_object
end
|
.wapi_object(obj = nil) ⇒ Object
5
6
7
|
# File 'lib/infoblox/resource.rb', line 5
def self.wapi_object(obj=nil)
obj.nil? ? @wapi_object : @wapi_object = obj
end
|
Instance Method Details
#delete ⇒ Object
110
111
112
|
# File 'lib/infoblox/resource.rb', line 110
def delete
connection.delete(resource_uri).status == 200
end
|
#get(params = {}) ⇒ Object
114
115
116
|
# File 'lib/infoblox/resource.rb', line 114
def get(params={})
connection.get(resource_uri, params)
end
|
#post ⇒ Object
Also known as:
create
104
105
106
107
|
# File 'lib/infoblox/resource.rb', line 104
def post
self._ref = connection.post(resource_uri, remote_attribute_hash(write = true, post = true)).body
true
end
|
#put ⇒ Object
118
119
120
|
# File 'lib/infoblox/resource.rb', line 118
def put
connection.put(resource_uri, remote_attribute_hash(write = true))
end
|
#remote_attribute_hash(write = false, post = false) ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/infoblox/resource.rb', line 126
def remote_attribute_hash(write=false, post=false)
{}.tap do |hsh|
self.class.remote_attrs.each do |k|
hsh[k] = self.send(k)
end
self.class.remote_write_only_attrs.each do |k|
hsh[k] = self.send(k)
end if write
self.class.remote_post_attrs.each do |k|
hsh[k] = self.send(k)
end if post
end
end
|
#resource_uri ⇒ Object
122
123
124
|
# File 'lib/infoblox/resource.rb', line 122
def resource_uri
self._ref.nil? ? self.class.resource_uri : (BASE_PATH + self._ref)
end
|