mix_tape 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mix_tape.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Omar Sahyoun
2
+
3
+ MIT License
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
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # MixTape
2
+
3
+ ## The Problem
4
+
5
+ Littering controllers with MixPanel events with large param payloads isn't a nice thing to do.
6
+
7
+ `MixTape` tries to help by creating a DSL for specifying your events in advance, and keeping them in a single file.
8
+
9
+ ## Defining your Events
10
+
11
+ MixTape::Builder.definition do
12
+
13
+ button_click "Log number of times user clicks button" do |user, button|
14
+ {
15
+ user_name: user.username,
16
+ distinct_id: user.id,
17
+ button_id: button.id,
18
+ button_page: button.page
19
+ }
20
+ end
21
+
22
+ checks_mail "User just checked their mail" do |user, inbox|
23
+ {
24
+ distinct_id: user.id,
25
+ user_name: user.username,
26
+ user_id: user.id,
27
+ unread_count: inbox.count
28
+ }
29
+ end
30
+
31
+ user_invites_friend "User has invited a friend" do |user, friend|
32
+ {
33
+ distinct_id: user.id,
34
+ user_name: user.username,
35
+ user_id: user.id,
36
+ friend_name: friend.name
37
+ }
38
+ end
39
+ end
40
+
41
+
42
+ To track a defined event:
43
+
44
+ MixTape.track_user_invites_friend(user, friend)
45
+
46
+ To update an existing event object:
47
+
48
+ MixTape.set_user_invites_friend(user, friend)
49
+
50
+ ## Available Events
51
+
52
+ To view defined events:
53
+
54
+ rake mix_tape:events
55
+
56
+ ## Installation
57
+
58
+ Add this line to your application's Gemfile:
59
+
60
+ gem 'mix_tape'
61
+
62
+ Don't forget to set your MixPanel API token:
63
+
64
+ MixTape.config do |config|
65
+ config.token = '12345'
66
+ end
67
+
68
+ And then execute:
69
+
70
+ $ bundle
71
+
72
+ Or install it yourself as:
73
+
74
+ $ gem install mix_tape
75
+
76
+
77
+ ## Contributing
78
+
79
+ 1. Fork it
80
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
81
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
82
+ 4. Push to the branch (`git push origin my-new-feature`)
83
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ Dir["lib/tasks/*.rake"].each { |ext| load ext }
@@ -0,0 +1,32 @@
1
+ module MixTape
2
+ module Builder
3
+ extend self
4
+
5
+ ## Store definitions in array, so we can generate documenation.
6
+ @@mix_tape = []
7
+
8
+ def mix_tape
9
+ @@mix_tape
10
+ end
11
+
12
+ def definition(&block)
13
+ block.arity < 1 ? self.instance_eval(&block) : block.call(self) if block_given?
14
+ end
15
+
16
+ def define(name, desc = '', &block)
17
+ @@mix_tape << [name, desc]
18
+
19
+ MixTape.define_singleton_method("track_#{name}") do |*args|
20
+ MixTape.client.track name.to_s, yield(*args)
21
+ end
22
+
23
+ MixTape.define_singleton_method("set_#{name}") do |id, *args|
24
+ MixTape.client.set id, yield(*args)
25
+ end
26
+ end
27
+
28
+ def method_missing(key, *arguments, &block)
29
+ define(key, arguments.first, &block)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ module MixTape
2
+
3
+ class << self
4
+ attr_accessor :token
5
+
6
+ def client
7
+ raise(ArgumentError, %{MixPanel token is undefined.}) if token.empty?
8
+ @client ||= Mixpanel::Tracker.new(token, async: true)
9
+ end
10
+
11
+ def config(&block)
12
+ instance_eval &block
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module MixTape
2
+ VERSION = "0.0.1"
3
+ end
data/lib/mix_tape.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "mixpanel"
2
+ require "mix_tape/client"
3
+ require "mix_tape/version"
4
+ require "mix_tape/builder"
5
+
6
+ module MixTape
7
+ end
@@ -0,0 +1,12 @@
1
+ require 'mix_tape'
2
+
3
+ namespace :mix_tape do
4
+ desc "Generates list of defined events"
5
+ task :events do
6
+ MixTape::Builder.mix_tape.each do |event, desc|
7
+ puts "++ #{event} ++"
8
+ puts desc
9
+ puts
10
+ end
11
+ end
12
+ end
data/mix_tape.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mix_tape/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mix_tape"
8
+ spec.version = MixTape::VERSION
9
+ spec.authors = ['Omar Sahyoun']
10
+ spec.email = ['omar@quipper.com']
11
+ spec.description = %q{Tidy up your mixpanel commits}
12
+ spec.summary = %q{Tidy up your mixpanel commits}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency 'rspec'
24
+
25
+ spec.add_dependency 'mixpanel'
26
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ MixTape::Builder.definition do
4
+
5
+ button_click "Log number of times user clicks button" do |user, button|
6
+ {
7
+ user_name: user.username,
8
+ distinct_id: user.id,
9
+ button_id: button.id,
10
+ button_page: button.page
11
+ }
12
+ end
13
+
14
+ checks_mail "When user checks mail" do |user, inbox|
15
+ {
16
+ user_name: user.username,
17
+ user_id: user.id,
18
+ unread_count: inbox.count
19
+ }
20
+ end
21
+ end
22
+
23
+ describe "Triggering Events" do
24
+ let(:user) { double(username: 'Zeus', id: '1') }
25
+ let(:button) { double(id: '2', page: 'homepage') }
26
+ let(:client) { double('client') }
27
+
28
+ before do
29
+ MixTape.stub(:client){ client }
30
+ end
31
+
32
+ it "tracks" do
33
+ expected_properties = { user_name: "Zeus", distinct_id: "1", button_id: "2", button_page: "homepage" }
34
+
35
+ client.should_receive(:track).with("button_click", expected_properties)
36
+ MixTape.track_button_click(user, button)
37
+ end
38
+
39
+ it "sets" do
40
+ expected_properties = { user_name: "Zeus", distinct_id: "1", button_id: "2", button_page: "homepage" }
41
+
42
+ client.should_receive(:set).with("1", expected_properties)
43
+ MixTape.set_button_click(user.id, user, button)
44
+ end
45
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Configuraton' do
4
+ it "sets token" do
5
+ MixTape.config do |config|
6
+ config.token = '1234'
7
+ end
8
+
9
+ expect(MixTape.token).to eq('1234')
10
+ end
11
+
12
+ it "raises when token not defined" do
13
+ MixTape.config{ |config|config.token = '' }
14
+
15
+ expect{
16
+ MixTape.client
17
+ }.to raise_error("MixPanel token is undefined.")
18
+ end
19
+ end
20
+
@@ -0,0 +1,8 @@
1
+ require 'rspec'
2
+ require 'mix_tape'
3
+
4
+ RSpec.configure do |config|
5
+ config.color_enabled = true
6
+ config.tty = true
7
+ config.formatter = :documentation # :progress, :html, :textmate
8
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mix_tape
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Omar Sahyoun
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: mixpanel
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Tidy up your mixpanel commits
79
+ email:
80
+ - omar@quipper.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - lib/mix_tape.rb
91
+ - lib/mix_tape/builder.rb
92
+ - lib/mix_tape/client.rb
93
+ - lib/mix_tape/version.rb
94
+ - lib/tasks/documentation.rake
95
+ - mix_tape.gemspec
96
+ - spec/lib/mix_tape/builder_spec.rb
97
+ - spec/lib/mix_tape/config_spec.rb
98
+ - spec/spec_helper.rb
99
+ homepage: ''
100
+ licenses:
101
+ - MIT
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 1.8.24
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: Tidy up your mixpanel commits
124
+ test_files:
125
+ - spec/lib/mix_tape/builder_spec.rb
126
+ - spec/lib/mix_tape/config_spec.rb
127
+ - spec/spec_helper.rb