Sha256: b08017884b4787299f1945a017b53d69b783ce349c4b3622f5afdd4f45e6a0ac

Contents?: true

Size: 1.75 KB

Versions: 2

Compression:

Stored size: 1.75 KB

Contents

# encoding: utf-8
require 'logger'

require 'framed/version'
require 'framed/rails' if defined?(::Rails)
require 'framed/railtie' if defined?(::Rails::Railtie)
require 'framed/client'
require 'framed/emitters'
require 'framed/utils'

module Framed
  SEGMENT_API_ENDPOINT = 'https://api.segment.io/v1/track'
  FRAMED_API_ENDPOINT = 'https://intake.framed.io/events'
  COOKIE_NAME = 'framed_id'

  class << self
    attr_accessor :client, :consumer

    def configuration
      @configuration ||= {
        :consumer => Framed::Emitters::Blocking,
        :user_id_controller_method => 'framed_current_user_id',
        :endpoint => Framed::FRAMED_API_ENDPOINT,
        :logger => Logger.new(STDERR),
        :anonymous_cookie => Framed::COOKIE_NAME,
        :include_xhr => false
      }
    end

    def configure(silent = false)
      yield configuration
      self.client = Client.new(configuration)

      @consumer.stop(true) if @consumer
      @consumer = configuration[:consumer].new(self.client)
    end

    def report(event)
      event[:lib] =  "framed_ruby"
      event[:lib_version] = Framed::VERSION
      event[:type] ||= :track
      event[:context] ||= {}
      event[:context].merge!({
        :channel => 'server',
      })

      event[:properties] ||= {}

      # fill in if needed, in case it sits in queue for a while.
      event[:timestamp] ||= Framed::Utils.serialize_date(Time.now)
      @consumer.enqueue(event)
    end

    def logger
      configuration[:logger]
    end

    def drain
      @consumer.stop(true) if @consumer
    end

    def user_id_controller_method
      configuration[:user_id_controller_method]
    end

    def anonymous_cookie
      configuration[:anonymous_cookie]
    end

    def new_anonymous_id
      Framed::Utils.uuid
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
framed_rails-0.1.5 lib/framed_rails.rb
framed_rails-0.1.4 lib/framed_rails.rb