Class: CARMA::Models::Attachments
- Defined in:
- lib/carma/models/attachments.rb
Instance Attribute Summary collapse
-
#all ⇒ Object
Returns the value of attribute all.
-
#carma_case_id ⇒ Object
Returns the value of attribute carma_case_id.
-
#has_errors ⇒ Object
readonly
Returns the value of attribute has_errors.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#veteran_first_name ⇒ Object
Returns the value of attribute veteran_first_name.
-
#veteran_last_name ⇒ Object
Returns the value of attribute veteran_last_name.
Instance Method Summary collapse
- #add(document_type, local_path) ⇒ Object
-
#initialize(carma_case_id, veteran_first_name, veteran_last_name) ⇒ Attachments
constructor
A new instance of Attachments.
- #submit!(client) ⇒ Object
- #to_hash ⇒ Object
- #to_request_payload ⇒ Object
Methods inherited from Base
after_to_request_payload, request_payload_key
Constructor Details
#initialize(carma_case_id, veteran_first_name, veteran_last_name) ⇒ Attachments
Returns a new instance of Attachments.
17 18 19 20 21 22 |
# File 'lib/carma/models/attachments.rb', line 17 def initialize(carma_case_id, veteran_first_name, veteran_last_name) @carma_case_id = carma_case_id @veteran_first_name = veteran_first_name @veteran_last_name = veteran_last_name @all = [] end |
Instance Attribute Details
#all ⇒ Object
Returns the value of attribute all.
12 13 14 |
# File 'lib/carma/models/attachments.rb', line 12 def all @all end |
#carma_case_id ⇒ Object
Returns the value of attribute carma_case_id.
12 13 14 |
# File 'lib/carma/models/attachments.rb', line 12 def carma_case_id @carma_case_id end |
#has_errors ⇒ Object (readonly)
Returns the value of attribute has_errors.
9 10 11 |
# File 'lib/carma/models/attachments.rb', line 9 def has_errors @has_errors end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
9 10 11 |
# File 'lib/carma/models/attachments.rb', line 9 def response @response end |
#veteran_first_name ⇒ Object
Returns the value of attribute veteran_first_name.
12 13 14 |
# File 'lib/carma/models/attachments.rb', line 12 def veteran_first_name @veteran_first_name end |
#veteran_last_name ⇒ Object
Returns the value of attribute veteran_last_name.
12 13 14 |
# File 'lib/carma/models/attachments.rb', line 12 def veteran_last_name @veteran_last_name end |
Instance Method Details
#add(document_type, local_path) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/carma/models/attachments.rb', line 24 def add(document_type, local_path) all << CARMA::Models::Attachment.new( carma_case_id:, document_type:, file_path: local_path, veteran_name: { first: veteran_first_name, last: veteran_last_name } ) self end |
#submit!(client) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/carma/models/attachments.rb', line 46 def submit!(client) return response if response @response = client.(to_request_payload) @has_errors = @response['hasErrors'] @all.each do || matching_result = @response['results'].find do |upload_result| upload_result['referenceId'] == .reference_id end .id = matching_result['id'] if matching_result end self end |
#to_hash ⇒ Object
64 65 66 67 68 69 |
# File 'lib/carma/models/attachments.rb', line 64 def to_hash { has_errors:, data: all.map(&:to_hash) } end |
#to_request_payload ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/carma/models/attachments.rb', line 38 def to_request_payload raise 'must have at least one attachment' if all.empty? { 'records' => all.map(&:to_request_payload) } end |