Class: CARMA::Models::Submission
- Defined in:
- lib/carma/models/submission.rb
Instance Attribute Summary collapse
-
#carma_case_id ⇒ Object
Returns the value of attribute carma_case_id.
-
#data ⇒ Object
Returns the value of attribute data.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#request_body ⇒ Object
readonly
Returns the value of attribute request_body.
-
#submitted_at ⇒ Object
Returns the value of attribute submitted_at.
Class Method Summary collapse
-
.from_claim(claim, metadata = {}) ⇒ CARMA::Models::Submission
Returns a new CARMA::Models::Submission built from a CaregiversAssistanceClaim.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Submission
constructor
A new instance of Submission.
- #submit!(client) ⇒ Object
- #submitted? ⇒ Boolean
Methods inherited from Base
after_to_request_payload, request_payload_key, #to_request_payload
Constructor Details
#initialize(args = {}) ⇒ Submission
Returns a new instance of Submission.
39 40 41 42 43 44 |
# File 'lib/carma/models/submission.rb', line 39 def initialize(args = {}) self.carma_case_id = args[:carma_case_id] self.submitted_at = args[:submitted_at] self.data = args[:data] self. = args[:metadata] || {} end |
Instance Attribute Details
#carma_case_id ⇒ Object
Returns the value of attribute carma_case_id.
10 11 12 |
# File 'lib/carma/models/submission.rb', line 10 def carma_case_id @carma_case_id end |
#data ⇒ Object
Returns the value of attribute data.
10 11 12 |
# File 'lib/carma/models/submission.rb', line 10 def data @data end |
#metadata ⇒ Object
Returns the value of attribute metadata.
9 10 11 |
# File 'lib/carma/models/submission.rb', line 9 def @metadata end |
#request_body ⇒ Object (readonly)
Returns the value of attribute request_body.
9 10 11 |
# File 'lib/carma/models/submission.rb', line 9 def request_body @request_body end |
#submitted_at ⇒ Object
Returns the value of attribute submitted_at.
10 11 12 |
# File 'lib/carma/models/submission.rb', line 10 def submitted_at @submitted_at end |
Class Method Details
.from_claim(claim, metadata = {}) ⇒ CARMA::Models::Submission
Returns a new CARMA::Models::Submission built from a CaregiversAssistanceClaim.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/carma/models/submission.rb', line 21 def self.from_claim(claim, = {}) if Flipper.enabled?(:caregiver_carma_submitted_at) return new( data: claim.parsed_form, metadata: .merge( claim_id: claim.id, claim_guid: claim.guid, submitted_at: claim.created_at&.iso8601 ) ) end new( data: claim.parsed_form, metadata: .merge(claim_id: claim.id, claim_guid: claim.guid) ) end |
Instance Method Details
#submit!(client) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/carma/models/submission.rb', line 46 def submit!(client) raise 'This submission has already been submitted to CARMA' if submitted? @request_body = to_request_payload response = client.create_submission(request_body) @carma_case_id = response['data']['carmacase']['id'] @submitted_at = response['data']['carmacase']['createdAt'] self end |
#submitted? ⇒ Boolean
59 60 61 |
# File 'lib/carma/models/submission.rb', line 59 def submitted? @submitted_at.present? || @carma_case_id.present? end |