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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 461172f5701b7d8840f666b3131bac59f8ea42ac
4
- data.tar.gz: dc35083fbcc97e01fd7aaace188202a7e3d4af06
3
+ metadata.gz: d062019c23e872496154215188aa3303a540f16d
4
+ data.tar.gz: d0ac18313b30ebada5046e7f391e66b2cb21b41c
5
5
  SHA512:
6
- metadata.gz: 1cf189936af9fc333ce783aeb05225f4d9bb4ebbeeafaab6c1a05891750ca76846729e87b25940a228cab5d106bf5db7847420d745b97b96f1cefe9594530547
7
- data.tar.gz: 66f001d5e5f7e667f9590f6454ef1e71d6da62ec2b5b1ba60fc2eb4918609b5da6b9c9c0fb45d178eeadb6cca953b77c0f17f34bbdc9bfa804b41546094423e6
6
+ metadata.gz: 543a825b9ab4943ff00682fac683d48d9f8bd2e510d9a72de30857db9e23544ad5d5d7fc0b007ef3a42a7afc41250ebeb0fc63ff4988e2aac3d6acc4d1402508
7
+ data.tar.gz: d94347a16e24ba5f6370cae4629f38ce68f117f42d8718e53acaf4ad0795f75d2a6f8f878b6e2040331d341b41760300ffd561d83f1b81c0a42af87bb69018ff
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kmts (3.0.0)
4
+ kmts (3.0.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
 
@@ -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|
@@ -1,3 +1,3 @@
1
1
  class KMTS
2
- VERSION = "3.0.0"
2
+ VERSION = "3.0.1"
3
3
  end
@@ -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.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-04 00:00:00.000000000 Z
11
+ date: 2017-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler