Class: Dps::DNS

Inherits:
Object
  • Object
show all
Defined in:
lib/dps/dns.rb

Defined Under Namespace

Classes: Endpoint, InvalidRecord, NoRecords, TooManyRecords

Class Method Summary collapse

Class Method Details

.decode_txt_record(value) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dps/dns.rb', line 13

def decode_txt_record(value)
  parts = value.gsub('"', '').split
  
  head, tail = head_and_tail(parts)
  
  case head
  when "dps:endpoint"  
    Endpoint.new(tail)
  else
    InvalidRecord.new("Unexpected action '#{head}'")
  end
end

.get_endpoint(domain) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dps/dns.rb', line 26

def get_endpoint(domain)
  records = get_records(domain).select { |r| r.is_a?(Endpoint) }
  
  if records.length > 1
    TooManyRecords.new("Too many valid endpoint TXT records returned.")
  elsif records.length == 0
    NoRecords.new("No valid endpoint TXT records found.")
  else
    records[0]
  end
end

.get_records(domain) ⇒ Object



7
8
9
10
11
# File 'lib/dps/dns.rb', line 7

def get_records(domain)
  get_txt_records(domain).
  collect { |value| decode_txt_record(value) }.
  select(&:valid?)
end