segment 2.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +89 -0
- data/History.md +222 -0
- data/Makefile +17 -0
- data/README.md +84 -0
- data/RELEASING.md +9 -0
- data/Rakefile +23 -0
- data/analytics-ruby.gemspec +33 -0
- data/bin/analytics +93 -0
- data/codecov.yml +2 -0
- data/lib/analytics-ruby.rb +1 -0
- data/lib/segment.rb +1 -0
- data/lib/segment/analytics.rb +38 -0
- data/lib/segment/analytics/backoff_policy.rb +49 -0
- data/lib/segment/analytics/client.rb +425 -0
- data/lib/segment/analytics/defaults.rb +36 -0
- data/lib/segment/analytics/logging.rb +33 -0
- data/lib/segment/analytics/message.rb +26 -0
- data/lib/segment/analytics/message_batch.rb +59 -0
- data/lib/segment/analytics/request.rb +134 -0
- data/lib/segment/analytics/response.rb +15 -0
- data/lib/segment/analytics/utils.rb +91 -0
- data/lib/segment/analytics/version.rb +5 -0
- data/lib/segment/analytics/worker.rb +61 -0
- data/spec/helpers/runscope_client.rb +38 -0
- data/spec/segment/analytics/backoff_policy_spec.rb +92 -0
- data/spec/segment/analytics/client_spec.rb +328 -0
- data/spec/segment/analytics/e2e_spec.rb +48 -0
- data/spec/segment/analytics/message_batch_spec.rb +49 -0
- data/spec/segment/analytics/message_spec.rb +35 -0
- data/spec/segment/analytics/request_spec.rb +244 -0
- data/spec/segment/analytics/response_spec.rb +30 -0
- data/spec/segment/analytics/worker_spec.rb +110 -0
- data/spec/segment/analytics_spec.rb +120 -0
- data/spec/spec_helper.rb +128 -0
- metadata +205 -0
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Segment
|
4
|
+
class Analytics
|
5
|
+
describe Analytics do
|
6
|
+
let(:analytics) { Segment::Analytics.new :write_key => WRITE_KEY, :stub => true }
|
7
|
+
|
8
|
+
describe '#track' do
|
9
|
+
it 'errors without an event' do
|
10
|
+
expect { analytics.track(:user_id => 'user') }.to raise_error(ArgumentError)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'errors without a user_id' do
|
14
|
+
expect { analytics.track(:event => 'Event') }.to raise_error(ArgumentError)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'does not error with the required options' do
|
18
|
+
expect do
|
19
|
+
analytics.track Queued::TRACK
|
20
|
+
sleep(1)
|
21
|
+
end.to_not raise_error
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#identify' do
|
26
|
+
it 'errors without a user_id' do
|
27
|
+
expect { analytics.identify :traits => {} }.to raise_error(ArgumentError)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'does not error with the required options' do
|
31
|
+
analytics.identify Queued::IDENTIFY
|
32
|
+
sleep(1)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#alias' do
|
37
|
+
it 'errors without from' do
|
38
|
+
expect { analytics.alias :user_id => 1234 }.to raise_error(ArgumentError)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'errors without to' do
|
42
|
+
expect { analytics.alias :previous_id => 1234 }.to raise_error(ArgumentError)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'does not error with the required options' do
|
46
|
+
expect do
|
47
|
+
analytics.alias ALIAS
|
48
|
+
sleep(1)
|
49
|
+
end.to_not raise_error
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#group' do
|
54
|
+
it 'errors without group_id' do
|
55
|
+
expect { analytics.group :user_id => 'foo' }.to raise_error(ArgumentError)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'errors without user_id or anonymous_id' do
|
59
|
+
expect { analytics.group :group_id => 'foo' }.to raise_error(ArgumentError)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'does not error with the required options' do
|
63
|
+
expect do
|
64
|
+
analytics.group Queued::GROUP
|
65
|
+
sleep(1)
|
66
|
+
end.to_not raise_error
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#page' do
|
71
|
+
it 'errors without user_id or anonymous_id' do
|
72
|
+
expect { analytics.page :name => 'foo' }.to raise_error(ArgumentError)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'does not error with the required options' do
|
76
|
+
expect do
|
77
|
+
analytics.page Queued::PAGE
|
78
|
+
sleep(1)
|
79
|
+
end.to_not raise_error
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#screen' do
|
84
|
+
it 'errors without user_id or anonymous_id' do
|
85
|
+
expect { analytics.screen :name => 'foo' }.to raise_error(ArgumentError)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'does not error with the required options' do
|
89
|
+
expect do
|
90
|
+
analytics.screen Queued::SCREEN
|
91
|
+
sleep(1)
|
92
|
+
end.to_not raise_error
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe '#flush' do
|
97
|
+
it 'flushes without error' do
|
98
|
+
expect do
|
99
|
+
analytics.identify Queued::IDENTIFY
|
100
|
+
analytics.flush
|
101
|
+
end.to_not raise_error
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe '#respond_to?' do
|
106
|
+
it 'responds to all public instance methods of Segment::Analytics::Client' do
|
107
|
+
expect(analytics).to respond_to(*Segment::Analytics::Client.public_instance_methods(false))
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe '#method' do
|
112
|
+
Segment::Analytics::Client.public_instance_methods(false).each do |public_method|
|
113
|
+
it "returns a Method object with '#{public_method}' as argument" do
|
114
|
+
expect(analytics.method(public_method).class).to eq(Method)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
# https://github.com/codecov/codecov-ruby#usage
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start
|
4
|
+
require 'codecov'
|
5
|
+
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
6
|
+
|
7
|
+
require 'segment/analytics'
|
8
|
+
require 'active_support/time'
|
9
|
+
require './spec/helpers/runscope_client'
|
10
|
+
|
11
|
+
# Setting timezone for ActiveSupport::TimeWithZone to UTC
|
12
|
+
Time.zone = 'UTC'
|
13
|
+
|
14
|
+
module Segment
|
15
|
+
class Analytics
|
16
|
+
WRITE_KEY = 'testsecret'
|
17
|
+
|
18
|
+
TRACK = {
|
19
|
+
:event => 'Ruby Library test event',
|
20
|
+
:properties => {
|
21
|
+
:type => 'Chocolate',
|
22
|
+
:is_a_lie => true,
|
23
|
+
:layers => 20,
|
24
|
+
:created => Time.new
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
IDENTIFY = {
|
29
|
+
:traits => {
|
30
|
+
:likes_animals => true,
|
31
|
+
:instrument => 'Guitar',
|
32
|
+
:age => 25
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
ALIAS = {
|
37
|
+
:previous_id => 1234,
|
38
|
+
:user_id => 'abcd'
|
39
|
+
}
|
40
|
+
|
41
|
+
GROUP = {}
|
42
|
+
|
43
|
+
PAGE = {
|
44
|
+
:name => 'home'
|
45
|
+
}
|
46
|
+
|
47
|
+
SCREEN = {
|
48
|
+
:name => 'main'
|
49
|
+
}
|
50
|
+
|
51
|
+
USER_ID = 1234
|
52
|
+
GROUP_ID = 1234
|
53
|
+
|
54
|
+
# Hashes sent to the client, snake_case
|
55
|
+
module Queued
|
56
|
+
TRACK = TRACK.merge :user_id => USER_ID
|
57
|
+
IDENTIFY = IDENTIFY.merge :user_id => USER_ID
|
58
|
+
GROUP = GROUP.merge :group_id => GROUP_ID, :user_id => USER_ID
|
59
|
+
PAGE = PAGE.merge :user_id => USER_ID
|
60
|
+
SCREEN = SCREEN.merge :user_id => USER_ID
|
61
|
+
end
|
62
|
+
|
63
|
+
# Hashes which are sent from the worker, camel_cased
|
64
|
+
module Requested
|
65
|
+
TRACK = TRACK.merge({
|
66
|
+
:userId => USER_ID,
|
67
|
+
:type => 'track'
|
68
|
+
})
|
69
|
+
|
70
|
+
IDENTIFY = IDENTIFY.merge({
|
71
|
+
:userId => USER_ID,
|
72
|
+
:type => 'identify'
|
73
|
+
})
|
74
|
+
|
75
|
+
GROUP = GROUP.merge({
|
76
|
+
:groupId => GROUP_ID,
|
77
|
+
:userId => USER_ID,
|
78
|
+
:type => 'group'
|
79
|
+
})
|
80
|
+
|
81
|
+
PAGE = PAGE.merge :userId => USER_ID
|
82
|
+
SCREEN = SCREEN.merge :userId => USER_ID
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# A worker that doesn't consume jobs
|
88
|
+
class NoopWorker
|
89
|
+
def run
|
90
|
+
# Does nothing
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# A backoff policy that returns a fixed list of values
|
95
|
+
class FakeBackoffPolicy
|
96
|
+
def initialize(interval_values)
|
97
|
+
@interval_values = interval_values
|
98
|
+
end
|
99
|
+
|
100
|
+
def next_interval
|
101
|
+
raise 'FakeBackoffPolicy has no values left' if @interval_values.empty?
|
102
|
+
@interval_values.shift
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# usage:
|
107
|
+
# it "should return a result of 5" do
|
108
|
+
# eventually(options: {timeout: 1}) { long_running_thing.result.should eq(5) }
|
109
|
+
# end
|
110
|
+
|
111
|
+
module AsyncHelper
|
112
|
+
def eventually(options = {})
|
113
|
+
timeout = options[:timeout] || 2
|
114
|
+
interval = options[:interval] || 0.1
|
115
|
+
time_limit = Time.now + timeout
|
116
|
+
loop do
|
117
|
+
begin
|
118
|
+
yield
|
119
|
+
return
|
120
|
+
rescue RSpec::Expectations::ExpectationNotMetError => error
|
121
|
+
raise error if Time.now >= time_limit
|
122
|
+
sleep interval
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
include AsyncHelper
|
metadata
ADDED
@@ -0,0 +1,205 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: segment
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.2.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Segment
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: commander
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: tzinfo
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.2.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.2.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 4.1.11
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 4.1.11
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: faraday
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.13'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.13'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pmap
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.1'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.1'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.51.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.51.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: codecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.1.4
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.1.4
|
139
|
+
description: The Segment ruby analytics library
|
140
|
+
email: friends@segment.com
|
141
|
+
executables:
|
142
|
+
- analytics
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- Gemfile
|
147
|
+
- Gemfile.lock
|
148
|
+
- History.md
|
149
|
+
- Makefile
|
150
|
+
- README.md
|
151
|
+
- RELEASING.md
|
152
|
+
- Rakefile
|
153
|
+
- analytics-ruby.gemspec
|
154
|
+
- bin/analytics
|
155
|
+
- codecov.yml
|
156
|
+
- lib/analytics-ruby.rb
|
157
|
+
- lib/segment.rb
|
158
|
+
- lib/segment/analytics.rb
|
159
|
+
- lib/segment/analytics/backoff_policy.rb
|
160
|
+
- lib/segment/analytics/client.rb
|
161
|
+
- lib/segment/analytics/defaults.rb
|
162
|
+
- lib/segment/analytics/logging.rb
|
163
|
+
- lib/segment/analytics/message.rb
|
164
|
+
- lib/segment/analytics/message_batch.rb
|
165
|
+
- lib/segment/analytics/request.rb
|
166
|
+
- lib/segment/analytics/response.rb
|
167
|
+
- lib/segment/analytics/utils.rb
|
168
|
+
- lib/segment/analytics/version.rb
|
169
|
+
- lib/segment/analytics/worker.rb
|
170
|
+
- spec/helpers/runscope_client.rb
|
171
|
+
- spec/segment/analytics/backoff_policy_spec.rb
|
172
|
+
- spec/segment/analytics/client_spec.rb
|
173
|
+
- spec/segment/analytics/e2e_spec.rb
|
174
|
+
- spec/segment/analytics/message_batch_spec.rb
|
175
|
+
- spec/segment/analytics/message_spec.rb
|
176
|
+
- spec/segment/analytics/request_spec.rb
|
177
|
+
- spec/segment/analytics/response_spec.rb
|
178
|
+
- spec/segment/analytics/worker_spec.rb
|
179
|
+
- spec/segment/analytics_spec.rb
|
180
|
+
- spec/spec_helper.rb
|
181
|
+
homepage: https://github.com/segmentio/analytics-ruby
|
182
|
+
licenses:
|
183
|
+
- MIT
|
184
|
+
metadata: {}
|
185
|
+
post_install_message:
|
186
|
+
rdoc_options: []
|
187
|
+
require_paths:
|
188
|
+
- lib
|
189
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
194
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
195
|
+
requirements:
|
196
|
+
- - ">="
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: '0'
|
199
|
+
requirements: []
|
200
|
+
rubyforge_project:
|
201
|
+
rubygems_version: 2.5.2
|
202
|
+
signing_key:
|
203
|
+
specification_version: 4
|
204
|
+
summary: Segment analytics library
|
205
|
+
test_files: []
|