kmts 2.0.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +12 -0
- data/Gemfile.lock +24 -16
- data/README.md +12 -7
- data/Rakefile +7 -2
- data/doc/README_rdoc.html +22 -22
- data/kmts.gemspec +9 -8
- data/lib/kmts.rb +30 -15
- data/lib/kmts/version.rb +1 -1
- data/spec/accept.rb +1 -1
- data/spec/km_old.rb +2 -2
- data/spec/km_saas_spec.rb +4 -6
- data/spec/km_send_spec.rb +14 -12
- data/spec/km_spec.rb +53 -19
- data/spec/setup.rb +5 -1
- metadata +30 -29
- data/README.rdoc +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 63f20f75c5fb43e2daf45c420ef3eef9c3dd9b8d8cf69c40fe85d1be139d51fb
|
4
|
+
data.tar.gz: ef06b72bb06e217c103c6323670b77795a876e625225fbce8b7b8e39d828c000
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d3e134e167ea89b741083b0a3c974922cc9ee7dd227ec07b97ea8aceaadc1d04138ee271c6c90f2f9482427047671651044960e64a1ab7e23332315e9712ef7
|
7
|
+
data.tar.gz: c5df65fef48f3ddf437e4c6703734b800aff1b6c8348ef5a2a1a2b517a2485e4f2799dabb3aeb39a413c8d2b56371e1ced7d7508a7406c79376cb16b6e1138fd
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,29 +1,37 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kmts (
|
4
|
+
kmts (3.1.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
diff-lcs (1.
|
10
|
-
json (
|
11
|
-
rake (0.
|
12
|
-
rspec (
|
13
|
-
rspec-core (~>
|
14
|
-
rspec-expectations (~>
|
15
|
-
rspec-mocks (~>
|
16
|
-
rspec-core (
|
17
|
-
|
18
|
-
|
19
|
-
|
9
|
+
diff-lcs (1.2.5)
|
10
|
+
json (2.0.2)
|
11
|
+
rake (12.0.0)
|
12
|
+
rspec (3.5.0)
|
13
|
+
rspec-core (~> 3.5.0)
|
14
|
+
rspec-expectations (~> 3.5.0)
|
15
|
+
rspec-mocks (~> 3.5.0)
|
16
|
+
rspec-core (3.5.4)
|
17
|
+
rspec-support (~> 3.5.0)
|
18
|
+
rspec-expectations (3.5.0)
|
19
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
20
|
+
rspec-support (~> 3.5.0)
|
21
|
+
rspec-mocks (3.5.0)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.5.0)
|
24
|
+
rspec-support (3.5.0)
|
20
25
|
|
21
26
|
PLATFORMS
|
22
27
|
ruby
|
23
28
|
|
24
29
|
DEPENDENCIES
|
25
|
-
bundler (
|
26
|
-
json
|
30
|
+
bundler (~> 1.13)
|
31
|
+
json (~> 2.0)
|
27
32
|
kmts!
|
28
|
-
rake
|
29
|
-
rspec (~>
|
33
|
+
rake (~> 12.0)
|
34
|
+
rspec (~> 3.5)
|
35
|
+
|
36
|
+
BUNDLED WITH
|
37
|
+
1.13.7
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
##
|
1
|
+
## Kissmetrics Threadsafe Ruby library
|
2
2
|
|
3
3
|
This gem is a threadsafe fork of the original `km` gem.
|
4
4
|
|
@@ -6,19 +6,23 @@ This gem is a threadsafe fork of the original `km` gem.
|
|
6
6
|
|
7
7
|
Version 1.0.2 of the `kmts` gem had an issue where it was found to not actually be thread safe. If you were using version 1.0.2 of the `kmts` gem, you were likely using non thread-safe code. In this case, you will want to either switch to using the non thread-safe [`km`](https://github.com/kissmetrics/km) gem, or update your code to use the thread-safe `kmts` gem version >= 2.0.0.
|
8
8
|
|
9
|
+
## `kmts` version 3.1.0
|
10
|
+
|
11
|
+
Uses the `trk.kissmetrics.io` tracking domain.
|
12
|
+
|
9
13
|
## Setup
|
10
14
|
|
11
15
|
The best way to install the gem is using `gem install kmts` or by adding it to your `Gemfile`:
|
12
16
|
|
13
17
|
```ruby
|
14
|
-
gem 'kmts', '~>
|
18
|
+
gem 'kmts', '~> 3.0.0'
|
15
19
|
```
|
16
20
|
|
17
21
|
Otherwise, the gem is available on GitHub:
|
18
22
|
|
19
23
|
https://github.com/kissmetrics/kmts
|
20
24
|
|
21
|
-
You will need your API key which you can find in your [site settings](
|
25
|
+
You will need your API key which you can find in your [site settings](https://support.kissmetrics.io/docs/product-settings).
|
22
26
|
|
23
27
|
## Usage
|
24
28
|
|
@@ -30,11 +34,12 @@ KMTS.init('KM_KEY' [, options])
|
|
30
34
|
|
31
35
|
The available options are:
|
32
36
|
|
33
|
-
* `log_dir`: sets the logging directory. Default is `'/tmp'`. Please make sure that the directory exists, and that whatever web process is writing to the log has permission to write to that directory. The log file will contain a list of the URLs that would be requested (`trk.kissmetrics.
|
34
|
-
* `use_cron`: toggles whether to send data directly to
|
37
|
+
* `log_dir`: sets the logging directory. Default is `'/tmp'`. Please make sure that the directory exists, and that whatever web process is writing to the log has permission to write to that directory. The log file will contain a list of the URLs that would be requested (`trk.kissmetrics.io` URLs - please refer to [API Specifications](https://support.kissmetrics.io/reference#api-specifications-1).
|
38
|
+
* `use_cron`: toggles whether to send data directly to Kissmetrics, or log to a file and send in the background via cron (see [Sending Data with Cron](http://support.kissmetrics.com/apis/cron) for more information). As of version 3.0, the default is `true`, which means data is saved to a local log file. Using cron is optional, but **recommended**.
|
35
39
|
* `to_stderr`: allows toggling of printing output to `stderr`. Default is `true`.
|
36
|
-
* `dryrun`: New option as of November 25, 2012. Toggles whether to send data to
|
40
|
+
* `dryrun`: New option as of November 25, 2012. Toggles whether to send data to Kissmetrics, or just log it to a file to review for debugging. Default is `false`, which means data is sent to Kissmetrics, regardless of whether you're working in a production or development environment.
|
37
41
|
* `env`: Updated option as of November 25, 2012. The environment variable now just helps us name the log files that store the history of event requests. This uses the Rails and Rack variables to determine if your Ruby environment is in `development`. If the Rails and Rack variables are not available, we default to `production`.
|
42
|
+
* `force_key`: Allows each individual request to specify the API key through the `_k` param. By default the `_k` is set on all requests using the value provided to `KMTS.init`. The `_k` key will default to the API key if no value is passed in. Defaults to **true**.
|
38
43
|
|
39
44
|
### Sample:
|
40
45
|
|
@@ -56,7 +61,7 @@ KMTS.alias('bob', 'bob@bob.com')
|
|
56
61
|
|
57
62
|
## Troubleshooting
|
58
63
|
|
59
|
-
If you were watching for the events in [
|
64
|
+
If you were watching for the events in [Kissmetrics Live](https://support.kissmetrics.io/docs/live-1) and did not see them, it helps to review what our library logged. In the log directory, you may see these files:
|
60
65
|
|
61
66
|
* `kissmetrics_production_sent.log`
|
62
67
|
* `kissmetrics_production_query.log`
|
data/Rakefile
CHANGED
data/doc/README_rdoc.html
CHANGED
@@ -33,21 +33,21 @@
|
|
33
33
|
</div>
|
34
34
|
|
35
35
|
<div id="project-metadata">
|
36
|
-
|
37
|
-
|
36
|
+
|
37
|
+
|
38
38
|
<div id="fileindex-section" class="section project-section">
|
39
39
|
<h3 class="section-header">Files</h3>
|
40
40
|
<ul>
|
41
|
-
|
41
|
+
|
42
42
|
<li class="file"><a href="./Gemfile.html">Gemfile</a></li>
|
43
|
-
|
43
|
+
|
44
44
|
<li class="file"><a href="./README_rdoc.html">README.rdoc</a></li>
|
45
|
-
|
45
|
+
|
46
46
|
<li class="file"><a href="./Rakefile.html">Rakefile</a></li>
|
47
|
-
|
47
|
+
|
48
48
|
</ul>
|
49
49
|
</div>
|
50
|
-
|
50
|
+
|
51
51
|
|
52
52
|
<div id="classindex-section" class="section project-section">
|
53
53
|
<h3 class="section-header">Class Index
|
@@ -63,46 +63,46 @@
|
|
63
63
|
</form>
|
64
64
|
|
65
65
|
<ul class="link-list">
|
66
|
-
|
66
|
+
|
67
67
|
<li><a href="./KMTS.html">KMTS</a></li>
|
68
|
-
|
68
|
+
|
69
69
|
<li><a href="./KMTS/IdentError.html">KMTS::IdentError</a></li>
|
70
|
-
|
70
|
+
|
71
71
|
<li><a href="./KMTS/InitError.html">KMTS::InitError</a></li>
|
72
|
-
|
72
|
+
|
73
73
|
<li><a href="./KMTS/SaaS.html">KMTS::SaaS</a></li>
|
74
|
-
|
74
|
+
|
75
75
|
<li><a href="./Accept.html">Accept</a></li>
|
76
|
-
|
76
|
+
|
77
77
|
<li><a href="./Hash.html">Hash</a></li>
|
78
|
-
|
78
|
+
|
79
79
|
<li><a href="./Helper.html">Helper</a></li>
|
80
|
-
|
80
|
+
|
81
81
|
<li><a href="./KMError.html">KMError</a></li>
|
82
|
-
|
82
|
+
|
83
83
|
<li><a href="./Object.html">Object</a></li>
|
84
|
-
|
84
|
+
|
85
85
|
<li><a href="./String.html">String</a></li>
|
86
|
-
|
86
|
+
|
87
87
|
</ul>
|
88
88
|
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
|
89
89
|
</div>
|
90
90
|
|
91
|
-
|
91
|
+
|
92
92
|
</div>
|
93
93
|
</div>
|
94
94
|
|
95
95
|
<div id="documentation">
|
96
|
-
|
96
|
+
|
97
97
|
<h1>Documentation</h1>
|
98
98
|
|
99
99
|
<p>We are hosting our documentation for our Ruby API here: <a
|
100
|
-
href="
|
100
|
+
href="https://support.kissmetrics.io/reference#ruby">https://support.kissmetrics.io/reference#ruby</a></p>
|
101
101
|
|
102
102
|
<h1>SaaS</h1>
|
103
103
|
|
104
104
|
<p>This gem includes SaaS calls. For more information please refer to: <a
|
105
|
-
href="
|
105
|
+
href="https://support.kissmetrics.io/docs/saas-essentials">https://support.kissmetrics.io/docs/saas-essentials</a></p>
|
106
106
|
|
107
107
|
<p>In order to get the API for SaaS, be sure to:</p>
|
108
108
|
|
data/kmts.gemspec
CHANGED
@@ -5,19 +5,20 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.name = "kmts"
|
6
6
|
s.version = KMTS::VERSION
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
|
-
s.
|
9
|
-
s.
|
8
|
+
s.license = "Apache-2.0"
|
9
|
+
s.authors = ["Kissmetrics"]
|
10
|
+
s.email = ["support@kissmetrics.io"]
|
10
11
|
s.homepage = "https://github.com/kissmetrics/kmts"
|
11
|
-
s.summary = "
|
12
|
-
s.description = "
|
12
|
+
s.summary = "Threadsafe Ruby gem for Kissmetrics tracking API"
|
13
|
+
s.description = "A threadsafe Ruby gem that can be used to interact with the Kissmetrics tracking API."
|
13
14
|
|
14
15
|
s.required_rubygems_version = ">= 1.3.6"
|
15
16
|
s.rubyforge_project = "kissmetrics"
|
16
17
|
|
17
|
-
s.add_development_dependency "bundler", "
|
18
|
-
s.add_development_dependency "rspec", "~>
|
19
|
-
s.add_development_dependency "rake"
|
20
|
-
s.add_development_dependency "json"
|
18
|
+
s.add_development_dependency "bundler", "~> 1.13"
|
19
|
+
s.add_development_dependency "rspec", "~> 3.5"
|
20
|
+
s.add_development_dependency "rake", "~> 12.0"
|
21
|
+
s.add_development_dependency "json", "~> 2.0"
|
21
22
|
|
22
23
|
s.files = `git ls-files`.split("\n")
|
23
24
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/lib/kmts.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'uri'
|
2
|
+
require 'erb'
|
2
3
|
require 'socket'
|
3
4
|
require 'net/http'
|
4
5
|
require 'fileutils'
|
@@ -7,13 +8,17 @@ require 'kmts/saas'
|
|
7
8
|
class KMError < StandardError; end
|
8
9
|
|
9
10
|
class KMTS
|
11
|
+
DEFAULT_TRACKING_SERVER = 'https://trk.kissmetrics.io'.freeze
|
12
|
+
PROTOCOL_MATCHER = %r(://)
|
13
|
+
|
10
14
|
@key = nil
|
11
15
|
@logs = {}
|
12
|
-
@host =
|
16
|
+
@host = DEFAULT_TRACKING_SERVER
|
13
17
|
@log_dir = '/tmp'
|
14
18
|
@to_stderr = true
|
15
|
-
@use_cron =
|
19
|
+
@use_cron = true
|
16
20
|
@dryrun = false
|
21
|
+
@force_key = true
|
17
22
|
|
18
23
|
class << self
|
19
24
|
class IdentError < StandardError; end
|
@@ -27,6 +32,7 @@ class KMTS
|
|
27
32
|
:use_cron => @use_cron,
|
28
33
|
:dryrun => @dryrun,
|
29
34
|
:env => set_env,
|
35
|
+
:force_key => @force_key
|
30
36
|
}
|
31
37
|
options = default.merge(options)
|
32
38
|
|
@@ -38,6 +44,7 @@ class KMTS
|
|
38
44
|
@to_stderr = options[:to_stderr]
|
39
45
|
@dryrun = options[:dryrun]
|
40
46
|
@env = options[:env]
|
47
|
+
@force_key = options[:force_key]
|
41
48
|
log_dir_writable?
|
42
49
|
rescue Exception => e
|
43
50
|
log_error(e)
|
@@ -121,12 +128,13 @@ class KMTS
|
|
121
128
|
@id = nil
|
122
129
|
@key = nil
|
123
130
|
@logs = {}
|
124
|
-
@host =
|
131
|
+
@host = DEFAULT_TRACKING_SERVER
|
125
132
|
@log_dir = '/tmp'
|
126
133
|
@to_stderr = true
|
127
134
|
@use_cron = false
|
128
135
|
@env = nil
|
129
136
|
@force = false
|
137
|
+
@force_key = true
|
130
138
|
end
|
131
139
|
|
132
140
|
def log_name(type)
|
@@ -143,7 +151,9 @@ class KMTS
|
|
143
151
|
when :sent
|
144
152
|
fname = "kissmetrics#{env}_sent.log"
|
145
153
|
when :send
|
146
|
-
|
154
|
+
now = Time.now.to_i
|
155
|
+
id = rand(2**64).to_s(16)
|
156
|
+
fname = "#{now}_#{id}_kissmetrics_#{env}_sending.log"
|
147
157
|
end
|
148
158
|
@logs[type] = File.join(@log_dir,fname)
|
149
159
|
end
|
@@ -188,14 +198,17 @@ class KMTS
|
|
188
198
|
query_arr = []
|
189
199
|
query = ''
|
190
200
|
data.update('_p' => id) if id
|
191
|
-
data.update
|
192
|
-
data.update '_d' => 1 if data['_t']
|
201
|
+
data.update '_d' => 1 if data['_t'] || @use_cron
|
193
202
|
data['_t'] ||= Time.now.to_i
|
194
|
-
|
195
|
-
|
196
|
-
|
203
|
+
|
204
|
+
if @force_key
|
205
|
+
data['_k'] = @key
|
206
|
+
else
|
207
|
+
data['_k'] ||= @key
|
208
|
+
end
|
209
|
+
|
197
210
|
data.inject(query) do |query,key_val|
|
198
|
-
query_arr << key_val.collect { |i|
|
211
|
+
query_arr << key_val.collect { |i| ERB::Util.url_encode(i.to_s) }.join('=')
|
199
212
|
end
|
200
213
|
query = '/' + type + '?' + query_arr.join('&')
|
201
214
|
if @use_cron
|
@@ -215,11 +228,13 @@ class KMTS
|
|
215
228
|
log_sent(line)
|
216
229
|
else
|
217
230
|
begin
|
218
|
-
host
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
231
|
+
host = @host
|
232
|
+
host = "http://#{host}" unless host =~ PROTOCOL_MATCHER
|
233
|
+
uri = URI.parse(host)
|
234
|
+
|
235
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
236
|
+
http.use_ssl = uri.is_a?(URI::HTTPS)
|
237
|
+
http.get(line)
|
223
238
|
rescue Exception => e
|
224
239
|
raise KMError.new("#{e} for host #{@host}")
|
225
240
|
end
|
data/lib/kmts/version.rb
CHANGED
data/spec/accept.rb
CHANGED
data/spec/km_old.rb
CHANGED
@@ -2,15 +2,15 @@ require 'setup'
|
|
2
2
|
|
3
3
|
describe KMTS do
|
4
4
|
attr_accessor :send_query, :log
|
5
|
+
|
5
6
|
before do
|
6
7
|
@send_query = []
|
7
8
|
@log = []
|
8
9
|
KMTS.stub(:send_query).and_return { |*args| send_query << args }
|
9
10
|
KMTS.stub(:log).and_return { |*args| log << Hash[*args] }
|
10
|
-
time = Time.at 1234567890
|
11
|
-
Time.stub!(:now).and_return(time)
|
12
11
|
KMTS.reset
|
13
12
|
end
|
13
|
+
|
14
14
|
context "initialization" do
|
15
15
|
it "should not record without initialization" do
|
16
16
|
KMTS::record 'My Action'
|
data/spec/km_saas_spec.rb
CHANGED
@@ -3,8 +3,6 @@ require 'kmts/saas'
|
|
3
3
|
describe KMTS do
|
4
4
|
before do
|
5
5
|
KMTS::reset
|
6
|
-
now = Time.now
|
7
|
-
Time.stub!(:now).and_return(now)
|
8
6
|
FileUtils.rm_f KMTS::log_name(:error)
|
9
7
|
FileUtils.rm_f KMTS::log_name(:query)
|
10
8
|
Helper.clear
|
@@ -12,7 +10,7 @@ describe KMTS do
|
|
12
10
|
|
13
11
|
describe "should record events" do
|
14
12
|
before do
|
15
|
-
KMTS::init 'KM_KEY', :log_dir => __('log'), :host => '127.0.0.1:9292'
|
13
|
+
KMTS::init 'KM_KEY', :log_dir => __('log'), :host => 'http://127.0.0.1:9292'
|
16
14
|
end
|
17
15
|
context "plain usage" do
|
18
16
|
it "records a signup event" do
|
@@ -56,13 +54,13 @@ describe KMTS do
|
|
56
54
|
res[:query]['_n'].first.should == 'Canceled'
|
57
55
|
end
|
58
56
|
it "records a visited site event" do
|
59
|
-
KMTS.visited_site 'bob', 'http://duckduckgo.com', 'http://kissmetrics.
|
57
|
+
KMTS.visited_site 'bob', 'http://duckduckgo.com', 'http://kissmetrics.io'
|
60
58
|
sleep 0.1
|
61
59
|
res = Helper.accept(:history).first.indifferent
|
62
60
|
res[:path].should == '/e'
|
63
61
|
res[:query]['_n'].first.should == 'Visited Site'
|
64
62
|
res[:query]['URL'].first.should == 'http://duckduckgo.com'
|
65
|
-
res[:query]['Referrer'].first.should == 'http://kissmetrics.
|
63
|
+
res[:query]['Referrer'].first.should == 'http://kissmetrics.io'
|
66
64
|
end
|
67
65
|
end
|
68
66
|
context "usage with props" do
|
@@ -97,7 +95,7 @@ describe KMTS do
|
|
97
95
|
res[:query]['foo'].first.should == 'bar'
|
98
96
|
end
|
99
97
|
it "records a visited site event" do
|
100
|
-
KMTS.visited_site 'bob', 'http://duckduckgo.com', 'http://kissmetrics.
|
98
|
+
KMTS.visited_site 'bob', 'http://duckduckgo.com', 'http://kissmetrics.io', :foo => 'bar'
|
101
99
|
sleep 0.1
|
102
100
|
res = Helper.accept(:history).first.indifferent
|
103
101
|
res[:query]['foo'].first.should == 'bar'
|
data/spec/km_send_spec.rb
CHANGED
@@ -4,32 +4,33 @@ describe 'km_send' do
|
|
4
4
|
context "using cron for sending logs" do
|
5
5
|
before do
|
6
6
|
now = Time.now
|
7
|
-
Time.stub!(:now).and_return(now)
|
8
7
|
Dir.glob(__('log','*')).each do |file|
|
9
8
|
FileUtils.rm file
|
10
9
|
end
|
11
10
|
KMTS.reset
|
12
11
|
Helper.clear
|
13
12
|
end
|
13
|
+
|
14
14
|
context "with default environment" do
|
15
15
|
before do
|
16
|
-
KMTS::init 'KM_KEY', :log_dir => __('log'), :host => '127.0.0.1:9292', :use_cron => true
|
16
|
+
KMTS::init 'KM_KEY', :log_dir => __('log'), :host => 'http://127.0.0.1:9292', :use_cron => true, :env => 'production'
|
17
17
|
end
|
18
18
|
it "should test commandline version" do
|
19
19
|
KMTS::record 'bob', 'Signup', 'age' => 26
|
20
|
-
`bundle exec km_send #{__('log/')} 127.0.0.1:9292`
|
20
|
+
`bundle exec km_send #{__('log/')} http://127.0.0.1:9292`
|
21
21
|
sleep 0.1
|
22
22
|
res = Helper.accept(:history).first.indifferent
|
23
23
|
res[:path].should == '/e'
|
24
24
|
res[:query]['_k'].first.should == 'KM_KEY'
|
25
25
|
res[:query]['_p'].first.should == 'bob'
|
26
26
|
res[:query]['_n'].first.should == 'Signup'
|
27
|
-
res[:query]['
|
27
|
+
res[:query]['_d'].first.should == '1'
|
28
|
+
res[:query]['_t'].first.to_i.should be_within(10.0).of(Time.now.to_i)
|
28
29
|
res[:query]['age'].first.should == '26'
|
29
30
|
end
|
30
31
|
it "should send from query_log" do
|
31
32
|
write_log :query, "/e?_t=1297105499&_n=Signup&_p=bob&_k=KM_KEY&age=26"
|
32
|
-
`bundle exec km_send #{__('log/')} 127.0.0.1:9292`
|
33
|
+
`bundle exec km_send #{__('log/')} http://127.0.0.1:9292`
|
33
34
|
sleep 0.1
|
34
35
|
res = Helper.accept(:history).first.indifferent
|
35
36
|
res[:path].should == '/e'
|
@@ -41,7 +42,7 @@ describe 'km_send' do
|
|
41
42
|
end
|
42
43
|
it "should send from query_log_old" do
|
43
44
|
write_log :query_old, "/e?_t=1297105499&_n=Signup&_p=bob&_k=KM_KEY&age=26"
|
44
|
-
`bundle exec km_send #{__('log/')} 127.0.0.1:9292`
|
45
|
+
`bundle exec km_send #{__('log/')} http://127.0.0.1:9292`
|
45
46
|
sleep 0.1
|
46
47
|
res = Helper.accept(:history).first.indifferent
|
47
48
|
res[:path].should == '/e'
|
@@ -54,7 +55,7 @@ describe 'km_send' do
|
|
54
55
|
it "should send from both query_log and query_log_old" do
|
55
56
|
File.open(__('log/kissmetrics_query.log'), 'w+') { |h| h.puts "/e?_t=1297105499&_n=Signup&_p=bob&_k=KM_KEY&age=27" }
|
56
57
|
File.open(__('log/kissmetrics_production_query.log'), 'w+') { |h| h.puts "/e?_t=1297105499&_n=Signup&_p=bob&_k=KM_KEY&age=26" }
|
57
|
-
`bundle exec km_send #{__('log/')} 127.0.0.1:9292`
|
58
|
+
`bundle exec km_send #{__('log/')} http://127.0.0.1:9292`
|
58
59
|
sleep 0.1
|
59
60
|
res = Helper.accept(:history).first.indifferent
|
60
61
|
res[:path].should == '/e'
|
@@ -64,7 +65,7 @@ describe 'km_send' do
|
|
64
65
|
res[:query]['_t'].first.should == '1297105499'
|
65
66
|
res[:query]['age'].first.should == '27'
|
66
67
|
Helper.clear
|
67
|
-
`bundle exec km_send #{__('log/')} 127.0.0.1:9292`
|
68
|
+
`bundle exec km_send #{__('log/')} http://127.0.0.1:9292`
|
68
69
|
sleep 0.1
|
69
70
|
res = Helper.accept(:history).first.indifferent
|
70
71
|
res[:path].should == '/e'
|
@@ -76,22 +77,23 @@ describe 'km_send' do
|
|
76
77
|
end
|
77
78
|
it "sends unless dryrun is specified" do
|
78
79
|
File.open(__('log/kissmetrics_alpha_query.log'), 'w+') { |h| h.puts "/e?_t=1297105499&_n=Signup&_p=bob&_k=KM_KEY&age=26" }
|
79
|
-
`bundle exec km_send -e alpha #{__('log/')} 127.0.0.1:9292`
|
80
|
+
`bundle exec km_send -e alpha #{__('log/')} http://127.0.0.1:9292`
|
80
81
|
sleep 0.1
|
81
82
|
res = Helper.accept(:history).first.should_not be_nil
|
82
83
|
end
|
83
84
|
end
|
84
85
|
it "should send from diff environment when force flag is used" do
|
85
|
-
KMTS::init 'KM_KEY', :log_dir => __('log'), :host => '127.0.0.1:9292', :use_cron => true, :env => 'development', :force => true
|
86
|
+
KMTS::init 'KM_KEY', :log_dir => __('log'), :host => 'http://127.0.0.1:9292', :use_cron => true, :env => 'development', :force => true
|
86
87
|
KMTS::record 'bob', 'Signup', 'age' => 26
|
87
|
-
`bundle exec km_send -f -e development #{__('log/')} 127.0.0.1:9292`
|
88
|
+
`bundle exec km_send -f -e development #{__('log/')} http://127.0.0.1:9292`
|
88
89
|
sleep 0.1
|
89
90
|
res = Helper.accept(:history).first.indifferent
|
90
91
|
res[:path].should == '/e'
|
91
92
|
res[:query]['_k'].first.should == 'KM_KEY'
|
92
93
|
res[:query]['_p'].first.should == 'bob'
|
93
94
|
res[:query]['_n'].first.should == 'Signup'
|
94
|
-
res[:query]['
|
95
|
+
res[:query]['_d'].first.should == '1'
|
96
|
+
res[:query]['_t'].first.to_i.should be_within(10.0).of(Time.now.to_i)
|
95
97
|
res[:query]['age'].first.should == '26'
|
96
98
|
end
|
97
99
|
end
|
data/spec/km_spec.rb
CHANGED
@@ -2,8 +2,6 @@ require 'setup'
|
|
2
2
|
describe KMTS do
|
3
3
|
before do
|
4
4
|
KMTS::reset
|
5
|
-
now = Time.now
|
6
|
-
Time.stub!(:now).and_return(now)
|
7
5
|
FileUtils.rm_f KMTS::log_name(:error)
|
8
6
|
FileUtils.rm_f KMTS::log_name(:query)
|
9
7
|
Helper.clear
|
@@ -19,7 +17,7 @@ describe KMTS do
|
|
19
17
|
end
|
20
18
|
|
21
19
|
it "shouldn't fail on alias without identifying" do
|
22
|
-
KMTS::init 'KM_OTHER', :log_dir => __('log'), :host => '127.0.0.1:9292'
|
20
|
+
KMTS::init 'KM_OTHER', :log_dir => __('log'), :host => 'http://127.0.0.1:9292'
|
23
21
|
KMTS::alias 'peter','joe' # Alias "bob" to "robert"
|
24
22
|
sleep 0.1
|
25
23
|
res = Helper.accept(:history).first.indifferent
|
@@ -27,11 +25,11 @@ describe KMTS do
|
|
27
25
|
res[:query]['_k'].first.should == 'KM_OTHER'
|
28
26
|
res[:query]['_p'].first.should == 'peter'
|
29
27
|
res[:query]['_n'].first.should == 'joe'
|
30
|
-
res[:query]['_t'].first.should
|
28
|
+
res[:query]['_t'].first.to_i.should be_within(2.0).of(Time.now.to_i)
|
31
29
|
end
|
32
30
|
|
33
31
|
it "shouldn't fail on alias without identifying from commandline" do
|
34
|
-
KMTS::init 'KM_OTHER', :log_dir => __('log'), :host => '127.0.0.1:9292'
|
32
|
+
KMTS::init 'KM_OTHER', :log_dir => __('log'), :host => 'http://127.0.0.1:9292'
|
35
33
|
KMTS::alias 'peter','joe' # Alias "bob" to "robert"
|
36
34
|
sleep 0.1
|
37
35
|
res = Helper.accept(:history).first.indifferent
|
@@ -39,12 +37,20 @@ describe KMTS do
|
|
39
37
|
res[:query]['_k'].first.should == 'KM_OTHER'
|
40
38
|
res[:query]['_p'].first.should == 'peter'
|
41
39
|
res[:query]['_n'].first.should == 'joe'
|
42
|
-
res[:query]['_t'].first.should
|
40
|
+
res[:query]['_t'].first.to_i.should be_within(2.0).of(Time.now.to_i)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should allow sending to https endpoints" do
|
44
|
+
lambda do
|
45
|
+
allow(KMTS).to receive(:log_error).and_raise('Error')
|
46
|
+
KMTS::init 'KM_OTHER', :log_dir => __('log'), :host => 'https://trk.kissmetrics.io/'
|
47
|
+
KMTS::record 'bob', 'My Action'
|
48
|
+
end.should_not raise_error
|
43
49
|
end
|
44
50
|
|
45
51
|
describe "should record events" do
|
46
52
|
before do
|
47
|
-
KMTS::init 'KM_KEY', :log_dir => __('log'), :host => '127.0.0.1:9292'
|
53
|
+
KMTS::init 'KM_KEY', :log_dir => __('log'), :host => 'http://127.0.0.1:9292'
|
48
54
|
end
|
49
55
|
it "records an action with no action-specific properties" do
|
50
56
|
KMTS::record 'bob', 'My Action'
|
@@ -54,7 +60,7 @@ describe KMTS do
|
|
54
60
|
res[:query]['_k'].first.should == 'KM_KEY'
|
55
61
|
res[:query]['_p'].first.should == 'bob'
|
56
62
|
res[:query]['_n'].first.should == 'My Action'
|
57
|
-
res[:query]['_t'].first.should
|
63
|
+
res[:query]['_t'].first.to_i.should be_within(2.0).of(Time.now.to_i)
|
58
64
|
end
|
59
65
|
it "records an action with properties" do
|
60
66
|
KMTS::record 'bob', 'Signup', 'age' => 26
|
@@ -64,7 +70,7 @@ describe KMTS do
|
|
64
70
|
res[:query]['_k'].first.should == 'KM_KEY'
|
65
71
|
res[:query]['_p'].first.should == 'bob'
|
66
72
|
res[:query]['_n'].first.should == 'Signup'
|
67
|
-
res[:query]['_t'].first.should
|
73
|
+
res[:query]['_t'].first.to_i.should be_within(2.0).of(Time.now.to_i)
|
68
74
|
res[:query]['age'].first.should == 26.to_s
|
69
75
|
end
|
70
76
|
it "should be able to hace spaces in key and value" do
|
@@ -75,7 +81,7 @@ describe KMTS do
|
|
75
81
|
res[:query]['_k'].first.should == 'KM_KEY'
|
76
82
|
res[:query]['_p'].first.should == 'bob'
|
77
83
|
res[:query]['_n'].first.should == 'Signup'
|
78
|
-
res[:query]['_t'].first.should
|
84
|
+
res[:query]['_t'].first.to_i.should be_within(2.0).of(Time.now.to_i)
|
79
85
|
res[:query]['age'].first.should == 26.to_s
|
80
86
|
res[:query]['city of residence'].first.should == 'eug ene'
|
81
87
|
end
|
@@ -87,7 +93,7 @@ describe KMTS do
|
|
87
93
|
res[:query]['_k'].first.should == 'KM_KEY'
|
88
94
|
res[:query]['_p'].first.should == 'bob'
|
89
95
|
res[:query]['_n'].first.should == 'Signup'
|
90
|
-
res[:query]['_t'].first.should
|
96
|
+
res[:query]['_t'].first.to_i.should be_within(2.0).of(Time.now.to_i)
|
91
97
|
res[:query]['age'].first.should == 26.to_s
|
92
98
|
end
|
93
99
|
it "should work with propps using @" do
|
@@ -97,7 +103,7 @@ describe KMTS do
|
|
97
103
|
res[:query]['_k'].first.should == 'KM_KEY'
|
98
104
|
res[:query]['_p'].first.should == 'bob'
|
99
105
|
res[:query]['_n'].first.should == 'Signup'
|
100
|
-
res[:query]['_t'].first.should
|
106
|
+
res[:query]['_t'].first.to_i.should be_within(2.0).of(Time.now.to_i)
|
101
107
|
res[:query]['email'].first.should == 'test@blah.com'
|
102
108
|
end
|
103
109
|
it "should just set properties without event" do
|
@@ -107,7 +113,7 @@ describe KMTS do
|
|
107
113
|
res[:path].should == '/s'
|
108
114
|
res[:query]['_k'].first.should == 'KM_KEY'
|
109
115
|
res[:query]['_p'].first.should == 'bob'
|
110
|
-
res[:query]['_t'].first.should
|
116
|
+
res[:query]['_t'].first.to_i.should be_within(2.0).of(Time.now.to_i)
|
111
117
|
res[:query]['age'].first.should == 26.to_s
|
112
118
|
end
|
113
119
|
it "should be able to use km set directly" do
|
@@ -117,7 +123,7 @@ describe KMTS do
|
|
117
123
|
res[:path].should == '/s'
|
118
124
|
res[:query]['_k'].first.should == 'KM_KEY'
|
119
125
|
res[:query]['_p'].first.should == 'bob'
|
120
|
-
res[:query]['_t'].first.should
|
126
|
+
res[:query]['_t'].first.to_i.should be_within(2.0).of(Time.now.to_i)
|
121
127
|
res[:query]['age'].first.should == 26.to_s
|
122
128
|
end
|
123
129
|
it "should work with multiple lines" do
|
@@ -131,13 +137,13 @@ describe KMTS do
|
|
131
137
|
res[:query]['_k'].first.should == 'KM_KEY'
|
132
138
|
res[:query]['_p'].first.should == 'bob'
|
133
139
|
res[:query]['_n'].first.should == 'Signup'
|
134
|
-
res[:query]['_t'].first.should
|
140
|
+
res[:query]['_t'].first.to_i.should be_within(2.0).of(Time.now.to_i)
|
135
141
|
res[:query]['age'].first.should == 26.to_s
|
136
142
|
res = Helper.accept(:history)[1].indifferent
|
137
143
|
res[:path].should == '/e'
|
138
144
|
res[:query]['_k'].first.should == 'KM_KEY'
|
139
145
|
res[:query]['_p'].first.should == 'bob'
|
140
|
-
res[:query]['_t'].first.should
|
146
|
+
res[:query]['_t'].first.to_i.should be_within(2.0).of(Time.now.to_i)
|
141
147
|
res[:query]['age'].first.should == 36.to_s
|
142
148
|
end
|
143
149
|
it "should not have key hardcoded anywhere" do
|
@@ -149,7 +155,35 @@ describe KMTS do
|
|
149
155
|
res[:query]['_k'].first.should == 'KM_OTHER'
|
150
156
|
res[:query]['_p'].first.should == 'truman'
|
151
157
|
res[:query]['_n'].first.should == 'harry'
|
152
|
-
res[:query]['_t'].first.should
|
158
|
+
res[:query]['_t'].first.to_i.should be_within(2.0).of(Time.now.to_i)
|
159
|
+
end
|
160
|
+
|
161
|
+
it "allows overriding of km_key" do
|
162
|
+
KMTS::init 'KM_OTHER', :log_dir => __('log'), :force_key => false
|
163
|
+
KMTS::record 'bob', 'Signup', 'age' => 36, '_k' => 'OTHER_KEY'
|
164
|
+
sleep 0.1
|
165
|
+
|
166
|
+
res = Helper.history.first.indifferent
|
167
|
+
res[:path].should == '/e'
|
168
|
+
res[:query]['_k'].first.should == 'OTHER_KEY'
|
169
|
+
res[:query]['_p'].first.should == 'bob'
|
170
|
+
res[:query]['_n'].first.should == 'Signup'
|
171
|
+
res[:query]['_t'].first.to_i.should be_within(2.0).of(Time.now.to_i)
|
172
|
+
res[:query]['age'].first.should == 36.to_s
|
173
|
+
end
|
174
|
+
|
175
|
+
it "uses default key when force_key is disabled" do
|
176
|
+
KMTS::init 'KM_OTHER', :log_dir => __('log'), :force_key => false
|
177
|
+
KMTS::record 'bob', 'Signup', 'age' => 36
|
178
|
+
sleep 0.1
|
179
|
+
|
180
|
+
res = Helper.history.first.indifferent
|
181
|
+
res[:path].should == '/e'
|
182
|
+
res[:query]['_k'].first.should == 'KM_OTHER'
|
183
|
+
res[:query]['_p'].first.should == 'bob'
|
184
|
+
res[:query]['_n'].first.should == 'Signup'
|
185
|
+
res[:query]['_t'].first.to_i.should be_within(2.0).of(Time.now.to_i)
|
186
|
+
res[:query]['age'].first.should == 36.to_s
|
153
187
|
end
|
154
188
|
end
|
155
189
|
context "reading from files" do
|
@@ -160,14 +194,14 @@ describe KMTS do
|
|
160
194
|
KMTS.reset
|
161
195
|
end
|
162
196
|
it "should run fine even though there's no server to connect to" do
|
163
|
-
KMTS::init 'KM_OTHER', :log_dir => __('log'), :host => '127.0.0.1:9291', :to_stderr => false
|
197
|
+
KMTS::init 'KM_OTHER', :log_dir => __('log'), :host => '127.0.0.1:9291', :to_stderr => false, :env => 'production'
|
164
198
|
KMTS::record 'bob', 'My Action' # records an action with no action-specific properties;
|
165
199
|
Helper.accept(:history).size.should == 0
|
166
200
|
File.exists?(__('log/kissmetrics_production_query.log')).should == true
|
167
201
|
File.exists?(__('log/kissmetrics_production_error.log')).should == true
|
168
202
|
end
|
169
203
|
it "should escape @ properly" do
|
170
|
-
KMTS::init 'KM_OTHER', :log_dir => __('log'), :host => '127.0.0.1:9292', :to_stderr => false, :use_cron => true
|
204
|
+
KMTS::init 'KM_OTHER', :log_dir => __('log'), :host => 'http://127.0.0.1:9292', :to_stderr => false, :use_cron => true
|
171
205
|
KMTS::record 'bob', 'prop_with_@_in' # records an action with no action-specific properties;
|
172
206
|
IO.readlines(KMTS::log_name(:query)).join.should_not contain_string('@')
|
173
207
|
end
|
data/spec/setup.rb
CHANGED
@@ -17,7 +17,7 @@ end
|
|
17
17
|
|
18
18
|
class Helper
|
19
19
|
def self.accept(cmd)
|
20
|
-
c = TCPSocket.new('
|
20
|
+
c = TCPSocket.new('127.0.0.1', 9292)
|
21
21
|
c.puts cmd.to_s
|
22
22
|
return JSON.parse(c.read) rescue nil
|
23
23
|
end
|
@@ -75,3 +75,7 @@ def write_log(type, content)
|
|
75
75
|
end
|
76
76
|
|
77
77
|
accept = Accept.new
|
78
|
+
|
79
|
+
RSpec.configure do |config|
|
80
|
+
config.expect_with(:rspec) { |c| c.syntax = :should }
|
81
|
+
end
|
metadata
CHANGED
@@ -1,86 +1,87 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kmts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Kissmetrics
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: '1.13'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: '1.13'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '3.5'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '3.5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '12.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
|
-
version: '0'
|
54
|
+
version: '12.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: json
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
61
|
+
version: '2.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
description:
|
68
|
+
version: '2.0'
|
69
|
+
description: A threadsafe Ruby gem that can be used to interact with the Kissmetrics
|
70
|
+
tracking API.
|
70
71
|
email:
|
71
|
-
- support@kissmetrics.
|
72
|
+
- support@kissmetrics.io
|
72
73
|
executables:
|
73
74
|
- km_send
|
74
75
|
extensions: []
|
75
76
|
extra_rdoc_files: []
|
76
77
|
files:
|
77
|
-
- .gitignore
|
78
|
+
- ".gitignore"
|
79
|
+
- ".travis.yml"
|
78
80
|
- CHANGELOG
|
79
81
|
- Gemfile
|
80
82
|
- Gemfile.lock
|
81
83
|
- LICENSE
|
82
84
|
- README.md
|
83
|
-
- README.rdoc
|
84
85
|
- Rakefile
|
85
86
|
- bin/km_send
|
86
87
|
- doc/Accept.html
|
@@ -147,7 +148,8 @@ files:
|
|
147
148
|
- spec/setup.rb
|
148
149
|
- spec/watchr.rb
|
149
150
|
homepage: https://github.com/kissmetrics/kmts
|
150
|
-
licenses:
|
151
|
+
licenses:
|
152
|
+
- Apache-2.0
|
151
153
|
metadata: {}
|
152
154
|
post_install_message:
|
153
155
|
rdoc_options: []
|
@@ -155,20 +157,19 @@ require_paths:
|
|
155
157
|
- lib
|
156
158
|
required_ruby_version: !ruby/object:Gem::Requirement
|
157
159
|
requirements:
|
158
|
-
- -
|
160
|
+
- - ">="
|
159
161
|
- !ruby/object:Gem::Version
|
160
162
|
version: '0'
|
161
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
164
|
requirements:
|
163
|
-
- -
|
165
|
+
- - ">="
|
164
166
|
- !ruby/object:Gem::Version
|
165
167
|
version: 1.3.6
|
166
168
|
requirements: []
|
167
|
-
|
168
|
-
rubygems_version: 2.0.3
|
169
|
+
rubygems_version: 3.0.3
|
169
170
|
signing_key:
|
170
171
|
specification_version: 4
|
171
|
-
summary:
|
172
|
+
summary: Threadsafe Ruby gem for Kissmetrics tracking API
|
172
173
|
test_files:
|
173
174
|
- spec/accept.rb
|
174
175
|
- spec/km_old.rb
|
data/README.rdoc
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
= Documentation
|
2
|
-
|
3
|
-
We are hosting our documentation for our Ruby API here: http://support.kissmetrics.com/apis/ruby
|
4
|
-
|
5
|
-
= Installation
|
6
|
-
|
7
|
-
gem install kmts
|
8
|
-
|
9
|
-
= SaaS
|
10
|
-
|
11
|
-
This gem includes SaaS calls. For more information please refer to:
|
12
|
-
http://support.kissmetrics.com/getting-started/saas_basics
|
13
|
-
|
14
|
-
For the methods used, see the {rdoc for SaaS}[link:KMTS/SaaS.html]
|