Class: DebtManagementCenter::DebtLetterDownloader

Inherits:
Object
  • Object
show all
Includes:
SentryLogging
Defined in:
lib/debt_management_center/debt_letter_downloader.rb

Constant Summary collapse

DEBTS_DOCUMENT_TYPES =
%w[
  193
  194
  1213
  1214
  1215
  1216
  1217
  1287
  1334
].freeze

Instance Method Summary collapse

Methods included from SentryLogging

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

Constructor Details

#initialize(user) ⇒ DebtLetterDownloader

Returns a new instance of DebtLetterDownloader.



21
22
23
24
25
26
27
# File 'lib/debt_management_center/debt_letter_downloader.rb', line 21

def initialize(user)
  @user = user
  @client = VBMS::Client.from_env_vars(env_name: Settings.vbms.env)
  @service = debts_service
  @vbms_documents = get_vbms_documents
  verify_no_dependent_debts
end

Instance Method Details

#file_name(document_id) ⇒ Object



37
38
39
40
41
42
# File 'lib/debt_management_center/debt_letter_downloader.rb', line 37

def file_name(document_id)
  verify_letter_in_folder(document_id)

  document = @vbms_documents.detect { |doc| doc.document_id == document_id }
  "#{document.type_description} #{document.upload_date.to_formatted_s(:long)}"
end

#get_letter(document_id) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/debt_management_center/debt_letter_downloader.rb', line 29

def get_letter(document_id)
  verify_letter_in_folder(document_id)

  @client.send_request(
    VBMS::Requests::GetDocumentContent.new(document_id)
  ).content
end

#list_lettersObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/debt_management_center/debt_letter_downloader.rb', line 44

def list_letters
  debts_records = @vbms_documents.find_all do |record|
    DEBTS_DOCUMENT_TYPES.include?(record.doc_type)
  end

  debts_records.map do |debts_record|
    debts_record.marshal_dump.slice(
      :document_id, :doc_type, :type_description, :received_at
    )
  end
end