Skip to content
Snippets Groups Projects

Added synchronous call functionality, refactored the architecture a bit

Merged automation_daan requested to merge gh-23000649/7/roqua/fb-add-render_sync-routes into master
14 files
+ 476
4
Compare changes
  • Side-by-side
  • Inline
Files
14
module Fizzy
module Api
class CalculateOutcome < ActiveInteraction::Base
string :dossier_id
string :protocol_subscription_id
module Endpoints
class CalculateOutcome < Endpoint
string :dossier_id
string :protocol_subscription_id
def execute
response = Api.basic_auth_session.post("/dossier/#{dossier_id}"\
"/protocol_subscriptions/#{protocol_subscription_id}"\
'/calculate')
process_response(response)
end
private
def process_response(response)
case response.code
when 200
response
else
invalid_response(response)
def execute
response = Api.basic_auth_session.post("/dossier/#{dossier_id}"\
"/protocol_subscriptions/#{protocol_subscription_id}"\
'/calculate')
process_response(response)
end
end
def invalid_response(response)
case response.code
when 202
raise Errors::OutcomeNotAvailableError, response.body || 'The results are currently being calculated.'
when 404
raise Errors::GraphNotFoundError, response.body || 'Participant not found, or graph not supported.'
else
raise Errors::UnexpectedStatusError, "Status code #{response.code} not expected."
private
def invalid_response(response)
case response.code
when 202
raise(Errors::OutcomeNotAvailableError,
select_measurement_text(response.body, 'The results are currently being calculated.'))
when 404
raise Errors::GraphNotFoundError, select_measurement_text(response.body,
'Participant not found, or graph not supported.')
else
raise Errors::UnexpectedStatusError, "Status code #{response.code} not expected."
end
end
end
end
Loading