Class: EVSS::Letters::Service

Inherits:
Service show all
Defined in:
lib/evss/letters/service.rb

Overview

Proxy Service for Letters Caseflow.

Examples:

Creating a service and fetching letters for a user

letters_response = EVSS::Letters::Service.new.get_letters

Constant Summary collapse

INVALID_ADDRESS_ERROR =
'letterDestination.addressLine1.invalid'

Constants inherited from Service

Service::STATSD_KEY_PREFIX

Instance Attribute Summary

Attributes inherited from Service

#transaction_id

Instance Method Summary collapse

Methods inherited from Service

#headers, #initialize, #perform, #save_error_details, service_is_up?, #with_monitoring_and_error_handling

Methods included from Common::Client::Concerns::Monitoring

#increment, #increment_failure, #increment_total, #with_monitoring

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

Constructor Details

This class inherits a constructor from EVSS::Service

Instance Method Details

#get_letter_beneficiaryEVSS::Letters::BeneficiaryResponse

Returns benefit and service information for a user.

an array of military service objects

Returns:



47
48
49
50
51
52
# File 'lib/evss/letters/service.rb', line 47

def get_letter_beneficiary
  with_monitoring_and_error_handling do
    raw_response = perform(:get, 'letterBeneficiary')
    EVSS::Letters::BeneficiaryResponse.new(raw_response.status, raw_response)
  end
end

#get_lettersEVSS::Letters::LettersResponse

Returns letters for a user.

array of letter objects

Returns:



32
33
34
35
36
37
38
39
# File 'lib/evss/letters/service.rb', line 32

def get_letters
  with_monitoring do
    raw_response = perform(:get, '')
    EVSS::Letters::LettersResponse.new(raw_response.status, raw_response)
  end
rescue => e
  handle_error(e)
end

#handle_error(error) ⇒ Object (private)



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/evss/letters/service.rb', line 56

def handle_error(error)
  Sentry.set_tags(team: 'benefits-memorial-1') # tag sentry logs with team name
  if (error.is_a?(Common::Client::Errors::ClientError) && error.status != 403 && error.body.is_a?(Hash)) ||
     error.is_a?(EVSS::ErrorMiddleware::EVSSError)
    begin
      log_edipi if invalid_address_error?(error)
    ensure
      save_error_details(error)
      raise EVSS::Letters::ServiceException, error.body
    end
  else
    super(error)
  end
end

#invalid_address_error?(error) ⇒ Boolean (private)

Returns:

  • (Boolean)


75
76
77
# File 'lib/evss/letters/service.rb', line 75

def invalid_address_error?(error)
  error.body['messages']&.any? { |m| m['key'].include? INVALID_ADDRESS_ERROR }
end

#log_edipiObject (private)



71
72
73
# File 'lib/evss/letters/service.rb', line 71

def log_edipi
  InvalidLetterAddressEdipi.find_or_create_by(edipi: @user.edipi)
end