Class: RecordStore::Provider::NS1::ApiAnswer

Inherits:
Object
  • Object
show all
Defined in:
lib/record_store/provider/ns1.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, record_id:, rrdata:) ⇒ ApiAnswer

Returns a new instance of ApiAnswer.



29
30
31
32
33
# File 'lib/record_store/provider/ns1.rb', line 29

def initialize(type:, record_id:, rrdata:)
  @type = type
  @record_id = record_id
  @rrdata = rrdata
end

Instance Attribute Details

#record_idObject

Returns the value of attribute record_id.



27
28
29
# File 'lib/record_store/provider/ns1.rb', line 27

def record_id
  @record_id
end

#rrdataObject

Returns the value of attribute rrdata.



27
28
29
# File 'lib/record_store/provider/ns1.rb', line 27

def rrdata
  @rrdata
end

#typeObject

Returns the value of attribute type.



27
28
29
# File 'lib/record_store/provider/ns1.rb', line 27

def type
  @type
end

Class Method Details

.from_full_api_answer(type:, record_id:, answer:) ⇒ Object



8
9
10
# File 'lib/record_store/provider/ns1.rb', line 8

def from_full_api_answer(type:, record_id:, answer:)
  ApiAnswer.new(type: type, record_id: record_id, rrdata: answer['answer'])
end

.from_short_api_answer(type:, record_id:, answer:) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/record_store/provider/ns1.rb', line 12

def from_short_api_answer(type:, record_id:, answer:)
  rrdata_fields = case type
  when 'SPF', 'TXT'
    [answer]
  when 'SRV'
    priority, weight, port, host = answer.split
    [priority.to_i, weight.to_i, port.to_i, Record.ensure_ends_with_dot(host)]
  else
    answer.split
  end

  ApiAnswer.new(type: type, record_id: record_id, rrdata: rrdata_fields)
end

Instance Method Details

#idObject



39
40
41
# File 'lib/record_store/provider/ns1.rb', line 39

def id
  [record_id, type, *rrdata]
end

#rrdata_stringObject



35
36
37
# File 'lib/record_store/provider/ns1.rb', line 35

def rrdata_string
  rrdata.join(' ')
end