simplestats 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,29 +8,41 @@ a view helper that tracks information from the client-side of a request.
8
8
  Both parts can be used independently, and when used together, SimpleStats will
9
9
  automatically store them together in the same MongoDB record.
10
10
 
11
- # How to use
11
+ ## How to use
12
12
 
13
- Mount as engine somewhere in your application:
13
+ Mount as engine somewhere in your `config/routes.rb`:
14
14
 
15
- mount SimpleStats, "/stats"
15
+ mount SimpleStats::Engine, "/stats"
16
16
 
17
- The following stuff is still TODO:
17
+ Include the middleware component in your `config/application.rb`:
18
18
 
19
- * Add SimpleStats::Middleware as Rack middleware to collect
20
- information from the server-side of the request.
21
- * In your layout, add
19
+ config.middleware.use SimpleStats::Middleware
22
20
 
23
- <%= simple_stats_collector %>
21
+ In your layout, add:
24
22
 
25
- ## Contributing to simplestats
26
-
27
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
28
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
29
- * Fork the project.
30
- * Start a feature/bugfix branch.
31
- * Commit and push until you are happy with your contribution.
32
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
33
- * 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.
23
+ :javascript
24
+ $(document).ready(function(){
25
+ jQuery.post("/stats", {
26
+ professional_id: #{@professional.id},
27
+ patient_id: #{@patient.id},
28
+ url: $(location).attr('href'),
29
+
30
+ browser: {
31
+ document: {
32
+ width: $(document).width(),
33
+ height: $(document).height()
34
+ }
35
+ }
36
+ });
37
+ });
38
+
39
+ ## TODO
40
+
41
+ * View helpers like
42
+
43
+ <%=
44
+ simple_stats_collector(:professional_id => @professional.id)
45
+ %>
34
46
 
35
47
  ## Copyright
36
48
 
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ require 'jeweler'
14
14
  Jeweler::Tasks.new do |gem|
15
15
  # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
16
16
  gem.name = "simplestats"
17
- gem.homepage = "http://github.com/marten/simplestats"
17
+ gem.homepage = "http://roqua.github.com/simplestats"
18
18
  gem.license = "MIT"
19
19
  gem.summary = %Q{A really simple webstats collection engine}
