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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a133c5bd94203f0b4f6f66e66d0b4d183d4a8e28
4
- data.tar.gz: 57c730f2fb6d60554ec02a7c50ccceb02bdd195a
3
+ metadata.gz: e97aa73390d413bbedaa2e0e446464786fd1b49f
4
+ data.tar.gz: cc2f451c4c4fb995f7e77eb5870b6f710b492862
5
5
  SHA512:
6
- metadata.gz: 72ef4b784bc8da3969708389bc7934027d313882fff8bcf26e45cd13d6a639bedd9549a20b2662b1bb4ff481f183fd37fad77d9c2f47b73a0c48a61f9459d883
7
- data.tar.gz: c0e785ff8b4d1cbf569ecac480413c573a8e27f1c90497ef3c537bff6f497d9c0662ab8054c0b0d475198bfad3eabc794dce5253b3edf98a0991659103144c54
6
+ metadata.gz: ae763217419637c7abe0abf2a45dfdab7bc04d876e9b0619dfe0daa4b19f60abf6e1260f6a9cb26daca75ad9a24b5ad3f7fe5e491faa5dfb28ee8f36b80368f8
7
+ data.tar.gz: 742ac898202b1215eca2978528802a3cd05dbae7c04238edbb88a79c5eb514c2bd0946c7561028d5e83c34fe94c7e15807b07cb5ac4af0e866538829935f0583
@@ -1 +1 @@
1
- 2.2.2
1
+ 2.3
@@ -1,8 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.6
6
- - 2.2.2
3
+ - 1.9
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
7
+ - 2.3
8
+ - 2.4
9
+ - 2.5
7
10
  script: bundle exec rake
8
11
  sudo: false
@@ -1,4 +1,10 @@
1
- ## Staccato 0.5.0 ##
1
+ ## Staccato 0.5.2 ##
2
+
3
+ * Multiple adapter support
4
+
5
+ *Tony Pitale - @tpitale*
6
+
7
+ ## Staccato 0.5.1 ##
2
8
 
3
9
  * Logger adapter uses the appropriate `::Logger` class
4
10
 
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
@@ -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://ssl' : 'http://www') + '.google-analytics.com/collect'
39
+ url = (ssl ? 'https://' : 'http://') + 'www.google-analytics.com/collect'
40
40
  URI(url)
41
41
  end
42
42
 
@@ -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
- adapter.post(params)
183
+ single_adapter? ? post_first(params) : post_all(params)
171
184
  end
172
185
 
173
- def adapter
174
- @adapter ||= Staccato.default_adapter.new(default_uri)
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
@@ -1,4 +1,4 @@
1
1
  module Staccato
2
2
  # The current Staccato VERSION
3
- VERSION = "0.5.1"
3
+ VERSION = "0.5.2"
4
4
  end
@@ -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
@@ -6,6 +6,7 @@ require 'bundler/setup'
6
6
  require 'rspec'
7
7
  require 'mocha/api'
8
8
  require 'bourne'
9
+ require 'net/http' # no longer auto-required in ruby
9
10
 
10
11
  require File.expand_path('../../lib/staccato', __FILE__)
11
12
 
@@ -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.1
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: 2016-11-23 00:00:00.000000000 Z
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