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.



1447
1448
1449
1450
1451
1452
1453
1454
1455
# File 'lib/mockserver/models.rb', line 1447

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.



1444
1445
1446
# File 'lib/mockserver/models.rb', line 1444

def additional_records
  @additional_records
end

#answer_recordsObject

Returns the value of attribute answer_records.



1444
1445
1446
# File 'lib/mockserver/models.rb', line 1444

def answer_records
  @answer_records
end

#authority_recordsObject

Returns the value of attribute authority_records.



1444
1445
1446
# File 'lib/mockserver/models.rb', line 1444

def authority_records
  @authority_records
end

#delayObject

Returns the value of attribute delay.



1444
1445
1446
# File 'lib/mockserver/models.rb', line 1444

def delay
  @delay
end

#primaryObject

Returns the value of attribute primary.



1444
1445
1446
# File 'lib/mockserver/models.rb', line 1444

def primary
  @primary
end

#response_codeObject

Returns the value of attribute response_code.



1444
1445
1446
# File 'lib/mockserver/models.rb', line 1444

def response_code
  @response_code
end

Class Method Details

.from_hash(data) ⇒ Object



1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
# File 'lib/mockserver/models.rb', line 1468

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



1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
# File 'lib/mockserver/models.rb', line 1457

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