Sha256: 0687ad783acbb3bf525c4d4c900f7a1ba6581df7d266996daeb787cc7eb54ff4

Contents?: true

Size: 1.01 KB

Versions: 4

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
          fail Errors::OutcomeNotAvailableError, 'The results have not yet been calculated.'
        when 204
          fail Errors::TooFewMeasurementsError, 'Not enough measurements available.'
        when 404
          fail Errors::GraphNotFoundError, 'Graph not found.'
        else
          fail Errors::UnexpectedStatusError, "Status code #{response.code} not expected."
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fizzy-api-0.0.3 lib/fizzy/api/render_graph.rb
fizzy-api-0.0.2.2 lib/fizzy/api/render_graph.rb
fizzy-api-0.0.2.1 lib/fizzy/api/render_graph.rb
fizzy-api-0.0.2 lib/fizzy/api/render_graph.rb