Skip to content

Instantly share code, notes, and snippets.

@kirs
Created February 20, 2012 12:42
Show Gist options
  • Save kirs/1869045 to your computer and use it in GitHub Desktop.
Save kirs/1869045 to your computer and use it in GitHub Desktop.
module Modules
module FnordmetricEvent
class << self
def create(*options)
define_api
event_key = options[0]
raise "Pass the event key" unless event_key.present?
params = options[1]
if params
user_id = params.delete(:user).id if params[:user]
user_id = params.delete(:user_id) if params[:user_id]
end
params[:_type] = event_key.to_s
params[:_session] = "userid_#{user_id}" if user_id
@_api.event params
end
def write_user(user)
define_api
@_api.event({ _type: "_set_name", name: user.name, _session: "userid_#{user.id}" })
end
private
def define_api
@_api ||= FnordMetric::API.new({})
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment