Class: MockServer::DnsResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/mockserver/models.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response_code: nil, answer_records: nil, authority_records: nil, additional_records: nil, delay: nil, primary: nil) ⇒ DnsResponse

Returns a new instance of DnsResponse.



1780
1781
1782
1783
1784
1785
1786
1787
1788
# File 'lib/mockserver/models.rb', line 1780

def initialize(response_code: nil, answer_records: nil, authority_records: nil,
               additional_records: nil, delay: nil, primary: nil)
  @response_code = response_code
  @answer_records = answer_records
  @authority_records = authority_records
  @additional_records = additional_records
  @delay = delay
  @primary = primary
end

Instance Attribute Details

#additional_recordsObject

Returns the value of attribute additional_records.



1777
1778
1779
# File 'lib/mockserver/models.rb', line 1777

def additional_records
  @additional_records
end

#answer_recordsObject

Returns the value of attribute answer_records.



1777
1778
1779
# File 'lib/mockserver/models.rb', line 1777

def answer_records
  @answer_records
end

#authority_recordsObject

Returns the value of attribute authority_records.



1777
1778
1779
# File 'lib/mockserver/models.rb', line 1777

def authority_records
  @authority_records
end

#delayObject

Returns the value of attribute delay.



1777
1778
1779
# File 'lib/mockserver/models.rb', line 1777

def delay
  @delay
end

#primaryObject

Returns the value of attribute primary.



1777
1778
1779
# File 'lib/mockserver/models.rb', line 1777

def primary
  @primary
end

#response_codeObject

Returns the value of attribute response_code.



1777
1778
1779
# File 'lib/mockserver/models.rb', line 1777

def response_code
  @response_code
end

Class Method Details

.from_hash(data) ⇒ Object



1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
# File 'lib/mockserver/models.rb', line 1801

def self.from_hash(data)
  return nil if data.nil?

  answer_data = data['answerRecords']
  authority_data = data['authorityRecords']
  additional_data = data['additionalRecords']
  new(
    response_code:    data['responseCode'],
    answer_records:   answer_data&.map { |r| DnsRecord.from_hash(r) },
    authority_records: authority_data&.map { |r| DnsRecord.from_hash(r) },
    additional_records: additional_data&.map { |r| DnsRecord.from_hash(r) },
    delay:            Delay.from_hash(data['delay']),
    primary:          data['primary']
  )
end

Instance Method Details

#to_hObject



1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
# File 'lib/mockserver/models.rb', line 1790

def to_h
  result = {}
  result['responseCode'] = @response_code unless @response_code.nil?
  result['answerRecords'] = @answer_records.map(&:to_h) if @answer_records
  result['authorityRecords'] = @authority_records.map(&:to_h) if @authority_records
  result['additionalRecords'] = @additional_records.map(&:to_h) if @additional_records
  result['delay'] = @delay.to_h if @delay
  result['primary'] = @primary unless @primary.nil?
  result
end