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

#increment, #increment_failure, #increment_total, #with_monitoring

Methods inherited from Service

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

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

#download(type) ⇒ Object (private)



50
51
52
# File 'lib/evss/letters/download_service.rb', line 50

def download(type)
  perform(:get, type)
end

#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
# 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
      Sentry.set_extras(url: config.base_path, body: response.body)
      raise_backend_exception('EVSS502', 'Letters')
    end
  end
end

#download_with_benefit_options(type, options) ⇒ Object (private)



54
55
56
# File 'lib/evss/letters/download_service.rb', line 54

def download_with_benefit_options(type, options)
  perform(:post, "#{type}/generate", options, 'Content-Type' => 'application/json')
end