Sha256: 437bba555f0796a454cfd289e78fc42190cba176be190732a494258cd29403cf

Contents?: true

Size: 1.48 KB

Versions: 2

Compression:

Stored size: 1.48 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

    def to_s
      "Keen IO Exception: #{super}"
    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, :project_id=, 
                   :write_key, :write_key=, 
                   :read_key, :read_key=, 
                   :api_url, :api_url=

    def_delegators :default_client,
                   :publish, :publish_async,
                   :beacon_url

    def_delegators :default_client,
                   :count, :count_unique, :minimum, :maximum,
                   :sum, :average, :select_unique, :funnel, :extraction

    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'],
        :write_key => ENV['KEEN_WRITE_KEY'],
        :read_key => ENV['KEEN_READ_KEY'],
        :api_url => ENV['KEEN_API_URL']
      )
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
keen-0.7.2 lib/keen.rb
keen-0.7.1 lib/keen.rb