gricer 0.0.1

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.
Files changed (88) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +84 -0
  3. data/Rakefile +49 -0
  4. data/app/assets/images/gricer/fluid/breadcrumb.png +0 -0
  5. data/app/assets/javascripts/gricer.js.coffee +85 -0
  6. data/app/assets/javascripts/gricer_backend_jquery.js.coffee +352 -0
  7. data/app/assets/javascripts/jquery.flot.js +2599 -0
  8. data/app/assets/javascripts/jquery.flot.pie.js +750 -0
  9. data/app/assets/javascripts/jquery.flot.resize.js +60 -0
  10. data/app/assets/javascripts/jquery.flot.symbol.js +70 -0
  11. data/app/assets/javascripts/worldmap.js +146 -0
  12. data/app/assets/stylesheets/gricer/fluid-jquery-ui.css.scss +1298 -0
  13. data/app/assets/stylesheets/gricer/fluid.css.scss +240 -0
  14. data/app/assets/stylesheets/gricer/helpers/css3.css.scss +21 -0
  15. data/app/controllers/gricer/base_controller.rb +141 -0
  16. data/app/controllers/gricer/capture_controller.rb +42 -0
  17. data/app/controllers/gricer/dashboard_controller.rb +18 -0
  18. data/app/controllers/gricer/requests_controller.rb +42 -0
  19. data/app/controllers/gricer/sessions_controller.rb +24 -0
  20. data/app/helpers/gricer/base_helper.rb +22 -0
  21. data/app/models/gricer/agent.rb +789 -0
  22. data/app/models/gricer/request.rb +239 -0
  23. data/app/models/gricer/session.rb +433 -0
  24. data/app/views/gricer/capture/index.html.erb +1 -0
  25. data/app/views/gricer/dashboard/_menu.html.erb +10 -0
  26. data/app/views/gricer/dashboard/_overview.html.erb +33 -0
  27. data/app/views/gricer/dashboard/index.html.erb +19 -0
  28. data/config/routes.rb +51 -0
  29. data/lib/gricer.rb +36 -0
  30. data/lib/gricer/action_controller/base.rb +28 -0
  31. data/lib/gricer/action_controller/track.rb +132 -0
  32. data/lib/gricer/active_model/statistics.rb +167 -0
  33. data/lib/gricer/config.rb +125 -0
  34. data/lib/gricer/engine.rb +9 -0
  35. data/lib/gricer/localization.rb +3 -0
  36. data/lib/tasks/gricer_tasks.rake +92 -0
  37. data/spec/controllers/gricer/base_controller_spec.rb +207 -0
  38. data/spec/controllers/gricer/capture_controller_spec.rb +44 -0
  39. data/spec/controllers/gricer/dashboard_controller_spec.rb +44 -0
  40. data/spec/controllers/gricer/requests_controller_spec.rb +36 -0
  41. data/spec/controllers/gricer/sessions_controller_spec.rb +37 -0
  42. data/spec/dummy/Rakefile +7 -0
  43. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  44. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  45. data/spec/dummy/app/assets/stylesheets/dashboard.css +4 -0
  46. data/spec/dummy/app/assets/stylesheets/scaffold.css +56 -0
  47. data/spec/dummy/app/assets/stylesheets/sessions.css +4 -0
  48. data/spec/dummy/app/controllers/application_controller.rb +23 -0
  49. data/spec/dummy/app/controllers/dashboard_controller.rb +19 -0
  50. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  51. data/spec/dummy/app/helpers/dashboard_helper.rb +2 -0
  52. data/spec/dummy/app/views/dashboard/index.html.erb +236 -0
  53. data/spec/dummy/app/views/layouts/application.html.erb +16 -0
  54. data/spec/dummy/config.ru +4 -0
  55. data/spec/dummy/config/application.rb +48 -0
  56. data/spec/dummy/config/boot.rb +10 -0
  57. data/spec/dummy/config/cucumber.yml +9 -0
  58. data/spec/dummy/config/database.yml +25 -0
  59. data/spec/dummy/config/environment.rb +5 -0
  60. data/spec/dummy/config/environments/development.rb +27 -0
  61. data/spec/dummy/config/environments/production.rb +51 -0
  62. data/spec/dummy/config/environments/test.rb +39 -0
  63. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  64. data/spec/dummy/config/initializers/inflections.rb +10 -0
  65. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  66. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  67. data/spec/dummy/config/initializers/session_store.rb +8 -0
  68. data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
  69. data/spec/dummy/config/locales/en.yml +5 -0
  70. data/spec/dummy/config/routes.rb +11 -0
  71. data/spec/dummy/db/schema.rb +241 -0
  72. data/spec/dummy/log/development.log +0 -0
  73. data/spec/dummy/public/404.html +26 -0
  74. data/spec/dummy/public/422.html +26 -0
  75. data/spec/dummy/public/500.html +26 -0
  76. data/spec/dummy/public/favicon.ico +0 -0
  77. data/spec/dummy/script/rails +6 -0
  78. data/spec/helpers/gricer/base_helper_spec.rb +28 -0
  79. data/spec/lib/gricer/action_controller/track_spec.rb +63 -0
  80. data/spec/models/gricer/agent_spec.rb +829 -0
  81. data/spec/models/gricer/request_spec.rb +145 -0
  82. data/spec/models/gricer/session_spec.rb +209 -0
  83. data/spec/routing/capture_routes_spec.rb +6 -0
  84. data/spec/routing/dashboard_routes_spec.rb +9 -0
  85. data/spec/routing/requests_routes_spec.rb +90 -0
  86. data/spec/routing/sessions_routes_spec.rb +115 -0
  87. data/spec/spec_helper.rb +23 -0
  88. metadata +185 -0
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gricer::DashboardController do
4
+ context 'index' do
5
+ it 'should render template' do
6
+ get :index
7
+ response.should be_success
8
+ response.should render_template(:index)
9
+ response.content_type.should == 'text/html'
10
+ end
11
+
12
+ it 'should assign sessions' do
13
+ get :index
14
+ assigns[:sessions].class.should == ActiveRecord::Relation
15
+ end
16
+
17
+ it 'should assign requests' do
18
+ get :index
19
+ assigns[:requests].class.should == ActiveRecord::Relation
20
+ end
21
+ end
22
+
23
+ context 'overview' do
24
+ it 'should render template' do
25
+ xhr :post, :overview
26
+ response.should be_success
27
+ response.should render_template(:overview)
28
+ # For some reason the content_type in the test is 'text/javascript'
29
+ # When requested it returns a 'text/html', so this is ok
30
+ # response.content_type.should == 'text/html'
31
+ end
32
+
33
+ it 'should assign sessions' do
34
+ xhr :post, :overview
35
+ assigns[:sessions].class.should == ActiveRecord::Relation
36
+ assigns[:sessions].inspect == ActiveRecord::Relation
37
+ end
38
+
39
+ it 'should assign requests' do
40
+ xhr :post, :overview
41
+ assigns[:requests].class.should == ActiveRecord::Relation
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gricer::RequestsController do
4
+ context 'process_stats' do
5
+ it 'should render json' do
6
+ xhr :get, :process_stats, field: :path
7
+ response.should be_success
8
+ response.content_type.should == 'application/json'
9
+ end
10
+ end
11
+
12
+ context 'spread_stats' do
13
+ it 'should render json' do
14
+ xhr :get, :spread_stats, field: :path
15
+ response.should be_success
16
+ response.content_type.should == 'application/json'
17
+ end
18
+ end
19
+
20
+ context 'basic_collection' do
21
+ it 'should define basic collection' do
22
+ Gricer::Request.should_receive(:browsers) { 'collection' }
23
+ collection = controller.send(:basic_collection)
24
+ collection.should == 'collection' end
25
+ end
26
+
27
+ context 'further_details' do
28
+ it 'should return a hash' do
29
+ controller.send(:further_details).class.should == Hash
30
+ end
31
+
32
+ it 'should have many entries' do
33
+ controller.send(:further_details).size.should > 1
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gricer::SessionsController do
4
+ context 'process_stats' do
5
+ it 'should render json' do
6
+ xhr :get, :process_stats, field: :java
7
+ response.should be_success
8
+ response.content_type.should == 'application/json'
9
+ end
10
+ end
11
+
12
+ context 'spread_stats' do
13
+ it 'should render json' do
14
+ xhr :get, :spread_stats, field: :java
15
+ response.should be_success
16
+ response.content_type.should == 'application/json'
17
+ end
18
+ end
19
+
20
+ context 'basic_collection' do
21
+ it 'should define basic collection' do
22
+ Gricer::Session.should_receive(:browsers) { 'collection' }
23
+ collection = controller.send(:basic_collection)
24
+ collection.should == 'collection'
25
+ end
26
+ end
27
+
28
+ context 'further_details' do
29
+ it 'should return a hash' do
30
+ controller.send(:further_details).class.should == Hash
31
+ end
32
+
33
+ it 'should have many entries' do
34
+ controller.send(:further_details).size.should > 1
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,9 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require jquery
8
+ //= require jquery_ujs
9
+ //= require gricer
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require gricer/fluid
7
+ */
8
+
9
+
10
+ th {
11
+ text-align: right;
12
+ }
13
+
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,23 @@
1
+ class User
2
+ def id
3
+ 42
4
+ end
5
+ end
6
+
7
+ class ApplicationController < ActionController::Base
8
+ protect_from_forgery
9
+
10
+ gricer_track_requests
11
+
12
+ def gricer_user_id
13
+ current_user.try(:id)
14
+ end
15
+
16
+ private
17
+ def current_user
18
+ User.new
19
+ end
20
+
21
+
22
+
23
+ end
@@ -0,0 +1,19 @@
1
+ class DashboardController < ApplicationController
2
+
3
+ helper Gricer::BaseHelper
4
+
5
+ def index
6
+ end
7
+
8
+ def error
9
+ this_function_does_not_exist
10
+ end
11
+
12
+ def forbidden
13
+ render text: 'Forbidden', status: 403
14
+ end
15
+
16
+ def redirect
17
+ redirect_to '/'
18
+ end
19
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module DashboardHelper
2
+ end
@@ -0,0 +1,236 @@
1
+ <h1>Gricer Request tracker</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <td colspan='2'><h2>Request</h2></td>
6
+ </tr>
7
+
8
+ <tr>
9
+ <th>Requested at:</th>
10
+ <td><%=l gricer_request.created_at%></td>
11
+ </tr>
12
+
13
+
14
+ <tr>
15
+ <th>Host:</th>
16
+ <td><%= gricer_request.host %></td>
17
+ </tr>
18
+ <tr>
19
+ <th>Path:</th>
20
+ <td><%= gricer_request.path %></td>
21
+ </tr>
22
+ <tr>
23
+ <th>Request Method:</th>
24
+ <td><%= gricer_request.method %></td>
25
+ </tr>
26
+ <tr>
27
+ <th>Request Protocol:</th>
28
+ <td><%= gricer_request.protocol %></td>
29
+ </tr>
30
+
31
+ <tr>
32
+ <th>Refererer Protocol:</th>
33
+ <td><%= gricer_request.referer_protocol %></td>
34
+ </tr>
35
+ <tr>
36
+ <th>Refererer Host:</th>
37
+ <td><%= gricer_request.referer_host %></td>
38
+ </tr>
39
+ <tr>
40
+ <th>Refererer Path:</th>
41
+ <td><%= gricer_request.referer_path %></td>
42
+ </tr>
43
+ <tr>
44
+ <th>Refererer Params:</th>
45
+ <td><%= gricer_request.referer_params %></td>
46
+ </tr>
47
+ <tr>
48
+ <th>Refering Search Engine:</th>
49
+ <td><%= gricer_request.search_engine %></td>
50
+ </tr>
51
+ <tr>
52
+ <th>Search Engine Query:</th>
53
+ <td><%= gricer_request.search_query %></td>
54
+ </tr>
55
+
56
+ <tr>
57
+ <th>First in Session:</th>
58
+ <td><%= gricer_request.is_first_in_session %></td>
59
+ </tr>
60
+
61
+ <tr>
62
+ <th>Controller:</th>
63
+ <td><%= gricer_request.controller %></td>
64
+ </tr>
65
+ <tr>
66
+ <th>Action:</th>
67
+ <td><%= gricer_request.action %></td>
68
+ </tr>
69
+ <tr>
70
+ <th>Format:</th>
71
+ <td><%= gricer_request.format %></td>
72
+ </tr>
73
+ <tr>
74
+ <th>Param ID:</th>
75
+ <td><%= gricer_request.param_id %></td>
76
+ </tr>
77
+ <tr>
78
+ <th>Locale:</th>
79
+ <td><%= gricer_request.locale %></td>
80
+ </tr>
81
+ <tr>
82
+ <th>User:</th>
83
+ <td><%= gricer_request.user_id %></td>
84
+ </tr>
85
+
86
+ <!-- JS values -->
87
+ <tr>
88
+ <th>Javascript:</th>
89
+ <td class="gricer-js">disabled</td>
90
+ </tr>
91
+ <tr>
92
+ <th>Window Size:</th>
93
+ <td id="gricer-w">N/A</td>
94
+ </tr>
95
+
96
+ <tr>
97
+ <td colspan='2'><h2>Agent</h2></td>
98
+ </tr>
99
+
100
+ <tr>
101
+ <th>Request Header:</th>
102
+ <td><%= gricer_request.agent.request_header %></td>
103
+ </tr>
104
+ <tr>
105
+ <th>Name:</th>
106
+ <td><%= gricer_request.agent.name %></td>
107
+ </tr>
108
+ <tr>
109
+ <th>Version:</th>
110
+ <td><%= gricer_request.agent.full_version %></td>
111
+ </tr>
112
+ <tr>
113
+ <th>Major Version:</th>
114
+ <td><%= gricer_request.agent.major_version %></td>
115
+ </tr>
116
+ <tr>
117
+ <th>Engine:</th>
118
+ <td><%= gricer_request.agent.engine_name %></td>
119
+ </tr>
120
+ <tr>
121
+ <th>Engine Version:</th>
122
+ <td><%= gricer_request.agent.engine_version %></td>
123
+ </tr>
124
+ <tr>
125
+ <th>OS:</th>
126
+ <td><%= gricer_request.agent.os %></td>
127
+ </tr>
128
+ <tr>
129
+ <th>Type:</th>
130
+ <td><%= gricer_request.agent.agent_class.to_s.humanize %></td>
131
+ </tr>
132
+ <tr>
133
+ <th>Number of Requests:</th>
134
+ <td><%= gricer_request.agent.requests_count.to_i + 1 %></td>
135
+ </tr>
136
+ <tr>
137
+ <th>Number of Sessions:</th>
138
+ <td><%= gricer_request.agent.sessions_count.to_i + ( gricer_request.is_first_in_session ? 1 : 0 ) %></td>
139
+ </tr>
140
+
141
+ <tr>
142
+ <td colspan='2'><h2>Session</h2></td>
143
+ </tr>
144
+
145
+ <tr>
146
+ <th>IP Hash:</th>
147
+ <td><%= gricer_request.session.ip_address_hash %></td>
148
+ </tr>
149
+ <tr>
150
+ <th>Domain:</th>
151
+ <td><%= gricer_request.session.domain %></td>
152
+ </tr>
153
+ <tr>
154
+ <th>Country:</th>
155
+ <td><%= gricer_request.session.country %></td>
156
+ </tr>
157
+ <tr>
158
+ <th>Requested Locale:</th>
159
+ <td><%= gricer_request.session.requested_locale %></td>
160
+ </tr>
161
+ <tr>
162
+ <th>Region:</th>
163
+ <td><%= gricer_request.session.region %></td>
164
+ </tr>
165
+ <tr>
166
+ <th>City:</th>
167
+ <td><%= gricer_request.session.city %></td>
168
+ </tr>
169
+ <tr>
170
+ <th>Postal Code:</th>
171
+ <td><%= gricer_request.session.postal_code %></td>
172
+ </tr>
173
+ <tr>
174
+ <th>Longitude:</th>
175
+ <td><%= gricer_request.session.longitude %></td>
176
+ </tr>
177
+ <tr>
178
+ <th>Latitude:</th>
179
+ <td><%= gricer_request.session.latitude %></td>
180
+ </tr>
181
+ <tr>
182
+ <th>Number of Requests:</th>
183
+ <td><%= gricer_request.session.requests_count.to_i + 1 %></td>
184
+ </tr>
185
+ <tr>
186
+ <th>Visitor Type:</th>
187
+ <td><%= gricer_request.session.previous_session_id ? 'Returning Visitor' : 'New Visitor' %></td>
188
+ </tr>
189
+ <tr>
190
+ <th>Started at:</th>
191
+ <td><%=l gricer_request.session.created_at %></td>
192
+ </tr>
193
+ <tr>
194
+ <th>Duration:</th>
195
+ <td><%=format_seconds gricer_request.session.duration %></td>
196
+ </tr>
197
+
198
+ <!-- JS values -->
199
+ <tr>
200
+ <th>Javascript:</th>
201
+ <td class="gricer-js">disabled</td>
202
+ </tr>
203
+ <tr>
204
+ <th>Java:</th>
205
+ <td id="gricer-j">N/A</td>
206
+ </tr>
207
+ <tr>
208
+ <th>Flash:</th>
209
+ <td id="gricer-f">N/A</td>
210
+ </tr>
211
+ <tr>
212
+ <th>Silverlight:</th>
213
+ <td id="gricer-sl">N/A</td>
214
+ </tr>
215
+ <tr>
216
+ <th>Screen Size:</th>
217
+ <td id="gricer-s">N/A</td>
218
+ </tr>
219
+ <tr>
220
+ <th>Screen Depth:</th>
221
+ <td id="gricer-sd">N/A</td>
222
+ </tr>
223
+ </table>
224
+
225
+ <script type="text/javascript">
226
+ $(function() {
227
+ var values = Gricer.prepareValues();
228
+ $('.gricer-js').html('enabled');
229
+ $('#gricer-j').html(values.j ? 'true' : 'false');
230
+ $('#gricer-f').html(values.f ? values.f : 'false');
231
+ $('#gricer-sl').html(values.sl ? values.sl : 'false');
232
+ $('#gricer-s').html(values.sx + 'x' + values.sy);
233
+ $('#gricer-sd').html(values.sd);
234
+ $('#gricer-w').html(values.wx + 'x' + values.wy);
235
+ });
236
+ </script>