saucy-kiss 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ 0.1.0
2
+
3
+ Instead of:
4
+
5
+ before_filter Saucy::Kiss::KissmetricsIdentityControllerFilter
6
+
7
+ include filters as:
8
+
9
+ include Saucy::Kiss::ControllerFilters
10
+
1
11
  0.0.2
2
12
 
3
13
  Add Ben Orenstein as additional author.
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = saucy-kiss
2
2
 
3
- Saucy-KISS is an extension to the Saucy gem for tracking your SaaS events
3
+ Saucy-kiss is an extension to the Saucy gem for tracking your SaaS events
4
4
  in KISSmetrics.
5
5
 
6
6
  It depends on the unofficial KISSmetrics gem http://rubygems.org/gems/kissmetrics
@@ -16,19 +16,6 @@ We assume that:
16
16
  advantage of KISSmetrics' anonymous identity tracking, automatic handling
17
17
  of the "Visited Site" metric, bot/crawler blacklisting, etc.
18
18
 
19
- By using the kissmetrics gem, we support:
20
-
21
- * Testing your KISSmetrics integration points.
22
-
23
- * Using the KISSmetrics JS API from the request/response cycle by storing
24
- identity, events, and properties in the session and rendering them into your
25
- view as JS calls, similar to the Rails flash.
26
-
27
- * Using the KISSmetrics HTTP API from outside the request/response cycle (think
28
- billing callbacks, or queued operations) delivered directly. Patches for
29
- queued delivery of HTTP API calls (Resque, Delayed::Job, QueueClassic, etc.)
30
- are welcome.
31
-
32
19
  == Supported events
33
20
 
34
21
  Saucy-kiss records all the KISSmetrics SaaS events http://support.kissmetrics.com/apis/saas_events:
@@ -39,6 +26,8 @@ Saucy-kiss records all the KISSmetrics SaaS events http://support.kissmetrics.co
39
26
  * Billed
40
27
  * Canceled
41
28
 
29
+ == Future work
30
+
42
31
  TODO: Additional events provided by Saucy:
43
32
 
44
33
  * Viewed Plan List
@@ -69,8 +58,7 @@ http://support.kissmetrics.com/advanced/identity-management
69
58
 
70
59
  In your Gemfile:
71
60
 
72
- gem "saucy-kiss" # depend on kissmetrics, snogmetrics
73
- gem "snogmetrics", :git => "git://github.com/jasonm/snogmetrics" # only until snogmetrics accepts my patch
61
+ gem "saucy-kiss"
74
62
 
75
63
  Then:
76
64
 
@@ -89,7 +77,7 @@ Add an initializer in config/initializers/saucy_kiss.rb:
89
77
 
90
78
  Add a filter to each request in ApplicationController:
91
79
 
92
- before_filter Saucy::Kiss::KissmetricsIdentityControllerFilter
80
+ include Saucy::Kiss::ControllerFilters
93
81
 
94
82
  Note: Saucy::Kiss will automatically instantiate the Snogmetrics gem like this:
95
83
 
@@ -140,6 +128,13 @@ Saucy-kiss distinguishes between in-request events and out-of-request events,
140
128
  because it prefers delivering events to KISSmetrics via the JS API where
141
129
  possible; this is only possible for in-request events.
142
130
 
131
+ Using the snogmetrics gem, we record to the KISSmetrics JS API from within the
132
+ request/response cycle by storing identity, events, and properties in the session
133
+ and rendering them into your view as JS calls, similar to the Rails flash.
134
+
135
+ Using the kissmetrics gem, we record to the KISSmetrics HTTP API from outside the
136
+ request/response cycle (think billing callbacks, or queued operations) delivered directly.
137
+
143
138
  == Contributing to saucy-kiss
144
139
 
145
140
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
@@ -0,0 +1,18 @@
1
+ module Saucy
2
+ module Kiss
3
+ module ControllerFilters
4
+ def identify_to_kissmetrics
5
+ if current_account
6
+ km.identify("account-#{current_account.id}")
7
+ else
8
+ km.identify(nil)
9
+ end
10
+ end
11
+
12
+ def self.included(base)
13
+ base.send(:hide_action, :identify_to_kissmetrics)
14
+ base.send(:before_filter, :identify_to_kissmetrics)
15
+ end
16
+ end
17
+ end
18
+ end
data/lib/saucy-kiss.rb CHANGED
@@ -1,2 +1,2 @@
1
1
  require 'saucy/kiss/observer'
