lib/fog/dynect/models/dns/records.rb in fog-1.15.0 vs lib/fog/dynect/models/dns/records.rb in fog-1.16.0
- old
+ new
@@ -12,39 +12,51 @@
model Fog::DNS::Dynect::Record
def all(options = {})
requires :zone
data = []
- service.get_node_list(zone.domain, options).body['data'].each do |fqdn|
- records = service.get_record('ANY', zone.domain, fqdn).body['data']
+ service.get_all_records(zone.domain, options).body['data'].each do |url|
+ (_, _, t, _, fqdn, id) = url.split('/')
+ type = t.gsub(/Record$/, '')
- # data in format ['/REST/xRecord/domain/fqdn/identity]
- records.map! do |record|
- tokens = record.split('/')
- {
- :identity => tokens.last,
- :fqdn => fqdn,
- :type => tokens[2][0...-6] # everything before 'Record'
- }
- end
+ # 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)
- data.concat(records)
+ 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
- # leave out the default, read only records
- data = data.reject {|record| ['NS', 'SOA'].include?(record[:type])}
-
load(data)
end
def get(record_id)
- # FIXME: can this be done more efficiently?
- all.detect {|record| record.identity == 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
def new(attributes = {})
requires :zone
- super({ :zone => zone }.merge!(attributes))
+ super({:zone => zone}.merge!(attributes))
end
end
end