devise_keen 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9eda9f2d7a8e03e47bb7d23a1d6cabbf4293c803
4
+ data.tar.gz: bc13378e957a35b7f96a6d91959aceb2c2c4b4f6
5
+ SHA512:
6
+ metadata.gz: 8e5b4b579054a15876c18fac6f9aa2e943de5239d6d6afb8b20f4125019620f140d6a7345b54920a50f5aee244f5042c0d6bfe96594cceb16e772707bfe0d6e6
7
+ data.tar.gz: 5bbff614bca428be4940f99ce1de2f5a67fc8616171fb72f3cc3aba19abe54024305a6c14927b890e20090b0a773b60dd0637f87b1cd716484b67a9b7913d1f2
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem 'rails'
7
+ gem 'warden'
8
+ gem 'devise'
9
+ gem 'keen'
10
+
11
+ # Add dependencies to develop your gem here.
12
+ # Include everything needed to run rake, tests, features, etc.
13
+ group :development do
14
+ gem "shoulda", ">= 0"
15
+ gem "rdoc", "~> 3.12"
16
+ gem "bundler", "~> 1.0"
17
+ gem "jeweler", "~> 2.0.1"
18
+ gem "simplecov", ">= 0"
19
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Alex Kleissner
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ # devise_keen gem
2
+
3
+ Track user signin and signouts automatically to your Keen IO project.
4
+
5
+ ## Requirements
6
+
7
+ The devise_keen gem requires the [keen gem](https://rubygems.org/gems/keen) and a [Keen IO account](https://keen.io) (free to sign up).
8
+
9
+ ## Configuration
10
+
11
+ There are three configuration paramters:
12
+
13
+ * `keen_project_id`
14
+ *Required*. The project id to write to.
15
+ * `keen_write_key`
16
+ *Required*. The Keen IO write key.
17
+ * `keen_collection`
18
+ The optional collection name to store events in. If not set, will default to `devise-keen`
19
+
20
+ Define these variables in `config/initializers/devise.rb`.
21
+
22
+ Example config:
23
+
24
+ ```ruby
25
+ # Keen IO Config
26
+ config.keen_project_id = "ASDF12345"
27
+ config.keen_write_key = "REALLYLONGWRITEKEYHERE1234567890"
28
+ config.keen_collection = "user-events"
29
+ ```
30
+
31
+ ## Contributing to devise_keen
32
+
33
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
34
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
35
+ * Fork the project.
36
+ * Start a feature/bugfix branch.
37
+ * Commit and push until you are happy with your contribution.
38
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
39
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
40
+
41
+ ## Copyright
42
+
43
+ Copyright (c) 2014 Alex Kleissner. See LICENSE.txt for
44
+ further details.
45
+
@@ -0,0 +1,19 @@
1
+ = devise_keen
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to devise_keen
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2014 Alex Kleissner. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "devise_keen"
18
+ gem.homepage = "http://github.com/alex@keen.io/devise_keen"
19
+ gem.license = "MIT"
20
+ gem.summary = "Add basic automatic logging to the Keen IO service when a user logs in."
21
+ gem.description = "Publish an event to your Keen IO project every time a user logs in. Allows for customizing the collection name."
22
+ gem.email = "alex@keen.io"
23
+ gem.authors = ["Alex Kleissner"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ desc "Code coverage detail"
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = "true"
38
+ Rake::Task['test'].execute
39
+ end
40
+
41
+ task :default => :test
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "devise_keen #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,82 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: devise_keen 0.1.1 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "devise_keen"
9
+ s.version = "0.1.1"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Alex Kleissner"]
14
+ s.date = "2014-09-16"
15
+ s.description = "Publish an event to your Keen IO project every time a user logs in. Allows for customizing the collection name."
16
+ s.email = "alex@keen.io"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md",
20
+ "README.rdoc"
21
+ ]
22
+ s.files = [
23
+ ".document",
24
+ "Gemfile",
25
+ "LICENSE.txt",
26
+ "README.md",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "devise_keen.gemspec",
31
+ "lib/devise_keen.rb",
32
+ "lib/devise_keen/hooks/keen_metrics.rb",
33
+ "lib/devise_keen/hooks/signin.rb",
34
+ "lib/devise_keen/hooks/signout.rb",
35
+ "lib/devise_keen/model.rb",
36
+ "lib/devise_keen/rails.rb",
37
+ "lib/devise_keen/version.rb",
38
+ "test/helper.rb",
39
+ "test/test_devise_keen.rb"
40
+ ]
41
+ s.homepage = "http://github.com/alex@keen.io/devise_keen"
42
+ s.licenses = ["MIT"]
43
+ s.rubygems_version = "2.2.2"
44
+ s.summary = "Add basic automatic logging to the Keen IO service when a user logs in."
45
+
46
+ if s.respond_to? :specification_version then
47
+ s.specification_version = 4
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<rails>, [">= 0"])
51
+ s.add_runtime_dependency(%q<warden>, [">= 0"])
52
+ s.add_runtime_dependency(%q<devise>, [">= 0"])
53
+ s.add_runtime_dependency(%q<keen>, [">= 0"])
54
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
55
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
56
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
57
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
58
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
59
+ else
60
+ s.add_dependency(%q<rails>, [">= 0"])
61
+ s.add_dependency(%q<warden>, [">= 0"])
62
+ s.add_dependency(%q<devise>, [">= 0"])
63
+ s.add_dependency(%q<keen>, [">= 0"])
64
+ s.add_dependency(%q<shoulda>, [">= 0"])
65
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
66
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
67
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
68
+ s.add_dependency(%q<simplecov>, [">= 0"])
69
+ end
70
+ else
71
+ s.add_dependency(%q<rails>, [">= 0"])
72
+ s.add_dependency(%q<warden>, [">= 0"])
73
+ s.add_dependency(%q<devise>, [">= 0"])
74
+ s.add_dependency(%q<keen>, [">= 0"])
75
+ s.add_dependency(%q<shoulda>, [">= 0"])
76
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
77
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
78
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
79
+ s.add_dependency(%q<simplecov>, [">= 0"])
80
+ end
81
+ end
82
+
@@ -0,0 +1,35 @@
1
+ unless defined?(Devise)
2
+ require 'devise'
3
+ end
4
+ require 'keen'
5
+ require 'devise_keen'
6
+
7
+ Devise.add_module :keen_trackable, :model => 'devise_keen/model'
8
+
9
+ module Devise
10
+ # Public: The Keen project id to use when recording events.
11
+ # Set keen_project_id in the Devise configuration file (config/initializers/devise.rb)
12
+ #
13
+ # Devise.keen_project_id = "YOURPROJECTID"
14
+ mattr_accessor :keen_project_id
15
+ @@keen_project_id = nil
16
+
17
+ # Public: The Keen Write Key for your project. Used to record events.
18
+ # Set keen_write_key in the Devise configuration file (config/initializers/devise.rb)
19
+ #
20
+ # Devise.keen_write_key = "YOUR_WRITE_KEY"
21
+ mattr_accessor :keen_write_key
22
+ @@keen_write_key = nil
23
+
24
+ # Public: The name of the collection to use when recording events.
25
+ # Set keen_collection in the Devise configuration file (config/initializers/devise.rb)
26
+ #
27
+ # Devise.keen_collection = "devise-keen"
28
+ mattr_accessor :keen_collection
29
+ @@keen_collection = "devise-keen"
30
+ end
31
+
32
+ module KeenTrackable
33
+ end
34
+
35
+ require 'devise_keen/rails'
@@ -0,0 +1,5 @@
1
+ Warden::Manager.after_set_user do |record, warden, opts|
2
+ if record.respond_to?(:record_login)
3
+ record.record_login
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ Warden::Manager.after_authentication do |record, warden, opts|
2
+ if record.respond_to?(:keen_record_signin)
3
+ record.keen_record_signin
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ Warden::Manager.before_logout do |record, warden, opts|
2
+ if record.respond_to?(:keen_record_signout)
3
+ record.keen_record_signout
4
+ end
5
+ end
@@ -0,0 +1,41 @@
1
+ require 'devise_keen/hooks/signin'
2
+ require 'devise_keen/hooks/signout'
3
+
4
+ module Devise
5
+ module Models
6
+ module KeenTrackable
7
+ def keen_record_signin
8
+ self.publish_action("signin", {sign_in_time: self.current_sign_in_at})
9
+ end
10
+
11
+ def keen_record_signout
12
+ self.publish_action("signout", {sign_out_time: Time.now.iso8601})
13
+ end
14
+
15
+ protected
16
+ def publish_action(action, params)
17
+ raise new Exception("Must define keen_project_id.") if self.class.keen_project_id.nil?
18
+ raise new Exception("Must define keen_write_key.") if self.class.keen_write_key.nil?
19
+
20
+ keen = Keen::Client.new(project_id: self.class.keen_project_id,
21
+ write_key: self.class.keen_write_key)
22
+
23
+ event_params = {
24
+ user: {
25
+ id: self.id,
26
+ email: self.email
27
+ },
28
+ action: "#{action}"
29
+ }
30
+
31
+ event_params.merge!(params)
32
+
33
+ keen.publish(self.class.keen_collection, event_params)
34
+ end
35
+ end
36
+
37
+ Devise::Models.config(self, :keen_project_id)
38
+ Devise::Models.config(self, :keen_write_key)
39
+ Devise::Models.config(self, :keen_collection)
40
+ end
41
+ end
@@ -0,0 +1,6 @@
1
+ require 'devise_keen'
2
+
3
+ module DeviseKeen
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module DeviseKeen
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,34 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_adapter 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ require 'rubygems'
18
+ require 'bundler'
19
+ begin
20
+ Bundler.setup(:default, :development)
21
+ rescue Bundler::BundlerError => e
22
+ $stderr.puts e.message
23
+ $stderr.puts "Run `bundle install` to install missing gems"
24
+ exit e.status_code
25
+ end
26
+ require 'test/unit'
27
+ require 'shoulda'
28
+
29
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
30
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
31
+ require 'devise_keen'
32
+
33
+ class Test::Unit::TestCase
34
+ end
@@ -0,0 +1,4 @@
1
+ require 'helper'
2
+
3
+ class TestDeviseKeen < Test::Unit::TestCase
4
+ end
metadata ADDED
@@ -0,0 +1,190 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devise_keen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Alex Kleissner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: warden
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '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'
41
+ - !ruby/object:Gem::Dependency
42
+ name: devise
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: keen
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: shoulda
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rdoc
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.12'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.12'
97
+ - !ruby/object:Gem::Dependency
98
+ name: bundler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: jeweler
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 2.0.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 2.0.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Publish an event to your Keen IO project every time a user logs in. Allows
140
+ for customizing the collection name.
141
+ email: alex@keen.io
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files:
145
+ - LICENSE.txt
146
+ - README.md
147
+ - README.rdoc
148
+ files:
149
+ - ".document"
150
+ - Gemfile
151
+ - LICENSE.txt
152
+ - README.md
153
+ - README.rdoc
154
+ - Rakefile
155
+ - VERSION
156
+ - devise_keen.gemspec
157
+ - lib/devise_keen.rb
158
+ - lib/devise_keen/hooks/keen_metrics.rb
159
+ - lib/devise_keen/hooks/signin.rb
160
+ - lib/devise_keen/hooks/signout.rb
161
+ - lib/devise_keen/model.rb
162
+ - lib/devise_keen/rails.rb
163
+ - lib/devise_keen/version.rb
164
+ - test/helper.rb
165
+ - test/test_devise_keen.rb
166
+ homepage: http://github.com/alex@keen.io/devise_keen
167
+ licenses:
168
+ - MIT
169
+ metadata: {}
170
+ post_install_message:
171
+ rdoc_options: []
172
+ require_paths:
173
+ - lib
174
+ required_ruby_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ required_rubygems_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ requirements: []
185
+ rubyforge_project:
186
+ rubygems_version: 2.2.2
187
+ signing_key:
188
+ specification_version: 4
189
+ summary: Add basic automatic logging to the Keen IO service when a user logs in.
190
+ test_files: []