2
- require 'saucy/kiss/controller_identity_filter'
2
+ require 'saucy/kiss/controller_filters'
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ class FakeController
4
+ class << self
5
+ attr_accessor :before_filters, :hidden_actions
6
+ end
7
+
8
+ attr_reader :km
9
+
10
+ def initialize(km)
11
+ @km = km
12
+ end
13
+
14
+ def self.before_filter(filter)
15
+ @before_filters ||= []
16
+ @before_filters << filter
17
+ end
18
+
19
+ def self.hide_action(hidden_actions)
20
+ @hidden_actions ||= []
21
+ @hidden_actions << hidden_actions
22
+ end
23
+ end
24
+
25
+ describe Saucy::Kiss::ControllerFilters do
26
+ let(:km) { stub('kissmetrics client', :identify => true) }
27
+ let(:account) { stub('account', :id => 12345) }
28
+
29
+ let(:controller_class) do
30
+ Class.new(FakeController) do
31
+ include Saucy::Kiss::ControllerFilters
32
+ end
33
+ end
34
+
35
+ let(:controller) { controller_class.new(km) }
36
+
37
+ it "includes #identify_to_kissmetrics as a before_filter" do
38
+ controller_class.before_filters.should == [:identify_to_kissmetrics]
39
+ end
40
+
41
+ it "hides the #identify_to_kissmetrics method" do
42
+ controller_class.hidden_actions.should == [:identify_to_kissmetrics]
43
+ end
44
+
45
+ it "sets identity based on the account if there is a current_account when there is a current_account" do
46
+ controller.stub(:current_account => account)
47
+ km.should_receive(:identify).with("account-12345")
48
+ controller.identify_to_kissmetrics
49
+ end
50
+
51
+ it "clears identity when there is not a current_account" do
52
+ controller.stub(:current_account => nil)
53
+ km.should_receive(:identify).with(nil)
54
+ controller.identify_to_kissmetrics
55
+ end
56
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: saucy-kiss
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jason Morrison
@@ -123,10 +123,10 @@ extra_rdoc_files:
123
123
  - LICENSE.txt
124
124
  - README.rdoc
125
125
  files:
126
- - lib/saucy/kiss/controller_identity_filter.rb
126
+ - lib/saucy/kiss/controller_filters.rb
127
127
  - lib/saucy/kiss/observer.rb
128
128
  - lib/saucy-kiss.rb
129
- - spec/saucy/kiss/controller_identity_filter_spec.rb
129
+ - spec/saucy/kiss/controller_filters_spec.rb
130
130
  - spec/saucy/kiss/observer_spec.rb
131
131
  - spec/spec_helper.rb
132
132
  - spec/support/rails_env.rb
@@ -1,13 +0,0 @@
1
- module Saucy
2
- module Kiss
3
- class ControllerIdentityFilter
4
- def self.filter(controller)
5
- if controller.current_account
6
- controller.km.identify("account-#{controller.current_account.id}")
7
- else
8
- controller.km.identify(nil)
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Saucy::Kiss::ControllerIdentityFilter do
4
- let(:km) { stub('kissmetrics client', :identify => true) }
5
- let(:account) { stub('account', :id => 12345) }
6
-
7
- context "when there is a current_account" do
8
- let(:controller) { stub('controller', :km => km, :current_account => account) }
9
-
10
- it "sets identity based on the account if there is a current_account" do
11
- controller.should_receive(:km).with()
12
- km.should_receive(:identify).with("account-12345")
13
-
14
- Saucy::Kiss::ControllerIdentityFilter.filter(controller)
15
- end
16
- end
17
-
18
- context "when there is not a current_account" do
19
- let(:controller) { stub('controller', :km => km, :current_account => nil) }
20
-
21
- it "clears identity" do
22
- controller.should_receive(:km).with()
23
- km.should_receive(:identify).with(nil)
24
- Saucy::Kiss::ControllerIdentityFilter.filter(controller)
25
- end
26
- end
27
- end