Class: CARMA::Models::Attachment
- Defined in:
- lib/carma/models/attachment.rb
Constant Summary collapse
- DOCUMENT_TYPES =
{ '10-10CG' => '10-10CG', 'POA' => 'Legal Representative' }.freeze
Instance Attribute Summary collapse
-
#carma_case_id ⇒ Object
Returns the value of attribute carma_case_id.
-
#document_date ⇒ Object
Returns the value of attribute document_date.
-
#document_type ⇒ Object
Returns the value of attribute document_type.
-
#file_path ⇒ Object
Returns the value of attribute file_path.
-
#id ⇒ Object
Returns the value of attribute id.
-
#veteran_name ⇒ Object
Returns the value of attribute veteran_name.
Instance Method Summary collapse
- #as_base64 ⇒ Object private
-
#initialize(args = {}) ⇒ Attachment
constructor
A new instance of Attachment.
- #reference_id ⇒ Object
- #title ⇒ Object
- #to_hash ⇒ Object
- #to_request_payload ⇒ Object
Methods inherited from Base
after_to_request_payload, request_payload_key
Constructor Details
#initialize(args = {}) ⇒ Attachment
Returns a new instance of Attachment.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/carma/models/attachment.rb', line 17 def initialize(args = {}) # TODO: We should select a timezone based on the claim's planned facility. timezone = 'Eastern Time (US & Canada)' @carma_case_id = args[:carma_case_id] @veteran_name = args[:veteran_name] @file_path = args[:file_path] @document_type = args[:document_type] @document_date = args[:document_date] || Time.now.in_time_zone(timezone).to_date @id = args[:id] end |
Instance Attribute Details
#carma_case_id ⇒ Object
Returns the value of attribute carma_case_id.
10 11 12 |
# File 'lib/carma/models/attachment.rb', line 10 def carma_case_id @carma_case_id end |
#document_date ⇒ Object
Returns the value of attribute document_date.
10 11 12 |
# File 'lib/carma/models/attachment.rb', line 10 def document_date @document_date end |
#document_type ⇒ Object
Returns the value of attribute document_type.
10 11 12 |
# File 'lib/carma/models/attachment.rb', line 10 def document_type @document_type end |
#file_path ⇒ Object
Returns the value of attribute file_path.
10 11 12 |
# File 'lib/carma/models/attachment.rb', line 10 def file_path @file_path end |
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'lib/carma/models/attachment.rb', line 10 def id @id end |
#veteran_name ⇒ Object
Returns the value of attribute veteran_name.
10 11 12 |
# File 'lib/carma/models/attachment.rb', line 10 def veteran_name @veteran_name end |
Instance Method Details
#as_base64 ⇒ Object (private)
119 120 121 122 123 124 125 |
# File 'lib/carma/models/attachment.rb', line 119 def as_base64 Base64.encode64( File.read( file_path ) ) end |
#reference_id ⇒ Object
38 39 40 |
# File 'lib/carma/models/attachment.rb', line 38 def reference_id document_type.delete('-') end |
#title ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/carma/models/attachment.rb', line 29 def title [ document_type, veteran_name[:first], veteran_name[:last], document_date.strftime('%m-%d-%Y') ].join('_') end |
#to_hash ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/carma/models/attachment.rb', line 106 def to_hash { id:, carma_case_id:, veteran_name:, file_path:, document_type:, document_date: } end |
#to_request_payload ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/carma/models/attachment.rb', line 42 def to_request_payload { 'attributes' => { # property: attributes.type # value: 'ContentVersion' # comments: Static String to reference the target object in salesforce for Files. # examples: 'ContentVersion' 'type' => 'ContentVersion', # property: attributes.referenceId # value: Any unique string that maps to the file that is posted. # comments: A string that will be returned in the response that can be correlated # to the salesforce unique id of the created file. This is not persisted in salesforce. # examples: '1010CG' | 'Legal Representative' 'referenceId' => reference_id }, # property: Title # value: Formatted file name that shows up in Salesforce # comments: The expected format is: # <CARMA_Document_Type__c>_<VeteranFirstName>_<VeteranLastName>_<SubmittedDateMM-DD-YYYY> # 1. <CARMA_Document_Type__c> - Type litral for the document valid values are # '10-10CG' for the online application and 'Legal Representative' for Power of attorney # 2. <VeteranFirstName> - First Name of the Veteran. # examples: '10-10CG_John_Doe_03-30-2020' | 'Legal Representative_John_Doe_03-30-2020' 'Title' => title, # property: PathOnClient # value: Name of the pdf file uploaded with file extension. # comments: The actual file pdf file name. # examples: 'filename.pdf' # 'PathOnClient' => file_path, 'PathOnClient' => file_path.split('/').last, # property: CARMA_Document_Type__c # value: Static string literal for the type of the document. # comments: Accepted values are '10-10CG' for the online application and 'Legal Representative' # for Power of attorney document. # examples: '10-10CG' | 'Legal Representative' 'CARMA_Document_Type__c' => document_type, # property: CARMA_Document_Date__c # value: Date when the document is uploaded. # comments: Date the file was submitted in the format YYYY-MM-DD # examples: '2020-03-30' 'CARMA_Document_Date__c' => document_date.strftime('%Y-%m-%d'), # property: FirstPublishLocationId # value: The carmacase.id that was returned during a successful application creation. # comments: 18 character salesforce id returned in the application submission # service call response(carmacase.id). # examples: 'aB9r00000004GW9CAK' 'FirstPublishLocationId' => carma_case_id, # property: VersionData # value: The base64 encoded binary of the pdf file content. # comments: The base64 encoded binary of the pdf file content. # service call response(carmacase.id). # examples: 'JVBERi0xLjMKJcTl8uXrp<.....rest of the base64 ecoded pdf file content>' 'VersionData' => as_base64 } end |