Class: DocVault::RetrieveDocument

Inherits:
Object
  • Object
show all
Defined in:
lib/doc_vault/retrieve_document.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, bucket:, key:) ⇒ RetrieveDocument

Returns a new instance of RetrieveDocument.



9
10
11
12
13
14
# File 'lib/doc_vault/retrieve_document.rb', line 9

def initialize(id:, bucket:, key:)
  @id = id
  @bucket = bucket
  @key = key
  validate_params
end

Class Method Details

.call(id:, bucket:, key:) ⇒ Object



5
6
7
# File 'lib/doc_vault/retrieve_document.rb', line 5

def self.call(id:, bucket:, key:)
  new(id:, bucket:, key:).call
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
# File 'lib/doc_vault/retrieve_document.rb', line 16

def call
  database = Database.new(@bucket)
  encrypted_doc = database.retrieve(@id)
  raise DocumentNotFoundError, "Document with id '#{@id}' not found" unless encrypted_doc

  decrypted_doc = Encryption.decrypt(encrypted_doc, @key)
  DocumentSerializer.deserialize(decrypted_doc)
end