Sha256: f4925fc98399147c32e1b9be642489ee51b229596067dac2338b344456fb9f5d

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

module Dnsdeploy
  class Base
    def initialize(records_file)
      @records_file = File.new(records_file)
    end

    def self.update_records(records_file)
      self.new(records_file).update_records
    end

    def validate
      JSON.load(@records_file.read)
      puts "#{@records_file.path} is valid json".green
    rescue => e
      puts "unable to parse #{@records_file.path}".red
    end

    def update_records
      local.domains.each do |domain|
        puts "[Processing] Domain #{domain.name}"

        # Delete records on DNSimple
        DNSimple::Record.all(domain).collect(&:destroy)

        # create records
        local.records(domain).each do |record|
          puts "[CREATE] #{record}".green
          begin
            DNSimple::Record.create(record.domain, record.name, record.record_type,
              record.content, { ttl: record.ttl, prio: record.prio })
          rescue DNSimple::RequestError => e
            puts "[ERROR] #{e} #{record}".red
            @exit = 1
          end
        end

        exit(@exit) if @exit
      end
    end

    def local
      @local ||= Dnsdeploy::Local.new(@records_file)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dnsdeploy-0.0.1 lib/dnsdeploy/base.rb