Class: VeteranVerification::Service

Inherits:
Common::Client::Base show all
Defined in:
lib/lighthouse/veteran_verification/service.rb

Constant Summary collapse

STATSD_KEY_PREFIX =
'api.veteran_verification'

Instance Method Summary collapse

Methods inherited from Common::Client::Base

#config, configuration, #connection, #delete, #get, #perform, #post, #put, #raise_backend_exception, #raise_not_authenticated, #request, #sanitize_headers!, #service_name

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata

Instance Method Details

#get_rated_disabilities(icn, lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, options = {}) ⇒ Object

Parameters:

  • icn: (string)

    the ICN of the target Veteran

  • lighthouse_client_id: (string)

    the lighthouse_client_id requested from Lighthouse

  • lighthouse_rsa_key_path: (string)

    path to the private RSA key used to create the lighthouse_client_id

  • options: (hash)

    options to override aud_claim_url, params, and auth_params

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :params (hash)

    body for the request

  • :aud_claim_url (string)

    option to override the aud_claim_url for LH Veteran Verification APIs

  • :auth_params (hash)

    a hash to send in auth params to create the access token

  • :host (string)

    a base host for the Lighthouse API call

  • :invoker (string)

    where this method was called from



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lighthouse/veteran_verification/service.rb', line 22

def get_rated_disabilities(icn, lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, options = {})
  endpoint = 'disability_rating'
  config
    .get(
      "#{endpoint}/#{icn}",
      lighthouse_client_id,
      lighthouse_rsa_key_path,
      options
    )
    .body
rescue => e
  handle_error(e, lighthouse_client_id, endpoint, options)
end

#get_vet_verification_status(icn, lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, options = {}) ⇒ Object

Request a veteran’s Title 38 status

see https://developer.va.gov/explore/api/veteran-service-history-and-eligibility/docs


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/lighthouse/veteran_verification/service.rb', line 39

def get_vet_verification_status(icn, lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, options = {})
  endpoint = 'status'
  response = config.get(
    "#{endpoint}/#{icn}",
    lighthouse_client_id,
    lighthouse_rsa_key_path,
    options
  ).body

  transform_response(response)
rescue => e
  StatsD.increment(VeteranVerification::Constants::STATSD_VET_VERIFICATION_FAIL_KEY)
  handle_error(e, lighthouse_client_id, endpoint)
ensure
  StatsD.increment(VeteranVerification::Constants::STATSD_VET_VERIFICATION_TOTAL_KEY)
end

#handle_error(error, lighthouse_client_id, endpoint, options = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/lighthouse/veteran_verification/service.rb', line 56

def handle_error(error, lighthouse_client_id, endpoint, options = {})
  Lighthouse::ServiceException.send_error(
    error,
    self.class.to_s.underscore,
    lighthouse_client_id,
    "#{config.base_api_path}/#{endpoint}",
    options
  )
end

#log_reason(reason) ⇒ Object



84
85
86
# File 'lib/lighthouse/veteran_verification/service.rb', line 84

def log_reason(reason)
  ::Rails.logger.info('Vet Verification Status Success', { not_confirmed_reason: reason })
end

#transform_response(response) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/lighthouse/veteran_verification/service.rb', line 66

def transform_response(response)
  attributes = response['data']['attributes']
  return response if attributes['veteran_status'] != 'not confirmed' || attributes.exclude?('not_confirmed_reason')

  reason = attributes['not_confirmed_reason']
  response['data']['message'] =
    if reason == 'ERROR'
      VeteranVerification::Constants::ERROR_MESSAGE
    elsif reason == 'NOT_TITLE_38'
      VeteranVerification::Constants::NOT_ELIGIBLE_MESSAGE
    else
      VeteranVerification::Constants::NOT_FOUND_MESSAGE
    end

  log_reason(reason)
  response
end