module Terrestrial::Cli::MixpanelClient

Constants

TOKEN
URL

Public Class Methods

event_json(event) click to toggle source
# File lib/terrestrial/cli/mixpanel_client.rb, line 30
def event_json(event)
  {
    event: event,
    properties: {
      distinct_id: user_identifier,
      token: TOKEN,
      time: Time.now.to_i
    }
  }.to_json
end
fetch_and_save_user_id() click to toggle source
# File lib/terrestrial/cli/mixpanel_client.rb, line 41
def fetch_and_save_user_id
  response = Web.new.get_profile
  if response.success?
    id = response.body["data"]["user"]["id"]
    Config.load({:user_id => id})
    Config.update_global_config
    id
  else
    "unknown"
  end
end
format_event(event) click to toggle source
# File lib/terrestrial/cli/mixpanel_client.rb, line 26
def format_event(event)
  Base64.strict_encode64(event_json(event))
end
track(event) click to toggle source
# File lib/terrestrial/cli/mixpanel_client.rb, line 12
def track(event)
  unless Config.testing?
    `curl -silent -X POST #{URL}?data=#{format_event(event)} &`
  end
end
user_identifier() click to toggle source
# File lib/terrestrial/cli/mixpanel_client.rb, line 18
def user_identifier
  if Config[:user_id]
    Config[:user_id]
  else
    fetch_and_save_user_id
  end
end