Class: Mixpanel
- Inherits:
-
Hash
- Object
- Hash
- Mixpanel
- Defined in:
- lib/mixpanel-client.rb
Constant Summary collapse
- URL =
'http://api.mixpanel.com'
Instance Method Summary collapse
-
#conn ⇒ Object
Create Faraday connection.
-
#get_data(event, data = {}) ⇒ Object
Assemble data for request.
-
#initialize(key) ⇒ Mixpanel
constructor
Require token at instantiation.
-
#track(event, data = {}) ⇒ Object
Get data and make HTTP request.
Constructor Details
#initialize(key) ⇒ Mixpanel
Require token at instantiation
13 14 15 |
# File 'lib/mixpanel-client.rb', line 13 def initialize(key) @key = key end |
Instance Method Details
#conn ⇒ Object
Create Faraday connection
41 42 43 44 45 |
# File 'lib/mixpanel-client.rb', line 41 def conn Faraday.new(:url => URL) do |c| c.adapter Faraday.default_adapter end end |
#get_data(event, data = {}) ⇒ Object
Assemble data for request
21 22 23 24 25 26 27 28 |
# File 'lib/mixpanel-client.rb', line 21 def get_data(event, data={}) self['event'] = event self['properties'] = data self['properties']['token'] = @key self['properties']['time'] = Time.now.to_i Base64.encode64(JSON.generate(self)) end |
#track(event, data = {}) ⇒ Object
Get data and make HTTP request
34 35 36 37 38 |
# File 'lib/mixpanel-client.rb', line 34 def track(event, data={}) params = self.get_data(event, data) r = self.conn.get '/track', {:data => params} r.body.to_i end |