Class: Dynacord::Provider::Gandi::LiveDNS

Inherits:
Object
  • Object
show all
Defined in:
lib/dynacord/provider/gandi/livedns.rb

Instance Method Summary collapse

Constructor Details

#initialize(apikey:) ⇒ LiveDNS

Returns a new instance of LiveDNS.



8
9
10
11
12
# File 'lib/dynacord/provider/gandi/livedns.rb', line 8

def initialize(apikey:)
  @apikey = apikey
  @api = Net::HTTP.new('dns.api.gandi.net', 443)
  @api.use_ssl = true
end

Instance Method Details

#update_record(record:, zone:, ipaddr:, ttl: 300) ⇒ Object

update a given A record in a provided zone



36
37
38
39
40
41
42
43
44
45
# File 'lib/dynacord/provider/gandi/livedns.rb', line 36

def update_record(record:, zone:, ipaddr:, ttl: 300)
  uri = "/api/v5/zones/#{zone}/records/#{record}/A"
  data = {'rrset_ttl' => ttl.to_i, 'rrset_values' => [ipaddr]}.to_json
  q = Net::HTTP::Put.new(uri)
  q['X-Api-Key'] = @apikey
  q["Content-Type"] = "application/json"
  q.body = data
  r = @api.request(q)
  return r.code, r.body
end

#uuid_from_domain(domain:) ⇒ Object

get the uuid for a given domain



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dynacord/provider/gandi/livedns.rb', line 23

def uuid_from_domain(domain:)
  zones = zone_uuids()
  uuid = nil
  JSON.parse(zones[1]).each do |zone|
    if zone['name'] == domain
      uuid = zone['uuid']
      break
    end
  end
  return uuid
end

#zone_uuidsObject

get the LiveDNS zones and their UUIDs



15
16
17
18
19
20
# File 'lib/dynacord/provider/gandi/livedns.rb', line 15

def zone_uuids()
  q = Net::HTTP::Get.new('/api/v5/zones')
  q['X-Api-Key'] = @apikey
  r = @api.request(q)
  return r.code, r.body
end