Sha256: 434e1d570c17fc51038700a69b23c2d4baff217f2ff96fee5a972cfc0e62f4f9
Contents?: true
Size: 1.77 KB
Versions: 34
Compression:
Stored size: 1.77 KB
Contents
module QuizApiClient class Config DEFAULT_ALLOWABLE_RESPONSE_CODES = [401, 422].freeze DEFAULT_PROTOCOL = 'https'.freeze ERROR_HANDLERS = %i[sentry_raven].freeze METRICS_HANDLERS = %i[inststatsd].freeze class InvalidErrorHandler < StandardError; end class InvalidMetricsHandler < StandardError; end class InvalidMetricsNamespace < StandardError; end attr_reader :error_handler, :metrics_handler, :metrics_namespace attr_writer :protocol, :allowable_response_codes attr_accessor :consumer_key, :consumer_request_id, :host, :shared_secret def initialize yield(self) if block_given? end def protocol @protocol || DEFAULT_PROTOCOL end def error_handler=(handler) validate_error_handler!(handler) @error_handler = handler.to_sym end def setup_metrics(handler, namespace) validate_metrics_handler!(handler) validate_metrics_namespace!(namespace) @metrics_handler = handler.to_sym @metrics_namespace = namespace.to_s.strip end def allowable_response_codes @allowable_response_codes || DEFAULT_ALLOWABLE_RESPONSE_CODES end private def validate_error_handler!(handler) return unless handler return if ERROR_HANDLERS.include?(handler) raise InvalidErrorHandler, "It must be one of the following: #{ERROR_HANDLERS.inspect}" end def validate_metrics_handler!(handler) return unless handler return if METRICS_HANDLERS.include?(handler) raise InvalidMetricsHandler, "It must be one of the following: #{METRICS_HANDLERS.inspect}" end def validate_metrics_namespace!(namespace) return unless namespace.nil? || namespace.to_s.strip == '' raise InvalidMetricsNamespace, 'It must be present' end end end
Version data entries
34 entries across 34 versions & 1 rubygems