Skip to content

Instantly share code, notes, and snippets.

@gooley
Created September 17, 2012 16:32
Show Gist options
  • Save gooley/3738364 to your computer and use it in GitHub Desktop.
Save gooley/3738364 to your computer and use it in GitHub Desktop.
Sample LessNeglect ruby helper class
# TODO - make sure you have the 'lessneglect' gem installed
require 'lessneglect'
class Neglect
def self.api
# TODO - replace with your credentials
@@api ||= LessNeglectApi::Client.new({
:code => "asdfasdf",
:secret => "1234asdfasdf1234"
})
end
def self.log_event(user, event_name, extras = {})
# there may be reasons why you want to not log events.
# delete or modify these as necessary
return if user.nil?
return if Rails.env == "development"
begin
person = user_to_person(user)
event = LessNeglectApi::ActionEvent.new({
:name => event_name
}.merge(extras))
api.create_action_event(person, event)
rescue
puts "error logging to LN"
end
end
def self.update_person(user)
return if user.nil?
return if Rails.env == "development"
begin
person = user_to_person(user)
api.update_person(person)
rescue
puts "error logging to LN"
end
end
def self.user_to_person(user)
# TODO - you should update this to build a full LN Person object
# with the data in your User model
LessNeglectApi::Person.new({
:name => user.name,
:email => user.email,
:external_identifer => user.id,
:properties => {
:account_level => user.account_level,
:is_paying => user.paying?,
:created_at => user.created_at.to_i
}
})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment