Class: Fog::DNS::Dynect::Record

Inherits:
Model
  • Object
show all
Extended by:
Fog::Deprecation
Defined in:
lib/fog/dynect/models/dns/record.rb

Instance Method Summary collapse

Instance Method Details

#destroyObject



16
17
18
19
20
# File 'lib/fog/dynect/models/dns/record.rb', line 16

def destroy
  requires :identity, :name, :type, :zone
  service.delete_record(type, zone.identity, name, identity)
  true
end

#save(replace = false) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fog/dynect/models/dns/record.rb', line 22

def save(replace=false)
  requires :name, :type, :rdata, :zone

  options = {
    :ttl => ttl
  }
  options.delete_if {|key, value| value.nil?}

  if replace
    data = service.put_record(type, zone.identity, name, rdata, options).body['data']
  else
    data = service.post_record(type, zone.identity, name, rdata, options).body['data']
  end
  # avoid overwriting zone object with zone string
  data = data.reject {|key, value| key == 'zone'}
  merge_attributes(data)

  zone.publish
  records = service.get_record(type, zone.identity, name).body['data']
  # data in format ['/REST/xRecord/domain/fqdn/identity]
  records.map! do |record|
    tokens = record.split('/')
    {
      :identity => tokens.last,
      :type     => tokens[2][0...-6] # everything before 'Record'
    }
  end
  record = records.find {|record| record[:type] == type}
  merge_attributes(record)

  true
end

#zoneObject



55
56
57
# File 'lib/fog/dynect/models/dns/record.rb', line 55

def zone
  @zone
end