Class: Forms::SubmissionStatuses::Gateway

Inherits:
Object
  • Object
show all
Defined in:
lib/forms/submission_statuses/gateway.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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 = 
  @allowed_forms = allowed_forms
  @dataset = Forms::SubmissionStatuses::Dataset.new
  @error_handler = Forms::SubmissionStatuses::ErrorHandler.new
end

Instance Attribute Details

#datasetObject

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

#dataObject



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_serviceObject (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

#submissionsObject



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