Class: Forms::SubmissionStatuses::Gateway
- Inherits:
-
Object
- Object
- Forms::SubmissionStatuses::Gateway
- Defined in:
- lib/forms/submission_statuses/gateway.rb
Instance Attribute Summary collapse
-
#dataset ⇒ Object
Returns the value of attribute dataset.
Instance Method Summary collapse
- #data ⇒ Object
- #extract_uuids(submissions) ⇒ Object private
- #fetch_bulk_status(uuids) ⇒ Object private
- #handle_intake_error(error) ⇒ Object private
-
#initialize(user_account:, allowed_forms:) ⇒ Gateway
constructor
A new instance of Gateway.
- #intake_service ⇒ Object private
- #intake_statuses(submissions) ⇒ Object
- #process_response(response) ⇒ Object private
- #submissions ⇒ Object
Constructor Details
#initialize(user_account:, allowed_forms:) ⇒ Gateway
Returns a new instance of Gateway.
12 13 14 15 16 17 |
# File 'lib/forms/submission_statuses/gateway.rb', line 12 def initialize(user_account:, allowed_forms:) @user_account = user_account @allowed_forms = allowed_forms @dataset = Forms::SubmissionStatuses::Dataset.new @error_handler = Forms::SubmissionStatuses::ErrorHandler.new end |
Instance Attribute Details
#dataset ⇒ Object
Returns the value of attribute dataset.
10 11 12 |
# File 'lib/forms/submission_statuses/gateway.rb', line 10 def dataset @dataset end |
Instance Method Details
#data ⇒ Object
19 20 21 22 23 24 |
# File 'lib/forms/submission_statuses/gateway.rb', line 19 def data @dataset.submissions = submissions @dataset.intake_statuses, @dataset.errors = intake_statuses(@dataset.submissions) if @dataset.submissions? @dataset end |
#extract_uuids(submissions) ⇒ Object (private)
43 44 45 |
# File 'lib/forms/submission_statuses/gateway.rb', line 43 def extract_uuids(submissions) submissions.map(&:benefits_intake_uuid) end |
#fetch_bulk_status(uuids) ⇒ Object (private)
47 48 49 |
# File 'lib/forms/submission_statuses/gateway.rb', line 47 def fetch_bulk_status(uuids) intake_service.bulk_status(uuids:) end |
#handle_intake_error(error) ⇒ Object (private)
55 56 57 58 |
# File 'lib/forms/submission_statuses/gateway.rb', line 55 def handle_intake_error(error) errors = @error_handler.handle_error(status: error.status, body: error.body) [nil, errors] end |
#intake_service ⇒ Object (private)
60 61 62 |
# File 'lib/forms/submission_statuses/gateway.rb', line 60 def intake_service @service ||= BenefitsIntake::Service.new end |
#intake_statuses(submissions) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/forms/submission_statuses/gateway.rb', line 33 def intake_statuses(submissions) uuids = extract_uuids(submissions) response = fetch_bulk_status(uuids) process_response(response) rescue => e handle_intake_error(e) end |
#process_response(response) ⇒ Object (private)
51 52 53 |
# File 'lib/forms/submission_statuses/gateway.rb', line 51 def process_response(response) [response.body['data'], nil] end |
#submissions ⇒ Object
26 27 28 29 30 31 |
# File 'lib/forms/submission_statuses/gateway.rb', line 26 def submissions query = FormSubmission.with_latest_benefits_intake_uuid(@user_account) .with_form_types(@allowed_forms) .order(:created_at) query.to_a end |