1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/dynect/models/dns/records.rb

66 lines
1.7 KiB
Ruby
Raw Normal View History

2011-06-16 17:51:13 -04:00
require 'fog/core/collection'
require 'fog/dynect/models/dns/record'
2011-06-16 17:51:13 -04:00
module Fog
module DNS
class Dynect
2011-06-16 17:51:13 -04:00
class Records < Fog::Collection
attribute :zone
model Fog::DNS::Dynect::Record
2011-06-16 17:51:13 -04:00
def all(options = {})
requires :zone
data = []
service.get_all_records(zone.domain, options).body['data'].each do |url|
(_, _, t, _, fqdn, id) = url.split('/')
type = t.gsub(/Record$/, '')
# leave out the default, read only records
# by putting this here we don't make the secondary request for these records
next if ['NS', 'SOA'].include?(type)
record = service.get_record(type, zone.domain, fqdn, 'record_id' => id).body['data']
data << {
:identity => record['record_id'],
:fqdn => record['fqdn'],
:type => record['record_type'],
:rdata => record['rdata']
}
end
load(data)
end
def get(record_id)
requires :zone
list = service.get_all_records(zone.domain, {}).body['data']
url = list.detect { |e| e =~ /\/#{record_id}$/ }
return unless url
(_, _, t, _, fqdn, id) = url.split('/')
type = t.gsub(/Record$/, '')
record = service.get_record(type, zone.domain, fqdn, 'record_id' => id).body['data']
new({
:identity => record['record_id'],
:fqdn => record['fqdn'],
:type => record['record_type'],
:rdata => record['rdata']
})
end
2011-06-16 17:51:13 -04:00
def new(attributes = {})
2011-06-16 18:04:01 -04:00
requires :zone
super({:zone => zone}.merge!(attributes))
2011-06-16 17:51:13 -04:00
end
end
end
end
end