Class: VAProfile::Profile::V3::HealthBenefitBioResponse

Inherits:
Response show all
Defined in:
lib/va_profile/profile/v3/health_benefit_bio_response.rb

Constant Summary

Constants included from Common::Client::Concerns::ServiceStatus

Common::Client::Concerns::ServiceStatus::RESPONSE_STATUS

Instance Attribute Summary

Attributes inherited from Common::Base

#errors_hash, #metadata

Instance Method Summary collapse

Methods inherited from Response

#cache?, #metadata, #ok?, #response_status

Methods inherited from Common::Base

#changed, #changed?, #changes, default_sort, filterable_attributes, max_per_page, per_page, sortable_attributes

Constructor Details

#initialize(response) ⇒ HealthBenefitBioResponse

Returns a new instance of HealthBenefitBioResponse.



16
17
18
19
20
21
22
23
24
25
# File 'lib/va_profile/profile/v3/health_benefit_bio_response.rb', line 16

def initialize(response)
  body = response&.body
  contacts = body.dig('profile', 'health_benefit', 'associated_persons')
                 &.select { |p| valid_contact_types.include?(p['contact_type']) }
                 &.sort_by { |p| valid_contact_types.index(p['contact_type']) }
  messages = body['messages']
  code = messages&.first&.dig('code')
  va_profile_tx_audit_id = response.response_headers['vaprofiletxauditid']
  super(response.status, { code:, contacts:, messages:, va_profile_tx_audit_id: })
end

Instance Method Details

#debug_dataObject



27
28
29
30
31
32
33
34
# File 'lib/va_profile/profile/v3/health_benefit_bio_response.rb', line 27

def debug_data
  {
    code:,
    status:,
    message:,
    va_profile_tx_audit_id:
  }
end

#messageObject (private)



46
47
48
49
50
51
# File 'lib/va_profile/profile/v3/health_benefit_bio_response.rb', line 46

def message
  m = messages&.first
  return '' unless m

  "#{m.code} #{m.key} #{m.text}"
end

#server_error?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/va_profile/profile/v3/health_benefit_bio_response.rb', line 36

def server_error?
  status >= 500
end

#valid_contact_typesObject (private)



42
43
44
# File 'lib/va_profile/profile/v3/health_benefit_bio_response.rb', line 42

def valid_contact_types
  VAProfile::Models::AssociatedPerson::PERSONAL_HEALTH_CARE_CONTACT_TYPES
end