mixpanel-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZmI0MTcyY2RjNWQxYWQxMWQwYTMxOWFhZDNkNzUwYzBkNGZjMDlhNA==
5
+ data.tar.gz: !binary |-
6
+ NzdlODIyYzNjYzM1OTM3Yjk5Mjc1NjcyYmRlMjkzNjIxZThhMDA5Ng==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ OWI2MzVmNjNiMDE0MDI5ZjM2NWIyOGZjNTI1OTE0NmY1ZTgxMTQzYzU4OTZh
10
+ YmJlMzg0NGI5NWRmNzgyY2U2NTdmZTE0NzM2YWNhY2VlNDFlNjU5ZDdmNTIz
11
+ MDBlNTZjZWJlNjgzZGQ4ZTM3Yzc1MTVlMTlmMDRlMDNmZDg0Y2E=
12
+ data.tar.gz: !binary |-
13
+ ZGY0Mjc5MzM2OGFmNWVkZmY5N2M5NmFhYjVkNTczZWNjY2RlMjI4Y2Y2MWIy
14
+ NmE1ZGU2YzA4ODVjZjY2MWRhNDYyOGZlYWI1NjRiMTE4YTdhNGVlYmYyOTJh
15
+ NTc5ZjMzNGFiODQ2ZDhlODUwNzIyNGExNDhhNmQxNzQ3ZGZiZTA=
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ Mixpanel API Client
2
+ ===================
3
+
4
+ A simple API client for tracking data in Mixpanel
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Installation is a piece of cake:
10
+
11
+ ```bash
12
+ $ gem install mixpanel-client
13
+ ```
14
+
15
+ Usage
16
+ -----
17
+
18
+ Usage is pretty straightforward:
19
+
20
+ ``` ruby
21
+
22
+ client = Mixpanel.new('YOUR API KEY')
23
+ client.track('event', :some => 'data')
24
+
25
+ ```
26
+
27
+ Copyright
28
+ ---------
29
+ See [LICENSE][] for details.
30
+
31
+ [license]: LICENSE
@@ -0,0 +1,47 @@
1
+ require 'json'
2
+ require 'base64'
3
+ require 'faraday'
4
+ require 'faraday/middleware'
5
+
6
+ class Mixpanel < Hash
7
+
8
+ URL = 'http://api.mixpanel.com'
9
+
10
+ # Require token at instantiation
11
+ #
12
+ # @param [string] project token
13
+ def initialize(key)
14
+ @key = key
15
+ end
16
+
17
+ # Assemble data for request
18
+ #
19
+ # @param [string] tracking event
20
+ # @param [hash] additional data points
21
+ def get_data(event, data={})
22
+ self['event'] = event
23
+ self['properties'] = data
24
+ self['properties']['token'] = @key
25
+ self['properties']['time'] = Time.now.to_i
26
+
27
+ Base64.encode64(JSON.generate(self))
28
+ end
29
+
30
+ # Get data and make HTTP request
31
+ #
32
+ # @param [string] tracking event
33
+ # @param [hash] additional data points
34
+ def track(event, data={})
35
+ params = self.get_data(event, data)
36
+ r = self.conn.get '/track', {:data => params}
37
+ r.body.to_i
38
+ end
39
+
40
+ # Create Faraday connection
41
+ def conn
42
+ Faraday.new(:url => URL) do |c|
43
+ c.adapter Faraday.default_adapter
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'mixpanel')
4
+
5
+ describe Mixpanel do
6
+
7
+ before(:each) do
8
+ @track = Mixpanel.new('YOUR API KEY')
9
+ end
10
+
11
+ it 'Should respond with 1' do
12
+ result = @track.track('nom', :foo => 'bar')
13
+ result.should == 1
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mixpanel-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Travis Tillotson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.0
41
+ description: Provides a simple interface for loading data to Mixpanel
42
+ email:
43
+ - tillotson.travis@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files:
47
+ - README.md
48
+ files:
49
+ - lib/mixpanel-client.rb
50
+ - README.md
51
+ - spec/mixpanel_spec.rb
52
+ homepage: https://github.com/Opus1no2/mixpanel-client
53
+ licenses:
54
+ - MIT
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 2.0.4
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Simple API client for Mixpanel
76
+ test_files:
77
+ - spec/mixpanel_spec.rb