Class: EVSS::Letters::DownloadService

Inherits:
Service show all
Includes:
Common::Client::Concerns::Monitoring
Defined in:
lib/evss/letters/download_service.rb

Overview

Proxy Service for Letters Download Caseflow

Examples:

Create a service and download letter by type

letter_response = EVSS::Letters::DownloadService.new.download_letter("commissary")

Constant Summary

Constants inherited from Service

Service::STATSD_KEY_PREFIX

Instance Attribute Summary

Attributes inherited from Service

#transaction_id

Instance Method Summary collapse

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

#with_monitoring

Methods inherited from Service

#headers, #initialize, #perform, service_is_up?

Methods inherited from Common::Client::Base

configuration, #raise_backend_exception

Methods included from SentryLogging

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

Constructor Details

This class inherits a constructor from EVSS::Service

Instance Method Details

#download_letter(type, options = nil) ⇒ String

Downloads a letter for a user

one of EVSS::Letters::Letter::LETTER_TYPES

Parameters:

  • type (String)

    The type of letter to be downloaded;

Returns:

  • (String)

    Service response body



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/evss/letters/download_service.rb', line 28

def download_letter(type, options = nil)
  with_monitoring do
    response = if options.blank?
                 download(type)
               else
                 download_with_benefit_options(type, options)
               end

    case response.status.to_i
    when 200
      response.body
    when 404
      raise Common::Exceptions::RecordNotFound, type
    else
      Raven.extra_context(
        url: config.base_path,
        body: response.body
      )
      raise_backend_exception('EVSS502', 'Letters')
    end
  end
end