Class: Infoblox::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/infoblox/resource.rb

Direct Known Subclasses

Host, Ipv4addr, Network

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Resource

Returns a new instance of Resource.



44
45
46
47
48
# File 'lib/infoblox/resource.rb', line 44

def initialize(attrs={})
  attrs.each do |k,v|
    self.send("#{k}=", v)
  end
end

Instance Attribute Details

#_refObject

Returns the value of attribute _ref.



3
4
5
# File 'lib/infoblox/resource.rb', line 3

def _ref
  @_ref
end

Class Method Details

.allObject



20
21
22
23
24
# File 'lib/infoblox/resource.rb', line 20

def self.all
  JSON.parse(connection.get(resource_uri).body).map do |item|
    new(item)
  end
end

.connectionObject



32
33
34
# File 'lib/infoblox/resource.rb', line 32

def self.connection
  @@connection
end

.connection=(con) ⇒ Object



36
37
38
# File 'lib/infoblox/resource.rb', line 36

def self.connection=(con)
  @@connection = con
end

.find(params) ⇒ Object



26
27
28
29
30
# File 'lib/infoblox/resource.rb', line 26

def self.find(params)
  JSON.parse(connection.get(resource_uri, params).body).map do |item|
    new(item)
  end
end

.remote_attr_accessor(*args) ⇒ Object



9
10
11
12
13
14
# File 'lib/infoblox/resource.rb', line 9

def self.remote_attr_accessor(*args)
  args.each do |a|
    attr_accessor a
    remote_attrs << a
  end
end

.remote_attrsObject



16
17
18
# File 'lib/infoblox/resource.rb', line 16

def self.remote_attrs
  @remote_attrs ||= []
end

.resource_uriObject



40
41
42
# File 'lib/infoblox/resource.rb', line 40

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

#createObject



50
51
52
53
# File 'lib/infoblox/resource.rb', line 50

def create
  self._ref = connection.post(resource_uri, remote_attribute_hash).body
  true
end

#deleteObject



55
56
57
# File 'lib/infoblox/resource.rb', line 55

def delete
  connection.delete(resource_uri).status == 200
end

#getObject



59
60
61
# File 'lib/infoblox/resource.rb', line 59

def get
  connection.get(resource_uri)
end

#remote_attribute_hashObject



67
68
69
70
71
72
73
# File 'lib/infoblox/resource.rb', line 67

def remote_attribute_hash
  {}.tap do |hsh|
    self.class.remote_attrs.each do |k|
      hsh[k] = self.send(k)
    end
  end
end

#resource_uriObject



63
64
65
# File 'lib/infoblox/resource.rb', line 63

def resource_uri
  self._ref.nil? ? self.class.resource_uri : (BASE_PATH + self._ref)
end