rakwik 0.4.2 → 0.4.3

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.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- Njg1ZmM2YzIxZGE4OGNjMTRlYTVjZDMwYzIyMmU2MjdkZDUzNGUyYg==
5
- data.tar.gz: !binary |-
6
- YmYyNTg4MjNiMjAzMTY5YmJmZGE0ZDQ3YjgyY2JiYTRiYmJiYzY4YQ==
2
+ SHA1:
3
+ metadata.gz: d3dc338c75380f85f8377f331ff32bf5f73cdff2
4
+ data.tar.gz: d0f6720f84bb6e77320ef4dfe2e477b1bd435a91
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZDA0OWM0NDI3YmMwOTZiODI2NjliNTQzYmE4NjU5NjJhY2Y4ZTgxNzY2N2E5
10
- YzRiNzIxOTU0Njk4NzI0OGMwMGU0MWZlOGQ3MGVlYTZlMTY1NjA1YWJmYTk5
11
- NzFlYjMxYjMxYzIzYzkzZGIxMjEyZDFmYzhjYmE0YWI5ODBiY2Q=
12
- data.tar.gz: !binary |-
13
- MWYwMjU2ZmJmMGM2M2JmYTI2Y2E3ZWI1MTAxZDkyMDM0YzUyNTE5NTE1M2Jj
14
- ZjE1NjkzNTg4MmEzNGY4ZDMxZTdkZWU2NzNmYjEwZDNiNDE2NWVhMDY5MmM5
15
- MWNlYjZmMWFmYzM0NDlhNGFiNzQxYjk2ZGM4MGFhMTMzMmI5MjE=
6
+ metadata.gz: 887054f2d0344d49b1b9014b1c289d9a818bce0878e85ccf0f497a53fd397e0b5a81ee031674c5f24337a13c9e8b4803570e47acfadf2fa77ff38f8461a5c5da
7
+ data.tar.gz: 4413db51d9e531f3f5fd14affa430515fd7e2e1d8c636ebcfb7aa17ab379c2934efeebc05e2c33f12cf49a2f2a81d9d54f0807fe0b52a7450383961124686e2f
@@ -1 +1 @@
1
- ruby-1.9.3-p484
1
+ ruby-2.1.2
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - "1.8.7"
4
- - "1.9.3"
5
4
  - "2.0.0"
5
+ - "2.1.2"
6
6
  # uncomment this line if your project needs to run something other than `rake`:
7
7
  # script: bundle exec rspec spec
@@ -48,6 +48,16 @@ module Rakwik
48
48
  @options[:token_auth]
49
49
  end
50
50
 
51
+ def path
52
+ @options[:path] || ""
53
+ end
54
+
55
+ def match_path?(url)
56
+ return path.call(url) if path.is_a? Proc
57
+ return url =~ path if path.is_a? Regexp
58
+ return url.start_with?(path.to_s)
59
+ end
60
+
51
61
  def extract(request)
