staccato 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +7 -4
- data/CHANGELOG.md +7 -1
- data/README.md +22 -0
- data/lib/staccato.rb +1 -1
- data/lib/staccato/tracker.rb +41 -5
- data/lib/staccato/version.rb +1 -1
- data/spec/integration/tracker_spec.rb +23 -1
- data/spec/spec_helper.rb +1 -0
- data/staccato.gemspec +0 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e97aa73390d413bbedaa2e0e446464786fd1b49f
|
4
|
+
data.tar.gz: cc2f451c4c4fb995f7e77eb5870b6f710b492862
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae763217419637c7abe0abf2a45dfdab7bc04d876e9b0619dfe0daa4b19f60abf6e1260f6a9cb26daca75ad9a24b5ad3f7fe5e491faa5dfb28ee8f36b80368f8
|
7
|
+
data.tar.gz: 742ac898202b1215eca2978528802a3cd05dbae7c04238edbb88a79c5eb514c2bd0946c7561028d5e83c34fe94c7e15807b07cb5ac4af0e866538829935f0583
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.3
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -10,6 +10,8 @@ https://developers.google.com/analytics/devguides/collection/protocol/v1/
|
|
10
10
|
[![Build Status](https://travis-ci.org/tpitale/staccato.png?branch=master)](https://travis-ci.org/tpitale/staccato)
|
11
11
|
[![Code Climate](https://codeclimate.com/github/tpitale/staccato.png)](https://codeclimate.com/github/tpitale/staccato)
|
12
12
|
|
13
|
+
If you're using Rails and would like to use Staccato, we have an gem for that! [Staccato Rails](https://github.com/tpitale/staccato-rails)
|
14
|
+
|
13
15
|
|
14
16
|
## Installation
|
15
17
|
|
@@ -453,6 +455,20 @@ https://developers.google.com/analytics/devguides/collection/protocol/v1/paramet
|
|
453
455
|
|
454
456
|
Staccato provides a variety of adapters for sending or debugging requests being made. To use them, first require the adapter by name: `require 'staccato/adapter/#{chosen-adapter-name}'`
|
455
457
|
|
458
|
+
Multiple adapters can be used by calling `add_adapter`:
|
459
|
+
|
460
|
+
```ruby
|
461
|
+
require 'staccato/adapter/validate'
|
462
|
+
|
463
|
+
tracker = Staccato.tracker('UA-XXXX-Y') do |c|
|
464
|
+
c.add_adapter Staccato::Adapter::Validate.new
|
465
|
+
c.add_adapter Staccato::Adapter::Logger.new(Staccato.ga_collection_uri)
|
466
|
+
c.add_adapter Staccato::Adapter::Faraday.new(Staccato.ga_collection_uri)
|
467
|
+
end
|
468
|
+
```
|
469
|
+
|
470
|
+
**Results returned will be in an array, as returned by each adapter in the order the adapters were added.**
|
471
|
+
|
456
472
|
### HTTP Adapters ###
|
457
473
|
|
458
474
|
Staccato provides a number of basic adapters to different ruby http libraries. By default, Staccato uses `net/http` when you create a new tracker. If you are using Faraday or [The Ruby HTTP library](https://github.com/httprb/http.rb) Staccato provides adapters.
|
@@ -519,6 +535,12 @@ tracker = Staccato.tracker('UA-XXXX-Y') do |c|
|
|
519
535
|
end
|
520
536
|
```
|
521
537
|
|
538
|
+
See results by printing a call to track any hit:
|
539
|
+
|
540
|
+
```ruby
|
541
|
+
puts tracker.pageview(path: '/')
|
542
|
+
```
|
543
|
+
|
522
544
|
By default, the staccato `default_adapter` is used to send validation hits, but a different adapter can be used (e.g. `Faraday` or `Net::HTTP`).
|
523
545
|
|
524
546
|
```ruby
|
data/lib/staccato.rb
CHANGED
@@ -36,7 +36,7 @@ module Staccato
|
|
36
36
|
|
37
37
|
# The tracking endpoint we use to submit requests to GA
|
38
38
|
def self.ga_collection_uri(ssl = false)
|
39
|
-
url = (ssl ? 'https://
|
39
|
+
url = (ssl ? 'https://' : 'http://') + 'www.google-analytics.com/collect'
|
40
40
|
URI(url)
|
41
41
|
end
|
42
42
|
|
data/lib/staccato/tracker.rb
CHANGED
@@ -4,7 +4,6 @@ module Staccato
|
|
4
4
|
#
|
5
5
|
# @author Tony Pitale
|
6
6
|
class Tracker
|
7
|
-
attr_writer :adapter
|
8
7
|
attr_accessor :hit_defaults
|
9
8
|
|
10
9
|
# sets up a new tracker
|
@@ -15,10 +14,19 @@ module Staccato
|
|
15
14
|
@id = id
|
16
15
|
@client_id = client_id
|
17
16
|
@ssl = options.delete(:ssl) || false
|
17
|
+
@adapters = []
|
18
18
|
|
19
19
|
self.hit_defaults = options
|
20
20
|
end
|
21
21
|
|
22
|
+
def adapter=(adapter)
|
23
|
+
@adapters = [new_adapter]
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_adapter(adapter)
|
27
|
+
@adapters << adapter
|
28
|
+
end
|
29
|
+
|
22
30
|
# The tracker id for GA
|
23
31
|
# @return [String, nil]
|
24
32
|
def id
|
@@ -165,20 +173,40 @@ module Staccato
|
|
165
173
|
|
166
174
|
private
|
167
175
|
|
176
|
+
# @private
|
177
|
+
def single_adapter?
|
178
|
+
adapters.length == 1
|
179
|
+
end
|
180
|
+
|
168
181
|
# @private
|
169
182
|
def post(params)
|
170
|
-
|
183
|
+
single_adapter? ? post_first(params) : post_all(params)
|
171
184
|
end
|
172
185
|
|
173
|
-
|
174
|
-
|
186
|
+
# @private
|
187
|
+
def post_first(params)
|
188
|
+
adapters.first.post(params)
|
189
|
+
end
|
190
|
+
|
191
|
+
# @private
|
192
|
+
def post_all(params)
|
193
|
+
adapters.map {|adapter| adapter.post(params)}
|
194
|
+
end
|
195
|
+
|
196
|
+
# @private
|
197
|
+
def adapters
|
198
|
+
@adapters.empty? ? [default_adapter] : @adapters
|
199
|
+
end
|
200
|
+
|
201
|
+
# @private
|
202
|
+
def default_adapter
|
203
|
+
@default_adapter ||= Staccato.default_adapter.new(default_uri)
|
175
204
|
end
|
176
205
|
end
|
177
206
|
|
178
207
|
# A tracker which does no tracking
|
179
208
|
# Useful in testing
|
180
209
|
class NoopTracker
|
181
|
-
attr_writer :adapter
|
182
210
|
attr_accessor :hit_defaults
|
183
211
|
|
184
212
|
# (see Tracker#initialize)
|
@@ -186,6 +214,14 @@ module Staccato
|
|
186
214
|
self.hit_defaults = hit_defaults
|
187
215
|
end
|
188
216
|
|
217
|
+
def adapter=(*)
|
218
|
+
[]
|
219
|
+
end
|
220
|
+
|
221
|
+
def add_adapter(*)
|
222
|
+
[]
|
223
|
+
end
|
224
|
+
|
189
225
|
# (see Tracker#id)
|
190
226
|
def id
|
191
227
|
nil
|
data/lib/staccato/version.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
require 'staccato/adapter/http'
|
4
|
+
require 'staccato/adapter/net_http'
|
5
|
+
|
3
6
|
describe Staccato::Tracker do
|
4
7
|
let(:uri) {Staccato.ga_collection_uri}
|
5
8
|
let(:tracker) {Staccato.tracker('UA-XXXX-Y')}
|
@@ -12,7 +15,7 @@ describe Staccato::Tracker do
|
|
12
15
|
|
13
16
|
describe "#pageview" do
|
14
17
|
before(:each) do
|
15
|
-
tracker.pageview(path: '/foobar', title: 'FooBar', hostname: 'mysite.com')
|
18
|
+
expect(tracker.pageview(path: '/foobar', title: 'FooBar', hostname: 'mysite.com')).to eq(response)
|
16
19
|
end
|
17
20
|
|
18
21
|
it 'tracks page path and page title' do
|
@@ -235,3 +238,22 @@ describe Staccato::Tracker do
|
|
235
238
|
end
|
236
239
|
end
|
237
240
|
end
|
241
|
+
|
242
|
+
describe Staccato::Tracker, "with multiple adapters" do
|
243
|
+
let(:uri) {Staccato.ga_collection_uri}
|
244
|
+
let(:net_http_adapter) {Staccato::Adapter::Net::HTTP.new(uri)}
|
245
|
+
let(:http_adapter) {Staccato::Adapter::HTTP.new(uri)}
|
246
|
+
let(:tracker) {Staccato.tracker('UA-XXXX-Y') do |c|
|
247
|
+
c.add_adapter net_http_adapter
|
248
|
+
c.add_adapter http_adapter
|
249
|
+
end}
|
250
|
+
|
251
|
+
before(:each) do
|
252
|
+
net_http_adapter.stubs(:post).returns("Net::HTTP response")
|
253
|
+
http_adapter.stubs(:post).returns("HTTP Response")
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'returns an array of responses in order of adapter' do
|
257
|
+
expect(tracker.pageview(path: '/')).to eq(["Net::HTTP response", "HTTP Response"])
|
258
|
+
end
|
259
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/staccato.gemspec
CHANGED
@@ -18,7 +18,6 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.3"
|
22
21
|
spec.add_development_dependency "rake", ">= 3.0.0"
|
23
22
|
spec.add_development_dependency "rspec", "~> 3.0"
|
24
23
|
spec.add_development_dependency "mocha"
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: staccato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Pitale
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.3'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.3'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rake
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|