trakio-ruby 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/lib/trakio-ruby.rb +1 -0
- data/lib/trakio.rb +15 -17
- data/lib/trakio/version.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/trakio/alias_spec.rb +5 -4
- data/spec/trakio/annotate_spec.rb +12 -12
- data/spec/trakio/class_methods_spec.rb +11 -11
- data/spec/trakio/exception_spec.rb +7 -4
- data/spec/trakio/{indentify_spec.rb → identify_spec.rb} +3 -3
- data/spec/trakio/initialize_spec.rb +3 -3
- data/spec/trakio/instance_methods_spec.rb +11 -11
- data/spec/trakio/page_view_spec.rb +12 -11
- data/spec/trakio/protected_instance_methods_spec.rb +40 -0
- data/spec/trakio/track_spec.rb +13 -8
- data/trakio-ruby.gemspec +1 -1
- metadata +31 -28
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
N2M3MWUyOTRkMWU4ZjZkMDMwMzJkYjExMWYyYmIyYjI1N2FhZThlNGIzZmM1
|
10
|
-
ODZjZmRkZGMwZjE5NzI1YzQ1OTVkZGM1YjgwNDNjN2M3ZGNlYTBiMDViZTY4
|
11
|
-
NDlmOTg0MDUzZGY4OWVlZWJiYTFmMWEzOTc5ZmNlZTU3OWVjMDE=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MzY0Mzg3MjY4YTllMGE0ZGRjNTAyNjA5MzAzOTJmMmU4N2UxODkxZTQ4MDk0
|
14
|
-
MDcxNWM3Y2I3MmZiZGVhNTlhYjJkOTA0M2E4MThhMGZiZDBmMjRlNDEyOTU3
|
15
|
-
ZDUyYTFiYzBiNzc4NTNmNDA1OWZlZjY3NWZjNjFlYTljYjI3OGY=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2f0f9ac5b8ceaa20fd8a33d9f461a5e86c6be2ee
|
4
|
+
data.tar.gz: b8752c480a4f6283c43f4e814cabd24bdaddcf70
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7f054a3bfde7856c73967229185e4be803e971c66fda25d3c6a48355268deb903478b666175c5f6dff31d017c76f8c99755d6b6fb3fc5b370660597ed47487fc
|
7
|
+
data.tar.gz: b7b930459be4683ba41b95f305de49d43c42c04dc90ef2a167ae820ff317ff03174ffff400b7ead85dce2d35e1fcf067c164f2abad785c14ee8905496ac4e314
|
data/lib/trakio-ruby.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'trakio'
|
data/lib/trakio.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "trakio/version"
|
2
2
|
require "rest_client"
|
3
3
|
require "json"
|
4
|
+
require "date"
|
4
5
|
|
5
6
|
|
6
7
|
class Trakio
|
@@ -78,10 +79,6 @@ class Trakio
|
|
78
79
|
def track(parameters)
|
79
80
|
parameters.default = nil
|
80
81
|
|
81
|
-
distinct_id = parameters[:distinct_id]
|
82
|
-
distinct_id = @distinct_id unless distinct_id
|
83
|
-
raise "No distinct_id specified" unless distinct_id
|
84
|
-
|
85
82
|
event = parameters[:event] or raise "No event specified"
|
86
83
|
|
87
84
|
channel = parameters[:channel]
|
@@ -90,12 +87,14 @@ class Trakio
|
|
90
87
|
properties = parameters[:properties]
|
91
88
|
|
92
89
|
params = {
|
93
|
-
distinct_id:
|
90
|
+
distinct_id: distinct_id_from_parameters(parameters),
|
94
91
|
event: event,
|
95
92
|
}
|
96
|
-
if parameters[:time]
|
93
|
+
if parameters[:time] # if specified
|
97
94
|
params[:time] = parameters[:time]
|
98
95
|
params[:time] = params[:time].iso8601 unless params[:time].is_a? String
|
96
|
+
else # if nots specified default to now
|
97
|
+
params[:time] = DateTime.now.iso8601
|
99
98
|
end
|
100
99
|
params[:channel] = channel if channel
|
101
100
|
params[:properties] = properties if properties
|
@@ -106,15 +105,11 @@ class Trakio
|
|
106
105
|
def identify(parameters)
|
107
106
|
parameters.default = nil
|
108
107
|
|
109
|
-
distinct_id = parameters[:distinct_id]
|
110
|
-
distinct_id = @distinct_id unless distinct_id
|
111
|
-
raise "No distinct_id specified" unless distinct_id
|
112
|
-
|
113
108
|
properties = parameters[:properties]
|
114
109
|
raise "Properties must be specified" unless properties and properties.length > 0
|
115
110
|
|
116
111
|
params = {
|
117
|
-
distinct_id:
|
112
|
+
distinct_id: distinct_id_from_parameters(parameters),
|
118
113
|
properties: properties,
|
119
114
|
}
|
120
115
|
send_request('identify', params)
|
@@ -123,16 +118,12 @@ class Trakio
|
|
123
118
|
def alias(parameters)
|
124
119
|
parameters.default = nil
|
125
120
|
|
126
|
-
distinct_id = parameters[:distinct_id]
|
127
|
-
distinct_id = @distinct_id unless distinct_id
|
128
|
-
raise "No distinct_id specified" unless distinct_id
|
129
|
-
|
130
121
|
alias_ = parameters[:alias]
|
131
122
|
raise "No alias specified" unless alias_
|
132
123
|
raise "alias must be string or array" unless alias_.is_a?(String) or alias_.is_a?(Array)
|
133
124
|
|
134
125
|
params = {
|
135
|
-
distinct_id:
|
126
|
+
distinct_id: distinct_id_from_parameters(parameters),
|
136
127
|
alias: alias_,
|
137
128
|
}
|
138
129
|
send_request('alias', params)
|
@@ -164,7 +155,7 @@ class Trakio
|
|
164
155
|
event: 'Page view'
|
165
156
|
}
|
166
157
|
|
167
|
-
distinct_id = parameters
|
158
|
+
distinct_id = distinct_id_from_parameters(parameters)
|
168
159
|
args[:distinct_id] = distinct_id if distinct_id
|
169
160
|
|
170
161
|
raise "Must specify URL" unless parameters.has_key?(:url)
|
@@ -227,4 +218,11 @@ class Trakio
|
|
227
218
|
end
|
228
219
|
end
|
229
220
|
|
221
|
+
def distinct_id_from_parameters parameters
|
222
|
+
distinct_id = parameters[:distinct_id]
|
223
|
+
distinct_id = @distinct_id unless distinct_id
|
224
|
+
raise "No distinct_id specified" unless distinct_id
|
225
|
+
distinct_id
|
226
|
+
end
|
227
|
+
|
230
228
|
end
|
data/lib/trakio/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -8,7 +8,7 @@ require 'active_support/core_ext/date/calculations'
|
|
8
8
|
|
9
9
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
10
10
|
RSpec.configure do |config|
|
11
|
-
config.
|
11
|
+
config.raise_errors_for_deprecations!
|
12
12
|
config.run_all_when_everything_filtered = true
|
13
13
|
|
14
14
|
# Run specs in random order to surface order dependencies. If you find an
|
data/spec/trakio/alias_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe Trakio do
|
|
8
8
|
Trakio.default_instance = nil
|
9
9
|
}
|
10
10
|
|
11
|
-
describe '
|
11
|
+
describe '#alias' do
|
12
12
|
|
13
13
|
context "when an array alias is provided" do
|
14
14
|
it "sends an array" do
|
@@ -30,7 +30,7 @@ describe Trakio do
|
|
30
30
|
trakio = Trakio.new 'my_api_token'
|
31
31
|
trakio.alias distinct_id: 'user@example.com', alias: ['alias1@example.com']
|
32
32
|
|
33
|
-
stub.
|
33
|
+
expect(stub).to have_been_requested
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -52,7 +52,7 @@ describe Trakio do
|
|
52
52
|
trakio = Trakio.new 'my_api_token'
|
53
53
|
trakio.alias distinct_id: 'user@example.com', alias: 'alias1@example.com'
|
54
54
|
|
55
|
-
stub.
|
55
|
+
expect(stub).to have_been_requested
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -83,7 +83,7 @@ describe Trakio do
|
|
83
83
|
trakio = Trakio.new 'my_api_token', distinct_id: 'user@example.com'
|
84
84
|
trakio.alias alias: 'alias1@example.com'
|
85
85
|
|
86
|
-
stub.
|
86
|
+
expect(stub).to have_been_requested
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -97,4 +97,5 @@ describe Trakio do
|
|
97
97
|
end
|
98
98
|
|
99
99
|
end
|
100
|
+
|
100
101
|
end
|
@@ -8,12 +8,12 @@ describe Trakio do
|
|
8
8
|
Trakio.default_instance = nil
|
9
9
|
}
|
10
10
|
|
11
|
-
|
11
|
+
describe '#annotate' do
|
12
12
|
|
13
13
|
context "when an event is provided" do
|
14
14
|
|
15
15
|
context "when a channel is provided" do
|
16
|
-
it "
|
16
|
+
it "sends a request with the channel" do
|
17
17
|
stub = stub_request(:post, "https://api.trak.io/v1/annotate").
|
18
18
|
with(:body => {
|
19
19
|
token: 'my_api_token',
|
@@ -30,13 +30,13 @@ describe Trakio do
|
|
30
30
|
trakio = Trakio.new 'my_api_token'
|
31
31
|
trakio.annotate event: 'event', channel: 'channel'
|
32
32
|
|
33
|
-
stub.
|
33
|
+
expect(stub).to have_been_requested
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
context "when a channel isnt provided" do
|
38
38
|
context "when there is a channel set on the instance" do
|
39
|
-
it "
|
39
|
+
it "sends a request with the channel" do
|
40
40
|
stub = stub_request(:post, "https://api.trak.io/v1/annotate").
|
41
41
|
with(:body => {
|
42
42
|
token: 'my_api_token',
|
@@ -53,13 +53,13 @@ describe Trakio do
|
|
53
53
|
trakio = Trakio.new 'my_api_token', channel: 'channel'
|
54
54
|
trakio.annotate event: 'event'
|
55
55
|
|
56
|
-
stub.
|
56
|
+
expect(stub).to have_been_requested
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
context "when properties are provided" do
|
62
|
-
it "
|
62
|
+
it "sends a request with the properties" do
|
63
63
|
stub = stub_request(:post, "https://api.trak.io/v1/annotate").
|
64
64
|
with(:body => {
|
65
65
|
token: 'my_api_token',
|
@@ -77,12 +77,12 @@ describe Trakio do
|
|
77
77
|
trakio = Trakio.new 'my_api_token'
|
78
78
|
trakio.annotate event: 'event', properties: { details: 'details' }
|
79
79
|
|
80
|
-
stub.
|
80
|
+
expect(stub).to have_been_requested
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
84
|
context "when properties are not provided" do
|
85
|
-
it "
|
85
|
+
it "sends a request with empty properties" do
|
86
86
|
stub = stub_request(:post, "https://api.trak.io/v1/annotate").
|
87
87
|
with(:body => {
|
88
88
|
token: 'my_api_token',
|
@@ -98,7 +98,7 @@ describe Trakio do
|
|
98
98
|
trakio = Trakio.new 'my_api_token'
|
99
99
|
trakio.annotate event: 'event'
|
100
100
|
|
101
|
-
stub.
|
101
|
+
expect(stub).to have_been_requested
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
@@ -107,21 +107,21 @@ describe Trakio do
|
|
107
107
|
context "when an event is not provided" do
|
108
108
|
|
109
109
|
context "when a channel is provided" do
|
110
|
-
it "
|
110
|
+
it "raises an error" do
|
111
111
|
trakio = Trakio.new 'my_api_token'
|
112
112
|
expect { trakio.annotate channel: 'channel' }.to raise_error RuntimeError
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
116
|
context "when properties are provided" do
|
117
|
-
it "
|
117
|
+
it "raises an error" do
|
118
118
|
trakio = Trakio.new 'my_api_token'
|
119
119
|
expect { trakio.annotate properties: { name: 'tobie' } }.to raise_error RuntimeError
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
123
|
context "when no arguments are provided" do
|
124
|
-
it "
|
124
|
+
it "raises an error" do
|
125
125
|
trakio = Trakio.new 'my_api_token'
|
126
126
|
expect { trakio.annotate }.to raise_error ArgumentError
|
127
127
|
end
|
@@ -8,7 +8,7 @@ describe Trakio do
|
|
8
8
|
Trakio.default_instance = nil
|
9
9
|
}
|
10
10
|
|
11
|
-
describe '
|
11
|
+
describe '.default_instance' do
|
12
12
|
|
13
13
|
context "when a default instance hasn't been created" do
|
14
14
|
it "raises an exception" do
|
@@ -25,7 +25,7 @@ describe Trakio do
|
|
25
25
|
|
26
26
|
end
|
27
27
|
|
28
|
-
describe '
|
28
|
+
describe '.init' do
|
29
29
|
|
30
30
|
context "when an API token is provided" do
|
31
31
|
|
@@ -51,14 +51,14 @@ describe Trakio do
|
|
51
51
|
context "when a https is provided" do
|
52
52
|
it "sets https option" do
|
53
53
|
Trakio.init 'my_api_token', https: false
|
54
|
-
expect(Trakio.https).to
|
54
|
+
expect(Trakio.https).to be false
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
context "when a https isn't provided" do
|
59
59
|
it "defaults to true" do
|
60
60
|
Trakio.init 'my_api_token'
|
61
|
-
expect(Trakio.https).to
|
61
|
+
expect(Trakio.https).to be true
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -86,7 +86,7 @@ describe Trakio do
|
|
86
86
|
|
87
87
|
end
|
88
88
|
|
89
|
-
describe '
|
89
|
+
describe '.track' do
|
90
90
|
it "calls track on the default Trakio instance" do
|
91
91
|
default_instance = double(Trakio)
|
92
92
|
|
@@ -97,7 +97,7 @@ describe Trakio do
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
describe '
|
100
|
+
describe '.identify' do
|
101
101
|
it "calls identify on the default Trakio instance" do
|
102
102
|
default_instance = double(Trakio)
|
103
103
|
|
@@ -108,7 +108,7 @@ describe Trakio do
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
describe '
|
111
|
+
describe '.alias' do
|
112
112
|
it "calls alias on the default Trakio instance" do
|
113
113
|
default_instance = double(Trakio)
|
114
114
|
|
@@ -119,7 +119,7 @@ describe Trakio do
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
-
describe '
|
122
|
+
describe '.annotate' do
|
123
123
|
|
124
124
|
it "calls annotate on the default Trakio instance" do
|
125
125
|
default_instance = double(Trakio)
|
@@ -132,7 +132,7 @@ describe Trakio do
|
|
132
132
|
|
133
133
|
end
|
134
134
|
|
135
|
-
describe '
|
135
|
+
describe '.page_view' do
|
136
136
|
|
137
137
|
it "calls page_view on the default Trakio instance" do
|
138
138
|
default_instance = double(Trakio)
|
@@ -146,13 +146,13 @@ describe Trakio do
|
|
146
146
|
end
|
147
147
|
|
148
148
|
|
149
|
-
describe '
|
149
|
+
describe '.distinct_id' do
|
150
150
|
it "raise an error" do
|
151
151
|
expect{ Trakio.distinct_id }.to raise_error Trakio::Exceptions::NoDistinctIdForDefaultInstance
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
155
|
-
describe '
|
155
|
+
describe '.channel' do
|
156
156
|
|
157
157
|
it "calls channel on the default Trakio instance" do
|
158
158
|
default_instance = double(Trakio)
|
@@ -8,7 +8,7 @@ describe Trakio do
|
|
8
8
|
Trakio.default_instance = nil
|
9
9
|
}
|
10
10
|
|
11
|
-
describe '
|
11
|
+
describe '#track' do
|
12
12
|
|
13
13
|
context "when an error is returned by the API" do
|
14
14
|
it "raises an exception" do
|
@@ -16,6 +16,7 @@ describe Trakio do
|
|
16
16
|
with(:body => {
|
17
17
|
token: 'my_api_token',
|
18
18
|
data: {
|
19
|
+
time: /.+/,
|
19
20
|
distinct_id: 'user@example.com',
|
20
21
|
event: 'my-event'
|
21
22
|
}
|
@@ -32,7 +33,7 @@ describe Trakio do
|
|
32
33
|
trakio.track distinct_id: 'user@example.com', event: 'my-event'
|
33
34
|
}.to raise_error Trakio::Exceptions::InvalidToken
|
34
35
|
|
35
|
-
stub.
|
36
|
+
expect(stub).to have_been_requested
|
36
37
|
|
37
38
|
end
|
38
39
|
end
|
@@ -43,6 +44,7 @@ describe Trakio do
|
|
43
44
|
with(:body => {
|
44
45
|
token: 'my_api_token',
|
45
46
|
data: {
|
47
|
+
time: /.+/,
|
46
48
|
distinct_id: 'user@example.com',
|
47
49
|
event: 'my-event'
|
48
50
|
}
|
@@ -57,9 +59,10 @@ describe Trakio do
|
|
57
59
|
expect(resp[:status]).to eql 'success'
|
58
60
|
expect(resp[:trak_id]).to eql '1234567890'
|
59
61
|
|
60
|
-
stub.
|
62
|
+
expect(stub).to have_been_requested
|
61
63
|
end
|
62
64
|
end
|
63
65
|
|
64
|
-
end
|
66
|
+
end
|
67
|
+
|
65
68
|
end
|
@@ -8,7 +8,7 @@ describe Trakio do
|
|
8
8
|
Trakio.default_instance = nil
|
9
9
|
}
|
10
10
|
|
11
|
-
describe '
|
11
|
+
describe '#identify' do
|
12
12
|
|
13
13
|
context "when a distinct_id is provided" do
|
14
14
|
context "when properties are provided" do
|
@@ -31,7 +31,7 @@ describe Trakio do
|
|
31
31
|
trakio = Trakio.new 'my_api_token'
|
32
32
|
trakio.identify distinct_id: 'user@example.com', properties: { name: 'Tobie' }
|
33
33
|
|
34
|
-
stub.
|
34
|
+
expect(stub).to have_been_requested
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -57,7 +57,7 @@ describe Trakio do
|
|
57
57
|
trakio = Trakio.new 'my_api_token', distinct_id: 'user@example.com'
|
58
58
|
trakio.identify properties: { name: 'Tobie' }
|
59
59
|
|
60
|
-
stub.
|
60
|
+
expect(stub).to have_been_requested
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -8,7 +8,7 @@ describe Trakio do
|
|
8
8
|
Trakio.default_instance = nil
|
9
9
|
}
|
10
10
|
|
11
|
-
describe '
|
11
|
+
describe '#initialize' do
|
12
12
|
|
13
13
|
context "when an API token is provided" do
|
14
14
|
|
@@ -39,14 +39,14 @@ describe Trakio do
|
|
39
39
|
context "when a https option is provided" do
|
40
40
|
it "sets https option" do
|
41
41
|
trakio = Trakio.new 'my_api_token', https: false
|
42
|
-
expect(trakio.https).to
|
42
|
+
expect(trakio.https).to be false
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
context "when a https option isn't provided" do
|
47
47
|
it "defaults to true" do
|
48
48
|
trakio = Trakio.new 'my_api_token'
|
49
|
-
expect(trakio.https).to
|
49
|
+
expect(trakio.https).to be true
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -8,7 +8,7 @@ describe Trakio do
|
|
8
8
|
Trakio.default_instance = nil
|
9
9
|
}
|
10
10
|
|
11
|
-
describe '
|
11
|
+
describe '#distinct_id=' do
|
12
12
|
|
13
13
|
it "sets the distinct_id to be used by this Interface" do
|
14
14
|
trakio = Trakio.new 'api_token'
|
@@ -27,7 +27,7 @@ describe Trakio do
|
|
27
27
|
|
28
28
|
end
|
29
29
|
|
30
|
-
describe '
|
30
|
+
describe '#distinct_id' do
|
31
31
|
|
32
32
|
it "returns the current value" do
|
33
33
|
trakio = Trakio.new 'api_token'
|
@@ -37,7 +37,7 @@ describe Trakio do
|
|
37
37
|
|
38
38
|
end
|
39
39
|
|
40
|
-
describe '
|
40
|
+
describe '#channel=' do
|
41
41
|
|
42
42
|
it "sets the channel to be used by this Interface" do
|
43
43
|
trakio = Trakio.new 'api_token'
|
@@ -47,7 +47,7 @@ describe Trakio do
|
|
47
47
|
|
48
48
|
end
|
49
49
|
|
50
|
-
describe '
|
50
|
+
describe '#channel' do
|
51
51
|
|
52
52
|
it "returns the current value" do
|
53
53
|
trakio = Trakio.new 'api_token'
|
@@ -57,32 +57,32 @@ describe Trakio do
|
|
57
57
|
|
58
58
|
end
|
59
59
|
|
60
|
-
describe '
|
60
|
+
describe '#https=' do
|
61
61
|
|
62
62
|
it "sets whether https is to be used by this Interface" do
|
63
63
|
trakio = Trakio.new 'api_token'
|
64
64
|
trakio.https = false
|
65
|
-
expect(trakio.instance_variable_get('@https')).to
|
65
|
+
expect(trakio.instance_variable_get('@https')).to be false
|
66
66
|
end
|
67
67
|
|
68
68
|
end
|
69
69
|
|
70
|
-
describe '
|
70
|
+
describe '#https' do
|
71
71
|
|
72
72
|
it "returns the current value" do
|
73
73
|
trakio = Trakio.new 'api_token'
|
74
74
|
trakio.instance_variable_set('@https',false)
|
75
|
-
expect(trakio.https).to
|
75
|
+
expect(trakio.https).to be false
|
76
76
|
end
|
77
77
|
|
78
78
|
it "defaults to true" do
|
79
79
|
trakio = Trakio.new 'api_token'
|
80
|
-
expect(trakio.https).to
|
80
|
+
expect(trakio.https).to be true
|
81
81
|
end
|
82
82
|
|
83
83
|
end
|
84
84
|
|
85
|
-
describe '
|
85
|
+
describe '#host=' do
|
86
86
|
|
87
87
|
it "sets the host to be used by this Interface" do
|
88
88
|
trakio = Trakio.new 'api_token'
|
@@ -92,7 +92,7 @@ describe Trakio do
|
|
92
92
|
|
93
93
|
end
|
94
94
|
|
95
|
-
describe '
|
95
|
+
describe '#host' do
|
96
96
|
|
97
97
|
it "returns the current value" do
|
98
98
|
trakio = Trakio.new 'api_token'
|
@@ -8,15 +8,16 @@ describe Trakio do
|
|
8
8
|
Trakio.default_instance = nil
|
9
9
|
}
|
10
10
|
|
11
|
-
describe '
|
11
|
+
describe '#page_view' do
|
12
12
|
|
13
|
-
context
|
14
|
-
context
|
15
|
-
it
|
13
|
+
context "when a url is specified" do
|
14
|
+
context "when a title is specified" do
|
15
|
+
it "tracks a page_view" do
|
16
16
|
stub = stub_request(:post, "https://api.trak.io/v1/track").
|
17
17
|
with(:body => {
|
18
18
|
token: 'my_api_token',
|
19
19
|
data: {
|
20
|
+
time: /.+/,
|
20
21
|
distinct_id: 'user@example.com',
|
21
22
|
event: 'Page view',
|
22
23
|
properties: {
|
@@ -35,12 +36,12 @@ describe Trakio do
|
|
35
36
|
expect(resp[:status]).to eql 'success'
|
36
37
|
expect(resp[:trak_id]).to eql '1234567890'
|
37
38
|
|
38
|
-
stub.
|
39
|
+
expect(stub).to have_been_requested
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
42
|
-
context
|
43
|
-
it
|
43
|
+
context "when a title is not specified" do
|
44
|
+
it "raises an error" do
|
44
45
|
trakio = Trakio.new 'my_api_token'
|
45
46
|
expect {
|
46
47
|
trakio.page_view distinct_id: 'user@example.com',
|
@@ -50,16 +51,16 @@ describe Trakio do
|
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
53
|
-
context
|
54
|
-
it
|
54
|
+
context "when a url is not specified" do
|
55
|
+
it "raises an error" do
|
55
56
|
trakio = Trakio.new 'my_api_token'
|
56
57
|
expect {
|
57
58
|
trakio.page_view distinct_id: 'user@example.com'
|
58
59
|
}.to raise_error RuntimeError
|
59
60
|
end
|
60
61
|
|
61
|
-
context
|
62
|
-
it
|
62
|
+
context "when a title is specified" do
|
63
|
+
it "raises an error" do
|
63
64
|
trakio = Trakio.new 'my_api_token'
|
64
65
|
expect {
|
65
66
|
trakio.page_view distinct_id: 'user@example.com', title: 'Test Title'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Trakio do
|
4
|
+
|
5
|
+
subject { Trakio }
|
6
|
+
let(:trakio) { Trakio.init 'my_api_token' }
|
7
|
+
|
8
|
+
after { Trakio.default_instance = nil }
|
9
|
+
|
10
|
+
before { Trakio.send(:public, *Trakio.protected_instance_methods) }
|
11
|
+
|
12
|
+
describe '#distinct_id_from_parameters' do
|
13
|
+
|
14
|
+
context "when the :distinct_id key is provided in parameters" do
|
15
|
+
it "returns that value" do
|
16
|
+
expect(trakio.distinct_id_from_parameters({ distinct_id: 'my_distinct_id'})).to eq 'my_distinct_id'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when the :distinct_id key isn't provided in parameters" do
|
21
|
+
|
22
|
+
it "returns @distinct_id" do
|
23
|
+
trakio.distinct_id = 'other_distinct_id'
|
24
|
+
expect(trakio.distinct_id_from_parameters({ distinct_id: nil})).to eq 'other_distinct_id'
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
context "and @distinct_id has not been set" do
|
29
|
+
|
30
|
+
it "raises an exception" do
|
31
|
+
expect{ trakio.distinct_id_from_parameters({ distinct_id: nil}) }.to raise_error RuntimeError
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/spec/trakio/track_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe Trakio do
|
|
8
8
|
Trakio.default_instance = nil
|
9
9
|
}
|
10
10
|
|
11
|
-
describe '
|
11
|
+
describe '#track' do
|
12
12
|
|
13
13
|
context "when a distinct_id is provided" do
|
14
14
|
|
@@ -19,6 +19,7 @@ describe Trakio do
|
|
19
19
|
with(:body => {
|
20
20
|
token: 'my_api_token',
|
21
21
|
data: {
|
22
|
+
time: /.+/,
|
22
23
|
distinct_id: 'user@example.com',
|
23
24
|
event: 'my-event'
|
24
25
|
}
|
@@ -33,7 +34,7 @@ describe Trakio do
|
|
33
34
|
expect(resp[:status]).to eql 'success'
|
34
35
|
expect(resp[:trak_id]).to eql '1234567890'
|
35
36
|
|
36
|
-
stub.
|
37
|
+
expect(stub).to have_been_requested
|
37
38
|
end
|
38
39
|
|
39
40
|
context "when a channel is provided" do
|
@@ -43,6 +44,7 @@ describe Trakio do
|
|
43
44
|
with(:body => {
|
44
45
|
token: 'my_api_token',
|
45
46
|
data: {
|
47
|
+
time: /.+/,
|
46
48
|
distinct_id: 'user@example.com',
|
47
49
|
event: 'my-event',
|
48
50
|
channel: 'my-channel'
|
@@ -59,7 +61,7 @@ describe Trakio do
|
|
59
61
|
expect(resp[:status]).to eql 'success'
|
60
62
|
expect(resp[:trak_id]).to eql '1234567890'
|
61
63
|
|
62
|
-
stub.
|
64
|
+
expect(stub).to have_been_requested
|
63
65
|
end
|
64
66
|
|
65
67
|
end
|
@@ -71,6 +73,7 @@ describe Trakio do
|
|
71
73
|
with(:body => {
|
72
74
|
token: 'my_api_token',
|
73
75
|
data: {
|
76
|
+
time: /.+/,
|
74
77
|
distinct_id: 'user@example.com',
|
75
78
|
event: 'my-event',
|
76
79
|
channel: 'my-channel'
|
@@ -86,7 +89,7 @@ describe Trakio do
|
|
86
89
|
expect(resp[:status]).to eql 'success'
|
87
90
|
expect(resp[:trak_id]).to eql '1234567890'
|
88
91
|
|
89
|
-
stub.
|
92
|
+
expect(stub).to have_been_requested
|
90
93
|
end
|
91
94
|
|
92
95
|
end
|
@@ -98,6 +101,7 @@ describe Trakio do
|
|
98
101
|
with(:body => {
|
99
102
|
token: 'my_api_token',
|
100
103
|
data: {
|
104
|
+
time: /.+/,
|
101
105
|
distinct_id: 'user@example.com',
|
102
106
|
event: 'my-event',
|
103
107
|
channel: 'my-channel',
|
@@ -117,7 +121,7 @@ describe Trakio do
|
|
117
121
|
expect(resp[:status]).to eql 'success'
|
118
122
|
expect(resp[:trak_id]).to eql '1234567890'
|
119
123
|
|
120
|
-
stub.
|
124
|
+
expect(stub).to have_been_requested
|
121
125
|
end
|
122
126
|
|
123
127
|
end
|
@@ -146,7 +150,7 @@ describe Trakio do
|
|
146
150
|
expect(resp[:status]).to eql 'success'
|
147
151
|
expect(resp[:trak_id]).to eql '1234567890'
|
148
152
|
|
149
|
-
stub.
|
153
|
+
expect(stub).to have_been_requested
|
150
154
|
end
|
151
155
|
|
152
156
|
end
|
@@ -175,7 +179,7 @@ describe Trakio do
|
|
175
179
|
expect(resp[:status]).to eql 'success'
|
176
180
|
expect(resp[:trak_id]).to eql '1234567890'
|
177
181
|
|
178
|
-
stub.
|
182
|
+
expect(stub).to have_been_requested
|
179
183
|
end
|
180
184
|
|
181
185
|
end
|
@@ -215,6 +219,7 @@ describe Trakio do
|
|
215
219
|
with(:body => {
|
216
220
|
token: 'my_api_token',
|
217
221
|
data: {
|
222
|
+
time: /.+/,
|
218
223
|
distinct_id: 'user@example.com',
|
219
224
|
event: 'my-event',
|
220
225
|
}
|
@@ -226,7 +231,7 @@ describe Trakio do
|
|
226
231
|
trakio = Trakio.new 'my_api_token', distinct_id: 'user@example.com'
|
227
232
|
trakio.track event: 'my-event'
|
228
233
|
|
229
|
-
stub.
|
234
|
+
expect(stub).to have_been_requested
|
230
235
|
end
|
231
236
|
|
232
237
|
end
|
data/trakio-ruby.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
22
|
spec.add_development_dependency 'rake'
|
23
|
-
spec.add_development_dependency 'rspec'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3'
|
24
24
|
spec.add_development_dependency 'webmock'
|
25
25
|
spec.add_development_dependency 'fuubar'
|
26
26
|
spec.add_development_dependency 'coveralls'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trakio-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Spence
|
@@ -9,118 +9,118 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-08-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - ~>
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '1.3'
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - ~>
|
25
|
+
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '1.3'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '0'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- -
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rspec
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
48
|
+
version: '3'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
55
|
+
version: '3'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: webmock
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: fuubar
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- -
|
81
|
+
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: coveralls
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- -
|
88
|
+
- - ">="
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '0'
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- -
|
95
|
+
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
99
|
name: activesupport
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- -
|
102
|
+
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- -
|
109
|
+
- - ">="
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
113
|
name: rest_client
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
|
-
- -
|
116
|
+
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: '0'
|
119
119
|
type: :runtime
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
|
-
- -
|
123
|
+
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
126
|
description: Official trak.io ruby library for Ruby
|
@@ -131,13 +131,14 @@ executables: []
|
|
131
131
|
extensions: []
|
132
132
|
extra_rdoc_files: []
|
133
133
|
files:
|
134
|
-
- .coveralls.yml
|
135
|
-
- .gitignore
|
136
|
-
- .travis.yml
|
134
|
+
- ".coveralls.yml"
|
135
|
+
- ".gitignore"
|
136
|
+
- ".travis.yml"
|
137
137
|
- Gemfile
|
138
138
|
- LICENSE
|
139
139
|
- README.md
|
140
140
|
- Rakefile
|
141
|
+
- lib/trakio-ruby.rb
|
141
142
|
- lib/trakio.rb
|
142
143
|
- lib/trakio/version.rb
|
143
144
|
- spec/spec_helper.rb
|
@@ -145,10 +146,11 @@ files:
|
|
145
146
|
- spec/trakio/annotate_spec.rb
|
146
147
|
- spec/trakio/class_methods_spec.rb
|
147
148
|
- spec/trakio/exception_spec.rb
|
148
|
-
- spec/trakio/
|
149
|
+
- spec/trakio/identify_spec.rb
|
149
150
|
- spec/trakio/initialize_spec.rb
|
150
151
|
- spec/trakio/instance_methods_spec.rb
|
151
152
|
- spec/trakio/page_view_spec.rb
|
153
|
+
- spec/trakio/protected_instance_methods_spec.rb
|
152
154
|
- spec/trakio/track_spec.rb
|
153
155
|
- trakio-ruby.gemspec
|
154
156
|
homepage: https://trak.io
|
@@ -161,17 +163,17 @@ require_paths:
|
|
161
163
|
- lib
|
162
164
|
required_ruby_version: !ruby/object:Gem::Requirement
|
163
165
|
requirements:
|
164
|
-
- -
|
166
|
+
- - ">="
|
165
167
|
- !ruby/object:Gem::Version
|
166
168
|
version: '0'
|
167
169
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
170
|
requirements:
|
169
|
-
- -
|
171
|
+
- - ">="
|
170
172
|
- !ruby/object:Gem::Version
|
171
173
|
version: '0'
|
172
174
|
requirements: []
|
173
175
|
rubyforge_project:
|
174
|
-
rubygems_version: 2.
|
176
|
+
rubygems_version: 2.2.2
|
175
177
|
signing_key:
|
176
178
|
specification_version: 4
|
177
179
|
summary: Official trak.io ruby library for Ruby
|
@@ -181,8 +183,9 @@ test_files:
|
|
181
183
|
- spec/trakio/annotate_spec.rb
|
182
184
|
- spec/trakio/class_methods_spec.rb
|
183
185
|
- spec/trakio/exception_spec.rb
|
184
|
-
- spec/trakio/
|
186
|
+
- spec/trakio/identify_spec.rb
|
185
187
|
- spec/trakio/initialize_spec.rb
|
186
188
|
- spec/trakio/instance_methods_spec.rb
|
187
189
|
- spec/trakio/page_view_spec.rb
|
190
|
+
- spec/trakio/protected_instance_methods_spec.rb
|
188
191
|
- spec/trakio/track_spec.rb
|