20
20
  gem.description = %Q{A Sinatra application that makes it easy to collect and store web statistics}
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
@@ -1,27 +1,2 @@
1
- require 'sinatra/base'
2
- require 'mongoid'
3
-
4
- class SimpleStats < Sinatra::Base
5
-
6
- class Stat
7
- include Mongoid::Document
8
- end
9
-
10
- # This endpoint can be used to create a new stat
11
- # for a request. If you don't want to store server-side
12
- # processing information, this is probably what you want.
13
- post '/' do
14
- Stat.create!(params)
15
- return 200
16
- end
17
-
18
- # This endpoint can be used to update an existing stat
19
- # for a request. This makes it possible to create the
20
- # stat from the controller action with information from
21
- # there, and update it later on from the browser.
22
- post '/:id' do |id|
23
- Stat.find(id).update_attributes(params)
24
- return 200
25
- end
26
-
27
- end
1
+ require "simplestats/engine"
2
+ require "simplestats/middleware"
@@ -0,0 +1,23 @@
1
+ require 'sinatra/base'
2
+ require 'simplestats/stat'
3
+
4
+ module SimpleStats
5
+ class Engine < Sinatra::Base
6
+ # This endpoint can be used to create a new stat
7
+ # for a request. If you don't want to store server-side
8
+ # processing information, this is probably what you want.
9
+ post '/' do
10
+ Stat.create!(params)
11
+ return 200
12
+ end
13
+
14
+ # This endpoint can be used to update an existing stat
15
+ # for a request. This makes it possible to create the
16
+ # stat from the controller action with information from
17
+ # there, and update it later on from the browser.
18
+ post '/:id' do |id|
19
+ Stat.find(id).update_attributes(params)
20
+ return 200
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ require 'simplestats/stat'
2
+
3
+ module SimpleStats
4
+ class Middleware
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ stat = SimpleStats::Stat.create(server_address: env["SERVER_ADDR"],
11
+ server_port: env["SERVER_PORT"],
12
+ request: {
13
+ uri: env["REQUEST_URI"]
14
+ })
15
+
16
+ status, headers, body = @app.call(env.merge("simplestats.stat_id" => stat.id.to_s))
17
+ [status, headers, body]
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ require 'mongoid'
2
+
3
+ module SimpleStats
4
+ class Stat
5
+ include Mongoid::Document
6
+ end
7
+ end
@@ -0,0 +1,77 @@
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 = "simplestats"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Marten Veldthuis"]
12
+ s.date = "2012-02-17"
13
+ s.description = "A Sinatra application that makes it easy to collect and store web statistics"
14
+ s.email = "marten@veldthuis.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".rspec",
21
+ ".travis.yml",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/simplestats.rb",
29
+ "lib/simplestats/engine.rb",
30
+ "lib/simplestats/middleware.rb",
31
+ "lib/simplestats/stat.rb",
32
+ "simplestats.gemspec",
33
+ "spec/simplestats/engine_spec.rb",
34
+ "spec/simplestats/middleware_spec.rb",
35
+ "spec/simplestats/stat_spec.rb",
36
+ "spec/spec_helper.rb"
37
+ ]
38
+ s.homepage = "http://roqua.github.com/simplestats"
39
+ s.licenses = ["MIT"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = "1.8.11"
42
+ s.summary = "A really simple webstats collection engine"
43
+
44
+ if s.respond_to? :specification_version then
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_runtime_dependency(%q<sinatra>, ["~> 1.3"])
49
+ s.add_runtime_dependency(%q<mongoid>, [">= 0"])
50
+ s.add_runtime_dependency(%q<bson_ext>, [">= 0"])
51
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
52
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
53
+ s.add_development_dependency(%q<rack-test>, [">= 0"])
54
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
55
+ s.add_development_dependency(%q<database_cleaner>, ["= 0.7.1"])
56
+ else
57
+ s.add_dependency(%q<sinatra>, ["~> 1.3"])
58
+ s.add_dependency(%q<mongoid>, [">= 0"])
59
+ s.add_dependency(%q<bson_ext>, [">= 0"])
60
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
62
+ s.add_dependency(%q<rack-test>, [">= 0"])
63
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
64
+ s.add_dependency(%q<database_cleaner>, ["= 0.7.1"])
65
+ end
66
+ else
67
+ s.add_dependency(%q<sinatra>, ["~> 1.3"])
68
+ s.add_dependency(%q<mongoid>, [">= 0"])
69
+ s.add_dependency(%q<bson_ext>, [">= 0"])
70
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
71
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
72
+ s.add_dependency(%q<rack-test>, [">= 0"])
73
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
74
+ s.add_dependency(%q<database_cleaner>, ["= 0.7.1"])
75
+ end
76
+ end
77
+
@@ -0,0 +1,54 @@
1
+ require_relative '../spec_helper'
2
+ require 'rack/test'
3
+
4
+ module SimpleStats
5
+ describe Engine do
6
+ include Rack::Test::Methods
7
+
8
+ def app
9
+ SimpleStats::Engine
10
+ end
11
+
12
+ describe "POST /" do
13
+ before { post '/', "foo" => "bar" }
14
+
15
+ it 'saves stats' do
16
+ SimpleStats::Stat.count.should == 1
17
+ end
18
+
19
+ it 'saves params' do
20
+ stat = SimpleStats::Stat.first
21
+ stat.attributes.should == {"_id" => stat.id, "foo" => "bar"}
22
+ end
23
+
24
+ it 'returns HTTP 200' do
25
+ last_response.should be_ok
26
+ end
27
+
28
+ it 'returns no body' do
29
+ last_response.body.should be_empty
30
+ end
31
+ end
32
+
33
+ describe "POST /:id" do
34
+ let(:stat) { SimpleStats::Stat.create(:session => {:user_id => 1}) }
35
+
36
+ before do
37
+ post "/#{stat.id}", :browser => {:window => {:width => 1032}}
38
+ end
39
+
40
+ it 'updates existing stats' do
41
+ stat.reload
42
+ stat.browser.should == {"window" => {"width" => "1032"}}
43
+ end
44
+
45
+ it 'returns HTTP 200' do
46
+ last_response.should be_ok
47
+ end
48
+
49
+ it 'returns no body' do
50
+ last_response.body.should be_empty
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,20 @@
1
+ require_relative "../spec_helper"
2
+ require 'rack/test'
3
+
4
+ module SimpleStats
5
+ describe Middleware do
6
+ it 'acts as middleware' do
7
+ app, status, headers, body = stub, stub, stub, stub
8
+ app.stub(:call).and_return { [status, headers, body] }
9
+ middleware = SimpleStats::Middleware.new(app)
10
+ middleware.call({}).should == [status, headers, body]
11
+ end
12
+
13
+ it 'creates a stat' do
14
+ app = stub(:call => nil)
15
+ middleware = SimpleStats::Middleware.new(app)
16
+ middleware.call({})
17
+ Stat.all.should have(1).stat
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ require_relative "../spec_helper"
2
+
3
+ module SimpleStats
4
+ describe Stat do
5
+ it 'saves to the db'
6
+ end
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplestats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-06 00:00:00.000000000 Z
12
+ date: 2012-02-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: &16897920 !ruby/object:Gem::Requirement
16
+ requirement: &16522860 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *16897920
24
+ version_requirements: *16522860
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mongoid
27
- requirement: &16897320 !ruby/object:Gem::Requirement
27
+ requirement: &16521040 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *16897320
35
+ version_requirements: *16521040
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bson_ext
38
- requirement: &16896560 !ruby/object:Gem::Requirement
38
+ requirement: &16519160 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *16896560
46
+ version_requirements: *16519160
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &16895500 !ruby/object:Gem::Requirement
49
+ requirement: &16516420 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.8.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *16895500
57
+ version_requirements: *16516420
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: jeweler
60
- requirement: &16894340 !ruby/object:Gem::Requirement
60
+ requirement: &18017300 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.8.3
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *16894340
68
+ version_requirements: *18017300
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rack-test
71
- requirement: &16893300 !ruby/object:Gem::Requirement
71
+ requirement: &18015720 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *16893300
79
+ version_requirements: *18015720
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rdoc
82
- requirement: &16892340 !ruby/object:Gem::Requirement
82
+ requirement: &18014880 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '3.12'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *16892340
90
+ version_requirements: *18014880
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: database_cleaner
93
- requirement: &16890620 !ruby/object:Gem::Requirement
93
+ requirement: &18014160 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - =
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: 0.7.1
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *16890620
101
+ version_requirements: *18014160
102
102
  description: A Sinatra application that makes it easy to collect and store web statistics
103
103
  email: marten@veldthuis.com
104
104
  executables: []
@@ -107,7 +107,6 @@ extra_rdoc_files:
107
107
  - LICENSE.txt
108
108
  - README.md
109
109
  files:
110
- - .document
111
110
  - .rspec
112
111
  - .travis.yml
113
112
  - Gemfile
@@ -117,9 +116,15 @@ files:
117
116
  - Rakefile
118
117
  - VERSION
119
118
  - lib/simplestats.rb
120
- - spec/simplestats_spec.rb
119
+ - lib/simplestats/engine.rb
120
+ - lib/simplestats/middleware.rb
121
+ - lib/simplestats/stat.rb
122
+ - simplestats.gemspec
123
+ - spec/simplestats/engine_spec.rb
124
+ - spec/simplestats/middleware_spec.rb
125
+ - spec/simplestats/stat_spec.rb
121
126
  - spec/spec_helper.rb
122
- homepage: http://github.com/marten/simplestats
127
+ homepage: http://roqua.github.com/simplestats
123
128
  licenses:
124
129
  - MIT
125
130
  post_install_message:
@@ -134,7 +139,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
134
139
  version: '0'
135
140
  segments:
136
141
  - 0
137
- hash: 3456130462776699016
142
+ hash: -1231894380103482237
138
143
  required_rubygems_version: !ruby/object:Gem::Requirement
139
144
  none: false
140
145
  requirements:
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
@@ -1,52 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
- require 'rack/test'
3
-
4
- describe SimpleStats do
5
- include Rack::Test::Methods
6
-
7
- def app
8
- SimpleStats
9
- end
10
-
11
- describe "POST /" do
12
- before { post '/', "foo" => "bar" }
13
-
14
- it 'saves stats' do
15
- SimpleStats::Stat.count.should == 1
16
- end
17
-
18
- it 'saves params' do
19
- stat = SimpleStats::Stat.first
20
- stat.attributes.should == {"_id" => stat.id, "foo" => "bar"}
21
- end
22
-
23
- it 'returns HTTP 200' do
24
- last_response.should be_ok
25
- end
26
-
27
- it 'returns no body' do
28
- last_response.body.should be_empty
29
- end
30
- end
31
-
32
- describe "POST /:id" do
33
- let(:stat) { SimpleStats::Stat.create(:session => {:user_id => 1}) }
34
-
35
- before do
36
- post "/#{stat.id}", :browser => {:window => {:width => 1032}}
37
- end
38
-
39
- it 'updates existing stats' do
40
- stat.reload
41
- stat.browser.should == {"window" => {"width" => "1032"}}
42
- end
43
-
44
- it 'returns HTTP 200' do
45
- last_response.should be_ok
46
- end
47
-
48
- it 'returns no body' do
49
- last_response.body.should be_empty
50
- end
51
- end
52
- end