Sha256: bc5775d63af78dbf740c4ee8553f9ab30f000e79f67e035b14e92e8c6a4fa25d

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

module Fizzy
  module Api
    class RenderGraph < ActiveInteraction::Base
      string :dossier_id
      string :protocol_subscription_id
      string :path
      hash :options, default: {}

      def execute
        response = Api.basic_auth_session.get("/dossier/#{dossier_id}"\
                                   "/protocol_subscriptions/#{protocol_subscription_id}" \
                                   "/render/#{path}", options)
        process_response(response)
      end

      private

      def process_response(response)
        case response.code
        when 200
          response
        when 202
          raise Errors::OutcomeNotAvailableError, 'The results have not yet been calculated.'
        when 204
          raise Errors::TooFewMeasurementsError, 'Not enough measurements available.'
        when 404
          raise Errors::GraphNotFoundError, 'Graph not found.'
        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/render_graph.rb
fizzy-api-0.0.4 lib/fizzy/api/render_graph.rb