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.



1419
1420
1421
1422
1423
1424
1425
1426
1427
# File 'lib/mockserver/models.rb', line 1419

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.



1416
1417
1418
# File 'lib/mockserver/models.rb', line 1416

def additional_records
  @additional_records
end

#answer_recordsObject

Returns the value of attribute answer_records.



1416
1417
1418
# File 'lib/mockserver/models.rb', line 1416

def answer_records
  @answer_records
end

#authority_recordsObject

Returns the value of attribute authority_records.



1416
1417
1418
# File 'lib/mockserver/models.rb', line 1416

def authority_records
  @authority_records
end

#delayObject

Returns the value of attribute delay.



1416
1417
1418
# File 'lib/mockserver/models.rb', line 1416

def delay
  @delay
end

#primaryObject

Returns the value of attribute primary.



1416
1417
1418
# File 'lib/mockserver/models.rb', line 1416

def primary
  @primary
end

#response_codeObject

Returns the value of attribute response_code.



1416
1417
1418
# File 'lib/mockserver/models.rb', line 1416

def response_code
  @response_code
end

Class Method Details

.from_hash(data) ⇒ Object



1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
# File 'lib/mockserver/models.rb', line 1440

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



1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
# File 'lib/mockserver/models.rb', line 1429

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