Sha256: 5076936d5a2c3daaa755efef3583d8dc637a52a17501267bdd570e2e49c396c3

Contents?: true

Size: 1.73 KB

Versions: 40

Compression:

Stored size: 1.73 KB

Contents

require 'fog/core/collection'
require 'fog/dynect/models/dns/record'

module Fog
  module DNS
    class Dynect

      class Records < Fog::Collection

        attribute :zone

        model Fog::DNS::Dynect::Record

        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

        def new(attributes = {})
          requires :zone
          super({:zone => zone}.merge!(attributes))
        end

      end

    end
  end
end

Version data entries

40 entries across 40 versions & 2 rubygems

Version Path
fog-1.22.0 lib/fog/dynect/models/dns/records.rb
fog-1.21.0 lib/fog/dynect/models/dns/records.rb
fog-maestrodev-1.20.0.20140305101839 lib/fog/dynect/models/dns/records.rb
fog-maestrodev-1.20.0.20140305101305 lib/fog/dynect/models/dns/records.rb
fog-maestrodev-1.19.0.20140212012611 lib/fog/dynect/models/dns/records.rb
fog-1.20.0 lib/fog/dynect/models/dns/records.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/dynect/models/dns/records.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/dynect/models/dns/records.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/dynect/models/dns/records.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/dynect/models/dns/records.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/dynect/models/dns/records.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/dynect/models/dns/records.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/dynect/models/dns/records.rb
fog-1.19.0 lib/fog/dynect/models/dns/records.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/dynect/models/dns/records.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/dynect/models/dns/records.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/dynect/models/dns/records.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/dynect/models/dns/records.rb
fog-maestrodev-1.18.0.20131218202447 lib/fog/dynect/models/dns/records.rb
fog-maestrodev-1.18.0.20131209091424 lib/fog/dynect/models/dns/records.rb