Class: Efolder::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/efolder/service.rb

Overview

Veteran Facing eFolder

This service provides the veteran with methods to both view the contents of their eFolder, and also download the files contained therein.

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ Service

Returns a new instance of Service.



12
13
14
15
16
# File 'lib/efolder/service.rb', line 12

def initialize(user)
  @user = user
  @client = VBMS::Client.from_env_vars(env_name: Settings.vbms.env)
  @bgs_doc_uuids = bgs_doc_uuids
end

Instance Method Details

#bgs_doc_uuidsObject (private)



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/efolder/service.rb', line 49

def bgs_doc_uuids
  uuids = []
  BGS::UploadedDocumentService
    .new(@user)
    .get_documents
    .each do |claim|
      uploaded_docs = claim[:uplded_dcmnts]
      if uploaded_docs.is_a?(Hash)
        uuids << uploaded_docs[:uuid_txt]
      else
        uploaded_docs.each do |doc|
          uuids << doc[:uuid_txt]
        end
      end
    end
  uuids.compact
end

#file_numberObject (private)



44
45
46
47
# File 'lib/efolder/service.rb', line 44

def file_number
  bgs_file_number = BGS::People::Request.new.find_person_by_participant_id(user: @user).file_number
  bgs_file_number.empty? ? @user.ssn : bgs_file_number
end

#get_document(document_id) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/efolder/service.rb', line 28

def get_document(document_id)
  verify_document_in_folder(document_id)

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

#list_documentsObject



18
19
20
21
22
23
24
25
26
# File 'lib/efolder/service.rb', line 18

def list_documents
  vbms_docs.map do |document|
    if @bgs_doc_uuids.include?(document[:document_id].delete('{}'))
      document.marshal_dump.slice(
        :document_id, :doc_type, :type_description, :received_at
      )
    end
  end.compact
end

#vbms_docsObject (private)



38
39
40
41
42
# File 'lib/efolder/service.rb', line 38

def vbms_docs
  @client.send_request(
    VBMS::Requests::FindDocumentVersionReference.new(file_number)
  )
end

#verify_document_in_folder(document_id) ⇒ Object (private)



67
68
69
70
71
# File 'lib/efolder/service.rb', line 67

def verify_document_in_folder(document_id)
  raise Common::Exceptions::Unauthorized unless list_documents.any? do |document|
    document[:document_id] == document_id
  end
end