Sha256: 17e01c5a6c592a591734df981154a4bdd4e7aeb3deadc6c41471592877268e7b

Contents?: true

Size: 927 Bytes

Versions: 2

Compression:

Stored size: 927 Bytes

Contents

module Fizzy
  module Api
    class CalculateOutcome < ActiveInteraction::Base
      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
        when 202
          raise Errors::OutcomeNotAvailableError, 'The results are currently being calculated.'
        when 404
          raise Errors::GraphNotFoundError, 'Participant not found, or graph not supported.'
        else
          raise Errors::UnexpectedStatusError, "Status code #{response.code} not expected."
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fizzy-api-0.0.5 lib/fizzy/api/calculate_outcome.rb
fizzy-api-0.0.4 lib/fizzy/api/calculate_outcome.rb