simplestats 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +65 -0
- data/LICENSE.txt +20 -0
- data/README.md +37 -0
- data/Rakefile +47 -0
- data/VERSION +1 -0
- data/lib/simplestats.rb +27 -0
- data/spec/simplestats_spec.rb +52 -0
- data/spec/spec_helper.rb +28 -0
- metadata +150 -0
data/.document
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "sinatra", "~> 1.3"
|
4
|
+
gem "mongoid"
|
5
|
+
gem "bson_ext"
|
6
|
+
|
7
|
+
group :development do
|
8
|
+
gem "rspec", "~> 2.8.0"
|
9
|
+
gem "jeweler", "~> 1.8.3"
|
10
|
+
gem "rack-test"
|
11
|
+
gem "rdoc", "~> 3.12"
|
12
|
+
gem "database_cleaner", "0.7.1"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (3.1.3)
|
5
|
+
activesupport (= 3.1.3)
|
6
|
+
builder (~> 3.0.0)
|
7
|
+
i18n (~> 0.6)
|
8
|
+
activesupport (3.1.3)
|
9
|
+
multi_json (~> 1.0)
|
10
|
+
bson (1.5.2)
|
11
|
+
bson_ext (1.5.2)
|
12
|
+
bson (= 1.5.2)
|
13
|
+
builder (3.0.0)
|
14
|
+
database_cleaner (0.7.1)
|
15
|
+
diff-lcs (1.1.3)
|
16
|
+
git (1.2.5)
|
17
|
+
i18n (0.6.0)
|
18
|
+
jeweler (1.8.3)
|
19
|
+
bundler (~> 1.0)
|
20
|
+
git (>= 1.2.5)
|
21
|
+
rake
|
22
|
+
rdoc
|
23
|
+
json (1.6.5)
|
24
|
+
mongo (1.5.2)
|
25
|
+
bson (= 1.5.2)
|
26
|
+
mongoid (2.4.2)
|
27
|
+
activemodel (~> 3.1)
|
28
|
+
mongo (~> 1.3)
|
29
|
+
tzinfo (~> 0.3.22)
|
30
|
+
multi_json (1.0.4)
|
31
|
+
rack (1.3.6)
|
32
|
+
rack-protection (1.2.0)
|
33
|
+
rack
|
34
|
+
rack-test (0.6.1)
|
35
|
+
rack (>= 1.0)
|
36
|
+
rake (0.9.2.2)
|
37
|
+
rdoc (3.12)
|
38
|
+
json (~> 1.4)
|
39
|
+
rspec (2.8.0)
|
40
|
+
rspec-core (~> 2.8.0)
|
41
|
+
rspec-expectations (~> 2.8.0)
|
42
|
+
rspec-mocks (~> 2.8.0)
|
43
|
+
rspec-core (2.8.0)
|
44
|
+
rspec-expectations (2.8.0)
|
45
|
+
diff-lcs (~> 1.1.2)
|
46
|
+
rspec-mocks (2.8.0)
|
47
|
+
sinatra (1.3.2)
|
48
|
+
rack (~> 1.3, >= 1.3.6)
|
49
|
+
rack-protection (~> 1.2)
|
50
|
+
tilt (~> 1.3, >= 1.3.3)
|
51
|
+
tilt (1.3.3)
|
52
|
+
tzinfo (0.3.31)
|
53
|
+
|
54
|
+
PLATFORMS
|
55
|
+
ruby
|
56
|
+
|
57
|
+
DEPENDENCIES
|
58
|
+
bson_ext
|
59
|
+
database_cleaner (= 0.7.1)
|
60
|
+
jeweler (~> 1.8.3)
|
61
|
+
mongoid
|
62
|
+
rack-test
|
63
|
+
rdoc (~> 3.12)
|
64
|
+
rspec (~> 2.8.0)
|
65
|
+
sinatra (~> 1.3)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 RGOc
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# SimpleStats
|
2
|
+
|
3
|
+
SimpleStats is a fairly minimalistic web stats package. It will track every
|
4
|
+
request to your app. It consists of two parts: a Rack middleware component
|
5
|
+
that can track information from the server-side processing of a request, and
|
6
|
+
a view helper that tracks information from the client-side of a request.
|
7
|
+
|
8
|
+
Both parts can be used independently, and when used together, SimpleStats will
|
9
|
+
automatically store them together in the same MongoDB record.
|
10
|
+
|
11
|
+
# How to use
|
12
|
+
|
13
|
+
Mount as engine somewhere in your application:
|
14
|
+
|
15
|
+
mount SimpleStats, "/stats"
|
16
|
+
|
17
|
+
The following stuff is still TODO:
|
18
|
+
|
19
|
+
* Add SimpleStats::Middleware as Rack middleware to collect
|
20
|
+
information from the server-side of the request.
|
21
|
+
* In your layout, add
|
22
|
+
|
23
|
+
<%= simple_stats_collector %>
|
24
|
+
|
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.
|
34
|
+
|
35
|
+
## Copyright
|
36
|
+
|
37
|
+
Copyright (c) 2012 RGOc. See LICENSE.txt for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
require 'rake'
|
12
|
+
|
13
|
+
require 'jeweler'
|
14
|
+
Jeweler::Tasks.new do |gem|
|
15
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
16
|
+
gem.name = "simplestats"
|
17
|
+
gem.homepage = "http://github.com/marten/simplestats"
|
18
|
+
gem.license = "MIT"
|
19
|
+
gem.summary = %Q{A really simple webstats collection engine}
|
20
|
+
gem.description = %Q{A Sinatra application that makes it easy to collect and store web statistics}
|
21
|
+
gem.email = "marten@veldthuis.com"
|
22
|
+
gem.authors = ["Marten Veldthuis"]
|
23
|
+
end
|
24
|
+
Jeweler::RubygemsDotOrgTasks.new
|
25
|
+
|
26
|
+
require 'rspec/core'
|
27
|
+
require 'rspec/core/rake_task'
|
28
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
29
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
30
|
+
end
|
31
|
+
|
32
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
33
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
34
|
+
spec.rcov = true
|
35
|
+
end
|
36
|
+
|
37
|
+
task :default => :spec
|
38
|
+
|
39
|
+
require 'rdoc/task'
|
40
|
+
Rake::RDocTask.new do |rdoc|
|
41
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
42
|
+
|
43
|
+
rdoc.rdoc_dir = 'rdoc'
|
44
|
+
rdoc.title = "simplestats #{version}"
|
45
|
+
rdoc.rdoc_files.include('README*')
|
46
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
47
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/lib/simplestats.rb
ADDED
@@ -0,0 +1,27 @@
|
|
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
|
@@ -0,0 +1,52 @@
|
|
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
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'simplestats'
|
5
|
+
require 'database_cleaner'
|
6
|
+
|
7
|
+
# Requires supporting files with custom matchers and macros, etc,
|
8
|
+
# in ./support/ and its subdirectories.
|
9
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
10
|
+
|
11
|
+
Mongoid.configure do |config|
|
12
|
+
config.master = Mongo::Connection.new.db("simplestats_test")
|
13
|
+
end
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.before(:suite) do
|
17
|
+
DatabaseCleaner.strategy = :truncation
|
18
|
+
DatabaseCleaner.clean_with(:truncation)
|
19
|
+
end
|
20
|
+
|
21
|
+
config.before(:each) do
|
22
|
+
DatabaseCleaner.start
|
23
|
+
end
|
24
|
+
|
25
|
+
config.after(:each) do
|
26
|
+
DatabaseCleaner.clean
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simplestats
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Marten Veldthuis
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sinatra
|
16
|
+
requirement: &16897920 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *16897920
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mongoid
|
27
|
+
requirement: &16897320 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *16897320
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bson_ext
|
38
|
+
requirement: &16896560 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *16896560
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: &16895500 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.8.0
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *16895500
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: jeweler
|
60
|
+
requirement: &16894340 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.8.3
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *16894340
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rack-test
|
71
|
+
requirement: &16893300 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *16893300
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: rdoc
|
82
|
+
requirement: &16892340 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '3.12'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *16892340
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: database_cleaner
|
93
|
+
requirement: &16890620 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - =
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 0.7.1
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *16890620
|
102
|
+
description: A Sinatra application that makes it easy to collect and store web statistics
|
103
|
+
email: marten@veldthuis.com
|
104
|
+
executables: []
|
105
|
+
extensions: []
|
106
|
+
extra_rdoc_files:
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
files:
|
110
|
+
- .document
|
111
|
+
- .rspec
|
112
|
+
- .travis.yml
|
113
|
+
- Gemfile
|
114
|
+
- Gemfile.lock
|
115
|
+
- LICENSE.txt
|
116
|
+
- README.md
|
117
|
+
- Rakefile
|
118
|
+
- VERSION
|
119
|
+
- lib/simplestats.rb
|
120
|
+
- spec/simplestats_spec.rb
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
homepage: http://github.com/marten/simplestats
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
hash: 3456130462776699016
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ! '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 1.8.11
|
147
|
+
signing_key:
|
148
|
+
specification_version: 3
|
149
|
+
summary: A really simple webstats collection engine
|
150
|
+
test_files: []
|