Sha256: 10bce4cfd3d9f5255dedb3730c147a2337209eb39afcac720ffa13b6b81b554e

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

require 'logger'
require 'forwardable'

require 'keen/client'

module Keen
  class Error < RuntimeError
    attr_accessor :original_error
    def initialize(message, _original_error=nil)
      self.original_error = _original_error
      super(message)
    end
  end

  class ConfigurationError < Error; end
  class HttpError < Error; end
  class BadRequestError < HttpError; end
  class AuthenticationError < HttpError; end
  class NotFoundError < HttpError; end

  class << self
    extend Forwardable

    def_delegators :default_client, :project_id, :api_key,
                   :project_id=, :api_key=, :publish, :publish_async,
                   :beacon_url

    attr_writer :logger

    def logger
      @logger ||= lambda {
        logger = Logger.new($stdout)
        logger.level = Logger::INFO
        logger
      }.call
    end

    private

    def default_client
      @default_client ||= Keen::Client.new(
        :project_id => ENV['KEEN_PROJECT_ID'],
        :api_key => ENV['KEEN_API_KEY']
      )
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
keen-0.5.0 lib/keen.rb
keen-0.4.4 lib/keen.rb
keen-0.4.3 lib/keen.rb