52
62
  header = {
53
63
  'User-Agent' => (request.user_agent || self.class.user_agent)
@@ -93,6 +103,8 @@ module Rakwik
93
103
  end
94
104
 
95
105
  def track(request)
106
+ return unless match_path?(request.path)
107
+
96
108
  h, d = extract(request)
97
109
  EventMachine.schedule do
98
110
  http = connection(piwik_url).post :head => h, :body => d
@@ -1,3 +1,3 @@
1
1
  module Rakwik
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -37,11 +37,11 @@ describe Rakwik::Tracker do
37
37
 
38
38
  # What now?
39
39
  posted_data = nil
40
- WebMock.should have_requested(:post, tracker_data[:piwik_url]).with{|req|
40
+ expect(WebMock).to have_requested(:post, tracker_data[:piwik_url]).with{|req|
41
41
  posted_data = URI::decode_www_form(req.body).
42
42
  inject(Hash.new){ |h, raw| h[raw[0]] = raw[1]; h }
43
43
  }
44
- posted_data.should include(
44
+ expect(posted_data).to include(
45
45
  "token_auth"=>"foobar",
46
46
  "idsite"=>"1",
47
47
  "rec"=>"1",
@@ -52,8 +52,8 @@ describe Rakwik::Tracker do
52
52
  "lang"=>"en",
53
53
  "urlref"=>"http://example.org/referring_page"
54
54
  )
55
- posted_data["rand"].should_not be_nil
56
- posted_data["gt_ms"].should_not be_nil
55
+ expect(posted_data["rand"]).not_to be_nil
56
+ expect(posted_data["gt_ms"]).not_to be_nil
57
57
  end
58
58
 
59
59
  it "accepts requests without user agent" do
@@ -61,15 +61,15 @@ describe Rakwik::Tracker do
61
61
  get '/'
62
62
 
63
63
  # wait a little while to let EventMachine send the request
64
- sleep 0.01
64
+ sleep 0.1
65
65
 
66
66
  # What now?
67
67
  headers = nil
68
- WebMock.should have_requested(:post, tracker_data[:piwik_url]).with{|req|
68
+ expect(WebMock).to have_requested(:post, tracker_data[:piwik_url]).with{|req|
69
69
  headers = req.headers
70
70
  }
71
71
 
72
- headers.should include(
72
+ expect(headers).to include(
73
73
  "User-Agent"=>Rakwik::Tracker.user_agent
74
74
  )
75
75
  end
@@ -89,18 +89,122 @@ describe Rakwik::Tracker do
89
89
  get '/'
90
90
 
91
91
  # wait a little while to let EventMachine send the request
92
- sleep 0.01
92
+ sleep 0.1
93
93
 
94
94
  # What now?
95
95
  posted_data = nil
96
- WebMock.should have_requested(:post, tracker_data[:piwik_url]).with{|req|
96
+ expect(WebMock).to have_requested(:post, tracker_data[:piwik_url]).with{|req|
97
97
  posted_data = URI::decode_www_form(req.body).
98
98
  inject(Hash.new){ |h, raw| h[raw[0]] = raw[1]; h }
99
99
  }
100
100
 
101
- posted_data["_id"].should_not be_nil
102
- posted_data["_id"].should match(/[0-9a-f]{16}/)
101
+ expect(posted_data["_id"]).not_to be_nil
102
+ expect(posted_data["_id"]).to match(/[0-9a-f]{16}/)
103
103
  end
104
104
  end
105
105
 
106
+ context 'with path option' do
107
+ let(:app) {
108
+ Rakwik::Tracker.new(
109
+ lambda { |env| [200, {"Content-Type"=>"text/plain"}, ["Hello."]] },
110
+ tracker_data
111
+ )
112
+ }
113
+
114
+ let(:tracker_data) {
115
+ {
116
+ :piwik_url => 'http://example.com/piwik.php',
117
+ :site_id => 1,
118
+ :token_auth => 'foobar',
119
+ :path => path
120
+ }
121
+ }
122
+
123
+ context 'as regexp' do
124
+ let(:path) { /^\/foo.*$/ }
125
+
126
+ it 'should track foo* pathes' do
127
+ get '/foo'
128
+ sleep 0.01
129
+
130
+ get '/foo/bar'
131
+ sleep 0.01
132
+
133
+ get '/foobar'
134
+ sleep 0.01
135
+
136
+ expect(WebMock).to have_requested(:post, tracker_data[:piwik_url]).times(3)
137
+ end
138
+
139
+ it 'should not track other pathes' do
140
+ get '/fo'
141
+ sleep 0.01
142
+
143
+ get '/index'
144
+ sleep 0.01
145
+
146
+ get '/bar/foo'
147
+ sleep 0.01
148
+
149
+ expect(WebMock).to have_requested(:post, tracker_data[:piwik_url]).times(0)
150
+ end
151
+ end
152
+
153
+ context 'as proc' do
154
+ let(:path) { Proc.new { |path| path.length == 5 }}
155
+
156
+ it 'should track pathes of length 5' do
157
+ get '/foos'
158
+ sleep 0.01
159
+
160
+ get '/a/bc'
161
+ sleep 0.01
162
+
163
+ expect(WebMock).to have_requested(:post, tracker_data[:piwik_url]).times(2)
164
+ end
165
+
166
+ it 'should not track other pathes' do
167
+ get '/fo'
168
+ sleep 0.01
169
+
170
+ get '/index'
171
+ sleep 0.01
172
+
173
+ get '/bar/foo'
174
+ sleep 0.01
175
+
176
+ expect(WebMock).to have_requested(:post, tracker_data[:piwik_url]).times(0)
177
+ end
178
+ end
179
+
180
+ context 'as string' do
181
+ let(:path) { "/api" }
182
+
183
+ it 'should track pathes that start with given string' do
184
+ get '/api/v2/users'
185
+ sleep 0.01
186
+
187
+ get '/api'
188
+ sleep 0.01
189
+
190
+ get '/api/v2/users.json'
191
+ sleep 0.01
192
+
193
+ expect(WebMock).to have_requested(:post, tracker_data[:piwik_url]).times(3)
194
+ end
195
+
196
+ it 'should not track other pathes' do
197
+ get '/'
198
+ sleep 0.01
199
+
200
+ get '/users.html'
201
+ sleep 0.01
202
+
203
+ get '/downloads/session.json'
204
+ sleep 0.01
205
+
206
+ expect(WebMock).to have_requested(:post, tracker_data[:piwik_url]).times(0)
207
+ end
208
+ end
209
+ end
106
210
  end
metadata CHANGED
@@ -1,73 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rakwik
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Aust
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-18 00:00:00.000000000 Z
11
+ date: 2014-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: em-http-request
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: ! 'Rakwik is a server-side tracker integration for the Piwik opensource
56
-
57
- web statistics software. It''s easy to integrate into rack-based applications and
58
- does not require
59
-
60
- frontend Javascript inclusion.'
55
+ description: |-
56
+ Rakwik is a server-side tracker integration for the Piwik opensource
57
+ web statistics software. It's easy to integrate into rack-based applications and does not require
58
+ frontend Javascript inclusion.
61
59
  email:
62
60
  - git@kontakt.software-consultant.net
63
61
  executables: []
64
62
  extensions: []
65
63
  extra_rdoc_files: []
66
64
  files:
67
- - .gitignore
68
- - .ruby-gemset
69
- - .ruby-version
70
- - .travis.yml
65
+ - ".gitignore"
66
+ - ".ruby-gemset"
67
+ - ".ruby-version"
68
+ - ".travis.yml"
71
69
  - Gemfile
72
70
  - LICENSE
73
71
  - README.md
@@ -90,17 +88,17 @@ require_paths:
90
88
  - lib
91
89
  required_ruby_version: !ruby/object:Gem::Requirement
92
90
  requirements:
93
- - - ! '>='
91
+ - - ">="
94
92
  - !ruby/object:Gem::Version
95
93
  version: '0'
96
94
  required_rubygems_version: !ruby/object:Gem::Requirement
97
95
  requirements:
98
- - - ! '>='
96
+ - - ">="
99
97
  - !ruby/object:Gem::Version
100
98
  version: '0'
101
99
  requirements: []
102
100
  rubyforge_project:
103
- rubygems_version: 2.1.11
101
+ rubygems_version: 2.3.0
104
102
  signing_key:
105
103
  specification_version: 4
106
104
  summary: Rack-based server-side asynchronous Piwik tracker integration.