class DnsServices::DigitalOcean
Public Class Methods
new(opts={})
click to toggle source
# File lib/dnsign/dns_services/digital_ocean.rb, line 10 def initialize(opts={}) @access_token = opts.fetch :access_token end
Public Instance Methods
retrieve_ip(fqdn)
click to toggle source
# File lib/dnsign/dns_services/digital_ocean.rb, line 24 def retrieve_ip(fqdn) name, domain = split_fqdn fqdn if record = fetch_record_by_name(domain, name) record.data end end
update_ip(fqdn, ip)
click to toggle source
# File lib/dnsign/dns_services/digital_ocean.rb, line 14 def update_ip(fqdn, ip) name, domain = split_fqdn fqdn if existing = fetch_record_by_name(domain, name) handle_record_response update_record(existing.id, domain, name, ip) else handle_record_response create_record(domain, name, ip) end end
Private Instance Methods
client()
click to toggle source
# File lib/dnsign/dns_services/digital_ocean.rb, line 34 def client @client ||= DropletKit::Client.new access_token: @access_token end
create_record(domain, record_name, ip)
click to toggle source
# File lib/dnsign/dns_services/digital_ocean.rb, line 57 def create_record(domain, record_name, ip) record = DropletKit::DomainRecord.new(type: 'A', name: record_name, data: ip) client.domain_records.create(record, for_domain: domain) end
fetch_record_by_name(domain, record_name)
click to toggle source
# File lib/dnsign/dns_services/digital_ocean.rb, line 42 def fetch_record_by_name(domain, record_name) # todo: handle non-existing domains client .domain_records .all(for_domain: domain) .select {|r| r.name == record_name} .first end
handle_record_response(record)
click to toggle source
# File lib/dnsign/dns_services/digital_ocean.rb, line 38 def handle_record_response(record) record.data # ip end
update_record(id, domain, record_name, ip)
click to toggle source
# File lib/dnsign/dns_services/digital_ocean.rb, line 52 def update_record(id, domain, record_name, ip) record = DropletKit::DomainRecord.new(name: record_name, data: ip) client.domain_records.update(record, for_domain: domain, id: id) end