notches 0.3.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MGJhY2U0YmUzMTc4ZTQ3Nzg2MTk2NzY5MDhmNGU5ZGExOTg5NTAyMw==
5
+ data.tar.gz: !binary |-
6
+ YWQ1ZTVlM2I4MWQ5ZTI0MzI0YmQ4ZDMzMTk5MWZhMDczNjIzYjUyYw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YmNiZmFmZGZlOGQ4ODQ5Yjg4ZjBmMzY0OTAwODQ1M2RmODBmNDVjNTdkZDJh
10
+ YjY0ZTM0MTkwNWNkOTQ2OGY0ZjU3NjNmMTA2ODI2ZDI0YjhiYmExMTIwOGFl
11
+ ZTI4OWJlMzc4NWQ5MTRhM2Y5MjU1MzhmNTJmNjllNzJlYjc1NDQ=
12
+ data.tar.gz: !binary |-
13
+ ZDcwZWQ2MjQ1YWVmMDk2MjRlZmY0ZDMxNDg0MjkwNTQwNmE5N2QwYTc1Yzg5
14
+ MzA2MjkzZjE4NWViMzhiYTFkMDU0MjVjMTkxOGZmOWZiMGZmZWU3ZjJmMzgy
15
+ YmFlMTI5ZjA0N2RmZmVlYTJkZGFhNWIzMTVlZjZiOTE5Njk4MWU=
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
@@ -1,11 +1,13 @@
1
1
  class Notches::HitsController < ActionController::Base
2
2
  def new
3
3
  session[:notched] = true
4
+
4
5
  Notches::Hit.log(
5
- :url => params[:url],
6
+ :url => params[:url],
6
7
  :user_agent => request.env["HTTP_USER_AGENT"],
8
+ :user_id => params[:user_id],
7
9
  :session_id => request.session_options[:id],
8
- :ip => request.remote_ip
10
+ :ip => request.remote_ip
9
11
  )
10
12
 
11
13
  # Don't cache the image.
@@ -14,18 +14,30 @@ class Notches::Hit < ActiveRecord::Base
14
14
  belongs_to :date, :foreign_key => :notches_date_id
15
15
  belongs_to :time, :foreign_key => :notches_time_id
16
16
 
17
- scope :unique, group("notches_url_id, notches_session_id, notches_ip_id")
17
+ scope :unique, -> { group("notches_url_id, notches_session_id, notches_ip_id") }
18
18
 
19
19
  def self.log(attributes)
20
+ attributes[:user_agent] ||= ''
20
21
  hit = self.new
21
22
  hit.transaction do
22
23
  Rails.logger.info("[Notches] Tracking #{attributes.inspect} at #{Date.today} #{Time.now}")
23
- hit.url = Notches::URL.find_or_create_by_url(attributes[:url])
24
- hit.user_agent = Notches::UserAgent.find_or_create_by_user_agent(attributes[:user_agent])
25
- hit.session = Notches::Session.find_or_create_by_session_id(attributes[:session_id])
26
- hit.ip = Notches::IP.find_or_create_by_ip(attributes[:ip])
27
- hit.date = Notches::Date.find_or_create_by_date(Date.today)
28
- hit.time = Notches::Time.find_or_create_by_time(Time.now)
24
+ hit.url = Notches::URL.find_or_create_by(url: attributes[:url])
25
+ hit.user_agent = Notches::UserAgent.find_or_create_by(
26
+ user_agent_md5: Digest::MD5.hexdigest(attributes[:user_agent]),
27
+ :user_agent => attributes[:user_agent]
28
+ )
29
+ hit.session = Notches::Session.find_or_create_by(session_id: attributes[:session_id])
30
+ hit.ip = Notches::IP.find_or_create_by(ip: attributes[:ip])
31
+ hit.date = Notches::Date.find_or_create_by(date: Date.today)
32
+ hit.time = Notches::Time.find_or_create_by(time: Time.now)
33
+
34
+ if attributes[:user_id].present?
35
+ Notches::UserSession.find_or_create_by(
36
+ user_id: attributes[:user_id],
37
+ notches_session_id: hit.session.id
38
+ )
39
+ end
40
+
29
41
  begin
30
42
  hit.save!
31
43
  rescue #ActiveRecord::RecordNotUnique
