kmts 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/lib/kmts.rb +10 -1
- data/lib/kmts/version.rb +1 -1
- data/spec/km_spec.rb +28 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d062019c23e872496154215188aa3303a540f16d
|
4
|
+
data.tar.gz: d0ac18313b30ebada5046e7f391e66b2cb21b41c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 543a825b9ab4943ff00682fac683d48d9f8bd2e510d9a72de30857db9e23544ad5d5d7fc0b007ef3a42a7afc41250ebeb0fc63ff4988e2aac3d6acc4d1402508
|
7
|
+
data.tar.gz: d94347a16e24ba5f6370cae4629f38ce68f117f42d8718e53acaf4ad0795f75d2a6f8f878b6e2040331d341b41760300ffd561d83f1b81c0a42af87bb69018ff
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -35,6 +35,7 @@ The available options are:
|
|
35
35
|
* `to_stderr`: allows toggling of printing output to `stderr`. Default is `true`.
|
36
36
|
* `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
37
|
* `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`.
|
38
|
+
* `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
39
|
|
39
40
|
### Sample:
|
40
41
|
|
data/lib/kmts.rb
CHANGED
@@ -17,6 +17,7 @@ class KMTS
|
|
17
17
|
@to_stderr = true
|
18
18
|
@use_cron = true
|
19
19
|
@dryrun = false
|
20
|
+
@force_key = true
|
20
21
|
|
21
22
|
class << self
|
22
23
|
class IdentError < StandardError; end
|
@@ -30,6 +31,7 @@ class KMTS
|
|
30
31
|
:use_cron => @use_cron,
|
31
32
|
:dryrun => @dryrun,
|
32
33
|
:env => set_env,
|
34
|
+
:force_key => @force_key
|
33
35
|
}
|
34
36
|
options = default.merge(options)
|
35
37
|
|
@@ -41,6 +43,7 @@ class KMTS
|
|
41
43
|
@to_stderr = options[:to_stderr]
|
42
44
|
@dryrun = options[:dryrun]
|
43
45
|
@env = options[:env]
|
46
|
+
@force_key = options[:force_key]
|
44
47
|
log_dir_writable?
|
45
48
|
rescue Exception => e
|
46
49
|
log_error(e)
|
@@ -130,6 +133,7 @@ class KMTS
|
|
130
133
|
@use_cron = false
|
131
134
|
@env = nil
|
132
135
|
@force = false
|
136
|
+
@force_key = true
|
133
137
|
end
|
134
138
|
|
135
139
|
def log_name(type)
|
@@ -191,10 +195,15 @@ class KMTS
|
|
191
195
|
query_arr = []
|
192
196
|
query = ''
|
193
197
|
data.update('_p' => id) if id
|
194
|
-
data.update('_k' => @key)
|
195
198
|
data.update '_d' => 1 if data['_t'] || @use_cron
|
196
199
|
data['_t'] ||= Time.now.to_i
|
197
200
|
|
201
|
+
if @force_key
|
202
|
+
data['_k'] = @key
|
203
|
+
else
|
204
|
+
data['_k'] ||= @key
|
205
|
+
end
|
206
|
+
|
198
207
|
unsafe = Regexp.new("[^#{URI::REGEXP::PATTERN::UNRESERVED}]", false, 'N')
|
199
208
|
|
200
209
|
data.inject(query) do |query,key_val|
|
data/lib/kmts/version.rb
CHANGED
data/spec/km_spec.rb
CHANGED
@@ -157,6 +157,34 @@ describe KMTS do
|
|
157
157
|
res[:query]['_n'].first.should == 'harry'
|
158
158
|
res[:query]['_t'].first.to_i.should be_within(2.0).of(Time.now.to_i)
|
159
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
|
187
|
+
end
|
160
188
|
end
|
161
189
|
context "reading from files" do
|
162
190
|
before do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kmts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kissmetrics
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|