mixpanel 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ .bundle
2
+ mixpanel*.gem
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2010 Alvaro Gil, cuboxsa.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,25 @@
1
+ == What is Mixpanel (the service) ?
2
+
3
+ *Mixpanel* is a real-time analytics service that helps companies understand how users interact with web applications.
4
+ http://mixpanel.com
5
+
6
+ == What does this Gem?
7
+
8
+ * Track events with properties directly from your backend
9
+
10
+
11
+ == How to install?
12
+
13
+ gem install mixpanel
14
+
15
+
16
+ == How to use?
17
+
18
+ require 'mixpanel'
19
+
20
+ mixpanel = Mixpanel.new("your_mixpanel_project_token")
21
+
22
+ mixpanel.track("Sign up", {
23
+ :referer => "http://example.com",
24
+ :ip => "4.4.4.4"
25
+ })
@@ -0,0 +1,9 @@
1
+ require 'spec/rake/spectask'
2
+
3
+ task :default => :spec
4
+
5
+ desc "Run all examples"
6
+ Spec::Rake::SpecTask.new('spec') do |t|
7
+ t.spec_opts = ["-u -c -fs"]
8
+ t.spec_files = FileList['spec/**/*_spec.rb']
9
+ end
@@ -0,0 +1,42 @@
1
+ require "open-uri"
2
+ require 'base64'
3
+ require 'json'
4
+
5
+ class Mixpanel
6
+ attr_reader :events
7
+
8
+ def initialize(token, options = {})
9
+ @token = token
10
+ @events = []
11
+ end
12
+
13
+ def append_event(event, properties = {})
14
+ @events << build_event(event, properties)
15
+ end
16
+
17
+ def track_event(event, properties = {})
18
+ params = build_event(event, properties.merge(:token => @token, :time => Time.now.utc.to_i))
19
+ parse_response request(params)
20
+ end
21
+
22
+ def clean_queue
23
+ @events = []
24
+ end
25
+
26
+ private
27
+
28
+ def parse_response(response)
29
+ response == "1" ? true : false
30
+ end
31
+
32
+ def request(params)
33
+ data = Base64.encode64(JSON.generate(params)).gsub(/\n/,'')
34
+ url = "http://api.mixpanel.com/track/?data=#{data}"
35
+
36
+ open(url).read
37
+ end
38
+
39
+ def build_event(event, properties)
40
+ {:event => event, :properties => properties}
41
+ end
42
+ end
@@ -0,0 +1,27 @@
1
+ spec = Gem::Specification.new do |s|
2
+ s.name = "mixpanel"
3
+ s.version = "0.5.1"
4
+ s.rubyforge_project = "mixpanel"
5
+ s.description = "Simple lib to track events in Mixpanel service."
6
+ s.author = "Alvaro Gil"
7
+ s.email = "zevarito@gmail.com"
8
+ s.homepage = "http://cuboxsa.com"
9
+ s.platform = Gem::Platform::RUBY
10
+ s.summary = "Supports direct request api and javascript requests."
11
+ s.files = %w[
12
+ .gitignore
13
+ README.rdoc
14
+ LICENSE
15
+ Rakefile
16
+ mixpanel.gemspec
17
+ lib/mixpanel.rb
18
+ spec/spec_helper.rb
19
+ spec/mixpanel/mixpanel_spec.rb
20
+ ]
21
+ s.require_path = "lib"
22
+ s.has_rdoc = false
23
+ s.extra_rdoc_files = ["README.rdoc"]
24
+ s.add_dependency 'json'
25
+ s.add_development_dependency 'rspec'
26
+ s.add_development_dependency 'fakeweb'
27
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mixpanel do
4
+ before do
5
+ @mixpanel = Mixpanel.new(MIX_PANEL_TOKEN)
6
+ end
7
+
8
+ context "Initializing object" do
9
+ it "should have an instance variable for token and events" do
10
+ @mixpanel.instance_variables.should include("@token", "@events")
11
+ end
12
+ end
13
+
14
+ context "Cleaning events" do
15
+ it "should clean the queue" do
16
+ @mixpanel.append_event("Sign up")
17
+ @mixpanel.events.size.should == 1
18
+ @mixpanel.clean_queue
19
+ @mixpanel.events.size.should == 0
20
+ end
21
+ end
22
+
23
+ context "Accessing Mixpanel through direct request" do
24
+ context "Tracking events" do
25
+ it "should track simple events" do
26
+ @mixpanel.track_event("Sign up").should == true
27
+ end
28
+
29
+ it "should call request method with token and time value" do
30
+ params = {:event => "Sign up", :properties => {:token => MIX_PANEL_TOKEN, :time => Time.now.utc.to_i}}
31
+
32
+ @mixpanel.should_receive(:request).with(params).and_return("1")
33
+ @mixpanel.track_event("Sign up").should == true
34
+ end
35
+ end
36
+ end
37
+
38
+ context "Accessing Mixpanel through javascript API" do
39
+ context "Appending events" do
40
+ it "should append simple events" do
41
+ @mixpanel.append_event("Sign up")
42
+ mixpanel_events_should_include(@mixpanel, "Sign up", {})
43
+ end
44
+
45
+ it "should append events with properties" do
46
+ @mixpanel.append_event("Sign up", {:referer => 'http://example.com'})
47
+ mixpanel_events_should_include(@mixpanel, "Sign up", {:referer => 'http://example.com'})
48
+ end
49
+
50
+ it "should give direct access to events" do
51
+ @mixpanel.append_event("Sign up", {:referer => 'http://example.com'})
52
+ @mixpanel.events.size.should == 1
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,15 @@
1
+ require File.join(File.dirname(__FILE__), "../lib", "mixpanel")
2
+ require 'fakeweb'
3
+
4
+ MIX_PANEL_TOKEN = "e2d8b0bea559147844ffab3d607d26a6"
5
+
6
+ def mixpanel_events_should_include(mixpanel, event, properties)
7
+ mixpanel.events.each do |event_hash|
8
+ event_hash[:event].should == event
9
+ event_hash[:properties].should == properties if properties
10
+ end
11
+ end
12
+
13
+ # Fakeweb
14
+ FakeWeb.allow_net_connect = false
15
+ FakeWeb.register_uri(:any, /http:\/\/api\.mixpanel\.com.*/, :body => "1")
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mixpanel
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 5
9
+ - 1
10
+ version: 0.5.1
11
+ platform: ruby
12
+ authors:
13
+ - Alvaro Gil
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-05 00:00:00 -03:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: json
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: fakeweb
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ version_requirements: *id003
63
+ description: Simple lib to track events in Mixpanel service.
64
+ email: zevarito@gmail.com
65
+ executables: []
66
+
67
+ extensions: []
68
+
69
+ extra_rdoc_files:
70
+ - README.rdoc
71
+ files:
72
+ - .gitignore
73
+ - README.rdoc
74
+ - LICENSE
75
+ - Rakefile
76
+ - mixpanel.gemspec
77
+ - lib/mixpanel.rb
78
+ - spec/spec_helper.rb
79
+ - spec/mixpanel/mixpanel_spec.rb
80
+ has_rdoc: true
81
+ homepage: http://cuboxsa.com
82
+ licenses: []
83
+
84
+ post_install_message:
85
+ rdoc_options: []
86
+
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ requirements: []
108
+
109
+ rubyforge_project: mixpanel
110
+ rubygems_version: 1.3.7
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Supports direct request api and javascript requests.
114
+ test_files: []
115
+