@@ -0,0 +1,8 @@
1
+ class Notches::UserSession < ActiveRecord::Base
2
+ self.table_name = "notches_user_sessions"
3
+
4
+ validates :user_id, :presence => true
5
+ validates :session, :presence => true
6
+
7
+ belongs_to :session, :foreign_key => :notches_session_id
8
+ end
@@ -0,0 +1,35 @@
1
+ class AddIndexToUserAgents < ActiveRecord::Migration
2
+ def up
3
+ add_column :notches_user_agents, :user_agent_md5, :string
4
+ add_index :notches_user_agents, :user_agent_md5
5
+ change_table :notches_hits do |t|
6
+ t.remove_index :name => :notches_index
7
+ end
8
+ add_index :notches_hits, [
9
+ :notches_time_id,
10
+ :notches_date_id,
11
+ :notches_ip_id,
12
+ :notches_session_id,
13
+ :notches_url_id,
14
+ :notches_user_agent_id
15
+ ], :name => :notches_index, :unique => true
16
+ Notches::UserAgent.find_each do |user_agent|
17
+ user_agent.update_attribute(:user_agent_md5, Digest::MD5.hexdigest(user_agent.user_agent))
18
+ end
19
+ end
20
+
21
+ def down
22
+ remove_index :notches_user_agents, :user_agent_md5
23
+ remove_column :notches_user_agents, :user_agent_md5
24
+ change_table :notches_hits do |t|
25
+ t.remove_index :name => :notches_index
26
+ end
27
+ add_index :notches_hits, [
28
+ :notches_time_id,
29
+ :notches_date_id,
30
+ :notches_ip_id,
31
+ :notches_session_id,
32
+ :notches_url_id
33
+ ], :name => :notches_index, :unique => true
34
+ end
35
+ end
@@ -0,0 +1,14 @@
1
+ class CreateNotchesUserSessions < ActiveRecord::Migration
2
+ def up
3
+ create_table :notches_user_sessions do |t|
4
+ t.integer :user_id, :null => false
5
+ t.integer :notches_session_id, :null => false
6
+ end
7
+ add_index :notches_user_sessions, :user_id, :unique => true
8
+ end
9
+
10
+ def down
11
+ remove_index :notches_user_sessions, :user_id
12
+ drop_table :notches_user_sessions
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Notches
2
- VERSION = '0.3.1'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -20,9 +20,9 @@ Gem::Specification.new do |s|
20
20
  }
21
21
  s.require_paths = ['lib']
22
22
 
23
- s.add_runtime_dependency 'rails', '~> 3.1'
23
+ s.add_runtime_dependency 'rails', '~> 4.0'
24
24
 
25
- s.add_development_dependency 'combustion', '~> 0.3.2'
26
- s.add_development_dependency 'rspec-rails', '~> 2.11'
25
+ s.add_development_dependency 'combustion', '~> 0.5.1'
26
+ s.add_development_dependency 'rspec-rails', '~> 2.14'
27
27
  s.add_development_dependency 'sqlite3', '~> 1.3.4'
28
28
  end
@@ -13,7 +13,7 @@ describe Notches::HitsController do
13
13
  @request.stub(:remote_ip => '234.101.82.14')
14
14
  @request.stub(:session_options => { :id => 'abcd' })
15
15
 
16
- get :new, :url => '/posts', :format => 'gif'
16
+ get :new, :url => '/posts', :user_id => 7, :format => 'gif'
17
17
 
18
18
  Notches::Hit.count.should == 1
19
19
  hit = Notches::Hit.first
@@ -21,6 +21,7 @@ describe Notches::HitsController do
21
21
  hit.user_agent.user_agent.should == 'FeedBurner/1.0'
22
22
  hit.ip.ip.should == '234.101.82.14'
23
23
  hit.session.session_id.should == 'abcd'
24
+ Notches::UserSession.exists?(notches_session_id: hit.session.id, user_id: 7).should be_true
24
25
  end
25
26
  end
26
27
  end
@@ -70,10 +70,11 @@ describe Notches::Hit do
70
70
  hit.date.date.should == today
71
71
  hit.time.time.strftime('%H:%M:%S').should == now.strftime('%H:%M:%S')
72
72
  hit.user_agent.user_agent.should == 'FeedBurner/1.0'
73
+ hit.user_agent.user_agent_md5.should == Digest::MD5.hexdigest('FeedBurner/1.0')
73
74
  end
74
75
  end
75
76
 
