Class: Splicer::DnsMadeEasy::Provider

Inherits:
Provider
  • Object
show all
Defined in:
lib/splicer/dns_made_easy/provider.rb

Overview

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Provider

Returns a new instance of Provider.



8
9
10
11
# File 'lib/splicer/dns_made_easy/provider.rb', line 8

def initialize(config)
  @config = config
  @client = config.client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/splicer/dns_made_easy/provider.rb', line 6

def client
  @client
end

Instance Method Details

#create_record_in_zone(record, zone) ⇒ Object



79
80
81
82
83
84
85
86
87
88
# File 'lib/splicer/dns_made_easy/provider.rb', line 79

def create_record_in_zone(record, zone)
  Splicer.logger.debug "[SPLICER][DNSMADEEASY] #create_record_in_zone record=#{record.inspect} zone=#{zone.inspect}"
  domain = find_domain(zone.name)
  return false unless domain.persisted?

  records = find_records(record.name, record.type, domain.id)
  return false unless records.empty?

  create_record(domain.id, record)
end

#create_zone(zone) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/splicer/dns_made_easy/provider.rb', line 13

def create_zone(zone)
  Splicer.logger.debug "[SPLICER][DNSMADEEASY] #create_zone zone=#{zone.inspect}"
  domain = find_domain(zone.name)
  return false if domain.persisted?

  client.post('dns/managed', name: zone.name)

  zone.records.each do |record|
    create_record(domain.id, record)
  end
end

#delete_record_in_zone(record, zone) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/splicer/dns_made_easy/provider.rb', line 57

def delete_record_in_zone(record, zone)
  Splicer.logger.debug "[SPLICER][DNSMADEEASY] #delete_record_in_zone record=#{record.inspect} zone=#{zone.inspect}"
  domain = find_domain(zone.name)
  return false unless domain.persisted?

  records = find_records(record.name, record.type, domain.id)
  return false if records.empty?

  delete_record(domain.id, records.first.id)
end

#delete_zone(zone) ⇒ Object



50
51
52
53
54
55
# File 'lib/splicer/dns_made_easy/provider.rb', line 50

def delete_zone(zone)
  Splicer.logger.debug "[SPLICER][DNSMADEEASY] #delete_zone zone=#{zone.inspect}"
  domain = find_domain(zone.name)
  return false unless domain.persisted?
  client.delete(domain_resource_url(domain.id))
end

#rewrite_zone(zone) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/splicer/dns_made_easy/provider.rb', line 30

def rewrite_zone(zone)
  Splicer.logger.debug "[SPLICER][DNSMADEEASY] #rewrite_zone zone=#{zone.inspect}"
  domain = find_domain(zone.name)

  unless domain.persisted?
    client.post('dns/managed', name: zone.name)
    domain = find_domain(zone.name)
  end

  if domain.persisted?
    fetch_records(domain.id).each do |record|
      delete_record(domain.id, record.id)
    end
  end

  zone.records.each do |record|
    create_record(domain.id, record)
  end
end

#update_record_in_zone(record, zone) ⇒ Object



68
69
70
71
72
73
74
75
76
77
# File 'lib/splicer/dns_made_easy/provider.rb', line 68

def update_record_in_zone(record, zone)
  Splicer.logger.debug "[SPLICER][DNSMADEEASY] #update_record_in_zone record=#{record.inspect} zone=#{zone.inspect}"
  domain = find_domain(zone.name)
  return false unless domain.persisted?

  records = find_records(record.name, record.type, domain.id)
  return false if records.empty?

  update_record(domain.id, records.first.id, record)
end

#update_zone(zone) ⇒ Object



25
26
27
28
# File 'lib/splicer/dns_made_easy/provider.rb', line 25

def update_zone(zone)
  Splicer.logger.debug "[SPLICER][DNSMADEEASY] #update_zone zone=#{zone.inspect}"
  rewrite_zone(zone)
end