impressionist 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,30 @@
1
+ module Impressionist
2
+ module Impressionable
3
+ def is_impressionable
4
+ has_many :impressions, :as=>:impressionable
5
+ include InstanceMethods
6
+ end
7
+
8
+ module InstanceMethods
9
+ def impressionable?
10
+ true
11
+ end
12
+
13
+ def impression_count(start_date=nil,end_date=Time.now)
14
+ start_date.blank? ? impressions.all.size : impressions.where("created_at>=? and created_at<=?",start_date,end_date).all.size
15
+ end
16
+
17
+ def unique_impression_count(start_date=nil,end_date=Time.now)
18
+ start_date.blank? ? impressions.group(:request_hash).all.size : impressions.where("created_at>=? and created_at<=?",start_date,end_date).group(:request_hash).all.size
19
+ end
20
+
21
+ def unique_impression_count_ip(start_date=nil,end_date=Time.now)
22
+ start_date.blank? ? impressions.group(:ip_address).all.size : impressions.where("created_at>=? and created_at<=?",start_date,end_date).group(:ip_address).all.size
23
+ end
24
+
25
+ def unique_impression_count_session(start_date=nil,end_date=Time.now)
26
+ start_date.blank? ? impressions.group(:session_hash).all.size : impressions.where("created_at>=? and created_at<=?",start_date,end_date).group(:session_hash).all.size
27
+ end
28
+ end
29
+ end
30
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,110 @@
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
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{impressionist}
8
+ s.version = "0.3.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["cowboycoded"]
12
+ s.date = %q{2011-03-06}
13
+ s.description = %q{Log impressions from controller actions or from a model}
14
+ s.email = %q{john.mcaliley@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "CHANGELOG.rdoc",
21
+ "Gemfile",
22
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "app/controllers/impressionist_controller.rb",
27
+ "app/models/impression.rb",
28
+ "app/models/impressionist/bots.rb",
29
+ "app/models/impressionist/impressionable.rb",
30
+ "config/routes.rb",
31
+ "impressionist.gemspec",
32
+ "lib/generators/impressionist/impressionist_generator.rb",
33
+ "lib/generators/impressionist/templates/create_impressions_table.rb",
34
+ "lib/impressionist.rb",
35
+ "lib/impressionist/bots.rb",
36
+ "lib/impressionist/engine.rb",
37
+ "lib/impressionist/railties/tasks.rake",
38
+ "upgrade_migrations/version_0_3_0.rb"
39
+ ]
40
+ s.homepage = %q{http://github.com/cowboycoded/impressionist}
41
+ s.licenses = ["MIT"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = %q{1.3.7}
44
+ s.summary = %q{Easy way to log impressions}
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
52
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
54
+ s.add_development_dependency(%q<rcov>, [">= 0"])
55
+ s.add_development_dependency(%q<ZenTest>, [">= 0"])
56
+ s.add_development_dependency(%q<autotest>, [">= 0"])
57
+ s.add_development_dependency(%q<systemu>, [">= 0"])
58
+ s.add_development_dependency(%q<rspec>, [">= 0"])
59
+ s.add_development_dependency(%q<rspec-rails>, [">= 0"])
60
+ s.add_development_dependency(%q<mongrel>, ["= 1.2.0.pre2"])
61
+ s.add_development_dependency(%q<capybara>, [">= 0"])
62
+ s.add_development_dependency(%q<database_cleaner>, [">= 0"])
63
+ s.add_development_dependency(%q<cucumber-rails>, [">= 0"])
64
+ s.add_development_dependency(%q<cucumber>, [">= 0"])
65
+ s.add_development_dependency(%q<spork>, [">= 0"])
66
+ s.add_development_dependency(%q<launchy>, [">= 0"])
67
+ s.add_development_dependency(%q<autotest-notification>, [">= 0"])
68
+ s.add_development_dependency(%q<httpclient>, [">= 0"])
69
+ else
70
+ s.add_dependency(%q<shoulda>, [">= 0"])
71
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
72
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
73
+ s.add_dependency(%q<rcov>, [">= 0"])
74
+ s.add_dependency(%q<ZenTest>, [">= 0"])
75
+ s.add_dependency(%q<autotest>, [">= 0"])
76
+ s.add_dependency(%q<systemu>, [">= 0"])
77
+ s.add_dependency(%q<rspec>, [">= 0"])
78
+ s.add_dependency(%q<rspec-rails>, [">= 0"])
79
+ s.add_dependency(%q<mongrel>, ["= 1.2.0.pre2"])
80
+ s.add_dependency(%q<capybara>, [">= 0"])
81
+ s.add_dependency(%q<database_cleaner>, [">= 0"])
82
+ s.add_dependency(%q<cucumber-rails>, [">= 0"])
83
+ s.add_dependency(%q<cucumber>, [">= 0"])
84
+ s.add_dependency(%q<spork>, [">= 0"])
85
+ s.add_dependency(%q<launchy>, [">= 0"])
86
+ s.add_dependency(%q<autotest-notification>, [">= 0"])
87
+ s.add_dependency(%q<httpclient>, [">= 0"])
88
+ end
89
+ else
90
+ s.add_dependency(%q<shoulda>, [">= 0"])
91
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
92
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
93
+ s.add_dependency(%q<rcov>, [">= 0"])
94
+ s.add_dependency(%q<ZenTest>, [">= 0"])
95
+ s.add_dependency(%q<autotest>, [">= 0"])
96
+ s.add_dependency(%q<systemu>, [">= 0"])
97
+ s.add_dependency(%q<rspec>, [">= 0"])
98
+ s.add_dependency(%q<rspec-rails>, [">= 0"])
99
+ s.add_dependency(%q<mongrel>, ["= 1.2.0.pre2"])
100
+ s.add_dependency(%q<capybara>, [">= 0"])
101
+ s.add_dependency(%q<database_cleaner>, [">= 0"])
102
+ s.add_dependency(%q<cucumber-rails>, [">= 0"])
103
+ s.add_dependency(%q<cucumber>, [">= 0"])
104
+ s.add_dependency(%q<spork>, [">= 0"])
105
+ s.add_dependency(%q<launchy>, [">= 0"])
106
+ s.add_dependency(%q<autotest-notification>, [">= 0"])
107
+ s.add_dependency(%q<httpclient>, [">= 0"])
108
+ end
109
+ end
110
+
@@ -0,0 +1,20 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ class ImpressionistGenerator < Rails::Generators::Base
5
+ include Rails::Generators::Migration
6
+ source_root File.join(File.dirname(__FILE__), 'templates')
7
+
8
+ def self.next_migration_number(dirname)
9
+ sleep 1
10
+ if ActiveRecord::Base.timestamped_migrations
11
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
12
+ else
13
+ "%.3d" % (current_migration_number(dirname) + 1)
14
+ end
15
+ end
16
+
17
+ def create_migration_file
18
+ migration_template 'create_impressions_table.rb', 'db/migrate/create_impressions_table.rb'
19
+ end
20
+ end
@@ -0,0 +1,36 @@
1
+ class CreateImpressionsTable < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :impressions, :force => true do |t|
4
+ t.string :impressionable_type
5
+ t.integer :impressionable_id
6
+ t.integer :user_id
7
+ t.string :controller_name
8
+ t.string :action_name
9
+ t.string :view_name
10
+ t.string :request_hash
11
+ t.string :session_hash
12
+ t.string :ip_address
13
+ t.string :message
14
+ t.timestamps
15
+ end
16
+ add_index :impressions, [:impressionable_type, :impressionable_id, :request_hash], :name => "poly_request_index", :unique => false
17
+ add_index :impressions, [:impressionable_type, :impressionable_id, :ip_address], :name => "poly_ip_index", :unique => false
18
+ add_index :impressions, [:impressionable_type, :impressionable_id, :session_hash], :name => "poly_session_index", :unique => false
19
+ add_index :impressions, [:controller_name,:action_name,:request_hash], :name => "controlleraction_request_index", :unique => false
20
+ add_index :impressions, [:controller_name,:action_name,:ip_address], :name => "controlleraction_ip_index", :unique => false
21
+ add_index :impressions, [:controller_name,:action_name,:session_hash], :name => "controlleraction_session_index", :unique => false
22
+ add_index :impressions, :user_id
23
+ end
24
+
25
+ def self.down
26
+ remove_index :impressions, :name => :poly_request_index
27
+ remove_index :impressions, :name => :poly_ip_index
28
+ remove_index :impressions, :name => :poly_session_index
29
+ remove_index :impressions, :name => :controlleraction_request_index
30
+ remove_index :impressions, :name => :controlleraction_ip_index
31
+ remove_index :impressions, :name => :controlleraction_session_index
32
+ remove_index :impressions, :user_id
33
+
34
+ drop_table :impressions
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ IMPRESSIONIST_PATH = File.dirname(__FILE__) + "/impressionist"
2
+ require "#{IMPRESSIONIST_PATH}/engine.rb"
3
+
4
+ module Impressionist
5
+ end
@@ -0,0 +1,18 @@
1
+ require 'httpclient'
2
+ require 'nokogiri'
3
+
4
+ module Impressionist
5
+ module Bots
6
+ LIST_URL = "http://www.user-agents.org/allagents.xml"
7
+ def self.consume
8
+ response = HTTPClient.new.get_content(LIST_URL)
9
+ doc = Nokogiri::XML(response)
10
+ list = []
11
+ doc.xpath('//user-agent').each do |agent|
12
+ type = agent.xpath("Type").text
13
+ list << agent.xpath("String").text.gsub("&lt;","<") if ["R","S"].include?(type) #gsub hack for badly formatted data
14
+ end
15
+ list
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ require "impressionist"
2
+ require "rails"
3
+
4
+ module Impressionist
5
+ class Engine < Rails::Engine
6
+ initializer 'impressionist.extend_ar' do |app|
7
+ ActiveRecord::Base.extend Impressionist::Impressionable
8
+ end
9
+
10
+ initializer 'impressionist.controller' do
11
+ ActiveSupport.on_load(:action_controller) do
12
+ include ImpressionistController::InstanceMethods
13
+ extend ImpressionistController::ClassMethods
14
+ end
15
+ end
16
+ end
17
+ end
File without changes
@@ -0,0 +1,27 @@
1
+ class CreateImpressionsTable < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :impressions, :session_hash, :string
4
+ remove_index :impressions, :name => :poly_index
5
+ remove_index :impressions, :name => :controlleraction_index
6
+ add_index :impressions, [:impressionable_type, :impressionable_id, :request_hash], :name => "poly_request_index", :unique => false
7
+ add_index :impressions, [:impressionable_type, :impressionable_id, :ip_address], :name => "poly_ip_index", :unique => false
8
+ add_index :impressions, [:impressionable_type, :impressionable_id, :session_hash], :name => "poly_session_index", :unique => false
9
+ add_index :impressions, [:controller_name,:action_name,:request_hash], :name => "controlleraction_request_index", :unique => false
10
+ add_index :impressions, [:controller_name,:action_name,:ip_address], :name => "controlleraction_ip_index", :unique => false
11
+ add_index :impressions, [:controller_name,:action_name,:session_hash], :name => "controlleraction_session_index", :unique => false
12
+
13
+ end
14
+
15
+ def self.down
16
+ remove_column :impressions, :session_hash
17
+ remove_index :impressions, :name => :poly_request_index
18
+ remove_index :impressions, :name => :poly_ip_index
19
+ remove_index :impressions, :name => :poly_session_index
20
+ remove_index :impressions, :name => :controlleraction_request_index
21
+ remove_index :impressions, :name => :controlleraction_ip_index
22
+ remove_index :impressions, :name => :controlleraction_session_index
23
+ remove_index :impressions, :user_id
24
+ add_index :impressions, [:impressionable_type, :impressionable_id, :request_hash, :ip_address], :name => "poly_index", :unique => false
25
+ add_index :impressions, [:controller_name,:action_name,:request_hash,:ip_address], :name => "controlleraction_index", :unique => false
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,324 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: impressionist
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 1
9
+ version: 0.3.1
10
+ platform: ruby
11
+ authors:
12
+ - cowboycoded
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-03-06 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: shoulda
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ prerelease: false
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 1
42
+ - 0
43
+ - 0
44
+ version: 1.0.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: jeweler
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 1
57
+ - 5
58
+ - 1
59
+ version: 1.5.1
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: rcov
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ type: :development
74
+ prerelease: false
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: ZenTest
78
+ requirement: &id005 !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: *id005
89
+ - !ruby/object:Gem::Dependency
90
+ name: autotest
91
+ requirement: &id006 !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *id006
102
+ - !ruby/object:Gem::Dependency
103
+ name: systemu
104
+ requirement: &id007 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ segments:
110
+ - 0
111
+ version: "0"
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: *id007
115
+ - !ruby/object:Gem::Dependency
116
+ name: rspec
117
+ requirement: &id008 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ type: :development
126
+ prerelease: false
127
+ version_requirements: *id008
128
+ - !ruby/object:Gem::Dependency
129
+ name: rspec-rails
130
+ requirement: &id009 !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ segments:
136
+ - 0
137
+ version: "0"
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: *id009
141
+ - !ruby/object:Gem::Dependency
142
+ name: mongrel
143
+ requirement: &id010 !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - "="
147
+ - !ruby/object:Gem::Version
148
+ segments:
149
+ - 1
150
+ - 2
151
+ - 0
152
+ - pre2
153
+ version: 1.2.0.pre2
154
+ type: :development
155
+ prerelease: false
156
+ version_requirements: *id010
157
+ - !ruby/object:Gem::Dependency
158
+ name: capybara
159
+ requirement: &id011 !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ segments:
165
+ - 0
166
+ version: "0"
167
+ type: :development
168
+ prerelease: false
169
+ version_requirements: *id011
170
+ - !ruby/object:Gem::Dependency
171
+ name: database_cleaner
172
+ requirement: &id012 !ruby/object:Gem::Requirement
173
+ none: false
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ segments:
178
+ - 0
179
+ version: "0"
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: *id012
183
+ - !ruby/object:Gem::Dependency
184
+ name: cucumber-rails
185
+ requirement: &id013 !ruby/object:Gem::Requirement
186
+ none: false
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ segments:
191
+ - 0
192
+ version: "0"
193
+ type: :development
194
+ prerelease: false
195
+ version_requirements: *id013
196
+ - !ruby/object:Gem::Dependency
197
+ name: cucumber
198
+ requirement: &id014 !ruby/object:Gem::Requirement
199
+ none: false
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ segments:
204
+ - 0
205
+ version: "0"
206
+ type: :development
207
+ prerelease: false
208
+ version_requirements: *id014
209
+ - !ruby/object:Gem::Dependency
210
+ name: spork
211
+ requirement: &id015 !ruby/object:Gem::Requirement
212
+ none: false
213
+ requirements:
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ segments:
217
+ - 0
218
+ version: "0"
219
+ type: :development
220
+ prerelease: false
221
+ version_requirements: *id015
222
+ - !ruby/object:Gem::Dependency
223
+ name: launchy
224
+ requirement: &id016 !ruby/object:Gem::Requirement
225
+ none: false
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ segments:
230
+ - 0
231
+ version: "0"
232
+ type: :development
233
+ prerelease: false
234
+ version_requirements: *id016
235
+ - !ruby/object:Gem::Dependency
236
+ name: autotest-notification
237
+ requirement: &id017 !ruby/object:Gem::Requirement
238
+ none: false
239
+ requirements:
240
+ - - ">="
241
+ - !ruby/object:Gem::Version
242
+ segments:
243
+ - 0
244
+ version: "0"
245
+ type: :development
246
+ prerelease: false
247
+ version_requirements: *id017
248
+ - !ruby/object:Gem::Dependency
249
+ name: httpclient
250
+ requirement: &id018 !ruby/object:Gem::Requirement
251
+ none: false
252
+ requirements:
253
+ - - ">="
254
+ - !ruby/object:Gem::Version
255
+ segments:
256
+ - 0
257
+ version: "0"
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: *id018
261
+ description: Log impressions from controller actions or from a model
262
+ email: john.mcaliley@gmail.com
263
+ executables: []
264
+
265
+ extensions: []
266
+
267
+ extra_rdoc_files:
268
+ - LICENSE.txt
269
+ - README.rdoc
270
+ files:
271
+ - CHANGELOG.rdoc
272
+ - Gemfile
273
+ - LICENSE.txt
274
+ - README.rdoc
275
+ - Rakefile
276
+ - VERSION
277
+ - app/controllers/impressionist_controller.rb
278
+ - app/models/impression.rb
279
+ - app/models/impressionist/bots.rb
280
+ - app/models/impressionist/impressionable.rb
281
+ - config/routes.rb
282
+ - impressionist.gemspec
283
+ - lib/generators/impressionist/impressionist_generator.rb
284
+ - lib/generators/impressionist/templates/create_impressions_table.rb
285
+ - lib/impressionist.rb
286
+ - lib/impressionist/bots.rb
287
+ - lib/impressionist/engine.rb
288
+ - lib/impressionist/railties/tasks.rake
289
+ - upgrade_migrations/version_0_3_0.rb
290
+ has_rdoc: true
291
+ homepage: http://github.com/cowboycoded/impressionist
292
+ licenses:
293
+ - MIT
294
+ post_install_message:
295
+ rdoc_options: []
296
+
297
+ require_paths:
298
+ - lib
299
+ required_ruby_version: !ruby/object:Gem::Requirement
300
+ none: false
301
+ requirements:
302
+ - - ">="
303
+ - !ruby/object:Gem::Version
304
+ hash: 2559717242736027668
305
+ segments:
306
+ - 0
307
+ version: "0"
308
+ required_rubygems_version: !ruby/object:Gem::Requirement
309
+ none: false
310
+ requirements:
311
+ - - ">="
312
+ - !ruby/object:Gem::Version
313
+ segments:
314
+ - 0
315
+ version: "0"
316
+ requirements: []
317
+
318
+ rubyforge_project:
319
+ rubygems_version: 1.3.7
320
+ signing_key:
321
+ specification_version: 3
322
+ summary: Easy way to log impressions
323
+ test_files: []
324
+