76
- let(:existing_hit) {
77
+ let(:existing_hit) {
77
78
  Notches::Hit.log(
78
79
  :url => "/posts/1",
79
80
  :user_agent => 'FeedBurner/1.0',
@@ -152,5 +153,18 @@ describe Notches::Hit do
152
153
  }.to_not change { Notches::Hit.count }
153
154
  end
154
155
  end
156
+
157
+ context "when given a user id" do
158
+ it "attaches the user id to the session" do
159
+ hit = Notches::Hit.log({
160
+ :url => '/posts',
161
+ :user_agent => 'FeedBurner/1.0',
162
+ :user_id => 7,
163
+ :session_id => '1',
164
+ :ip => '0.0.0.1'
165
+ })
166
+ Notches::UserSession.exists?(notches_session_id: hit.session.id, user_id: 7).should be_true
167
+ end
168
+ end
155
169
  end
156
170
  end
@@ -1,12 +1,12 @@
1
1
  require 'rubygems'
2
- require 'bundler'
2
+ require 'bundler/setup'
3
3
 
4
- Bundler.require :default, :development
4
+ require 'combustion'
5
5
 
6
- Combustion.initialize!
6
+ Combustion.initialize! :active_record, :action_controller, :action_view
7
7
 
8
8
  require 'rspec/rails'
9
9
 
10
10
  RSpec.configure do |config|
11
11
  config.use_transactional_fixtures = true
12
- end
12
+ end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notches
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
5
- prerelease:
4
+ version: 0.5.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Cillian O'Ruanaidh
@@ -10,72 +9,64 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2012-08-01 00:00:00.000000000 Z
12
+ date: 2013-09-29 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
15
+ prerelease: false
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '4.0'
16
21
  name: rails
17
22
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
23
  requirements:
20
24
  - - ~>
21
25
  - !ruby/object:Gem::Version
22
- version: '3.1'
26
+ version: '4.0'
23
27
  type: :runtime
28
+ - !ruby/object:Gem::Dependency
24
29
  prerelease: false
25
30
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
31
  requirements:
28
32
  - - ~>
29
33
  - !ruby/object:Gem::Version
30
- version: '3.1'
31
- - !ruby/object:Gem::Dependency
34
+ version: 0.5.1
32
35
  name: combustion
33
36
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
37
  requirements:
36
38
  - - ~>
37
39
  - !ruby/object:Gem::Version
38
- version: 0.3.2
40
+ version: 0.5.1
39
41
  type: :development
42
+ - !ruby/object:Gem::Dependency
40
43
  prerelease: false
41
44
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
45
  requirements:
44
46
  - - ~>
45
47
  - !ruby/object:Gem::Version
46
- version: 0.3.2
47
- - !ruby/object:Gem::Dependency
48
+ version: '2.14'
48
49
  name: rspec-rails
49
50
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '2.11'
54
+ version: '2.14'
55
55
  type: :development
56
+ - !ruby/object:Gem::Dependency
56
57
  prerelease: false
57
58
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
59
  requirements:
60
60
  - - ~>
61
61
  - !ruby/object:Gem::Version
62
- version: '2.11'
63
- - !ruby/object:Gem::Dependency
62
+ version: 1.3.4
64
63
  name: sqlite3
65
64
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
65
  requirements:
68
66
  - - ~>
69
67
  - !ruby/object:Gem::Version
70
68
  version: 1.3.4
71
69
  type: :development
72
- prerelease: false
73
- version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ~>
77
- - !ruby/object:Gem::Version
78
- version: 1.3.4
79
70
  description: A Rails Engine for tracking your web traffic.
80
71
  email:
81
72
  - contact@cilliano.com
@@ -98,10 +89,13 @@ files:
98
89
  - app/models/notches/time.rb
99
90
  - app/models/notches/url.rb
100
91
  - app/models/notches/user_agent.rb
92
+ - app/models/notches/user_session.rb
101
93
  - config.ru
102
94
  - config/routes.rb
103
95
  - db/migrate/20120323111734_create_notches.rb
104
96
  - db/migrate/20120713142636_create_notches_user_agents.rb
97
+ - db/migrate/20120910093652_add_index_to_user_agents.rb
98
+ - db/migrate/20130918115023_create_notches_user_sessions.rb
105
99
  - lib/notches.rb
106
100
  - lib/notches/engine.rb
107
101
  - lib/notches/version.rb
@@ -116,33 +110,26 @@ files:
116
110
  - spec/spec_helper.rb
117
111
  homepage: http://github.com/hypertiny/notches
118
112
  licenses: []
113
+ metadata: {}
119
114
  post_install_message:
120
115
  rdoc_options: []
121
116
  require_paths:
122
117
  - lib
123
118
  required_ruby_version: !ruby/object:Gem::Requirement
124
- none: false
125
119
  requirements:
126
120
  - - ! '>='
127
121
  - !ruby/object:Gem::Version
128
122
  version: '0'
129
- segments:
130
- - 0
131
- hash: 1687754116731628172
132
123
  required_rubygems_version: !ruby/object:Gem::Requirement
133
- none: false
134
124
  requirements:
135
125
  - - ! '>='
136
126
  - !ruby/object:Gem::Version
137
127
  version: '0'
138
- segments:
139
- - 0
140
- hash: 1687754116731628172
141
128
  requirements: []
142
129
  rubyforge_project: notches
143
- rubygems_version: 1.8.24
130
+ rubygems_version: 2.0.3
144
131
  signing_key:
145
- specification_version: 3
132
+ specification_version: 4
146
133
  summary: Simple Rails web traffic counter
147
134
  test_files:
148
135
  - spec/controllers/notches/hits_controller_spec.rb