kmts 2.0.1 → 3.0.0

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: b7fac5bf794804436935e08acc69e9e5795378d0
4
- data.tar.gz: d8b375322632f2cbf62136b62cbaaea04db4d78a
3
+ metadata.gz: 461172f5701b7d8840f666b3131bac59f8ea42ac
4
+ data.tar.gz: dc35083fbcc97e01fd7aaace188202a7e3d4af06
5
5
  SHA512:
6
- metadata.gz: 9c06978b76f29e4eb415ca27923762578698f34ad95752e7c28491a252808f94caf58d5b31bb03dc467f4e2062342fd1f48d2cb014bf11f1b4bade21f661a089
7
- data.tar.gz: 876e7fbcb0fab76dd6b333d047b7b9d7fdd4db8e7f1bbfa846ddf504e8a53d2e2feea59b139bb5285a2165a91b5a499f297b063fdcd4b9bb008e9b2463751267
6
+ metadata.gz: 1cf189936af9fc333ce783aeb05225f4d9bb4ebbeeafaab6c1a05891750ca76846729e87b25940a228cab5d106bf5db7847420d745b97b96f1cefe9594530547
7
+ data.tar.gz: 66f001d5e5f7e667f9590f6454ef1e71d6da62ec2b5b1ba60fc2eb4918609b5da6b9c9c0fb45d178eeadb6cca953b77c0f17f34bbdc9bfa804b41546094423e6
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ - 2.2
5
+ - 2.1
6
+ - 2.0
7
+ cache:
8
+ bundler: true
9
+ sudo: false
@@ -1,29 +1,37 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kmts (2.0.1)
4
+ kmts (3.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- diff-lcs (1.1.2)
10
- json (1.5.1)
11
- rake (0.8.7)
12
- rspec (2.4.0)
13
- rspec-core (~> 2.4.0)
14
- rspec-expectations (~> 2.4.0)
15
- rspec-mocks (~> 2.4.0)
16
- rspec-core (2.4.0)
17
- rspec-expectations (2.4.0)
18
- diff-lcs (~> 1.1.2)
19
- rspec-mocks (2.4.0)
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 (>= 1.0.0)
26
- json
30
+ bundler (~> 1.13)
31
+ json (~> 2.0)
27
32
  kmts!
28
- rake
29
- rspec (~> 2.4.0)
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
- ## KISSmetrics Threadsafe Ruby library
1
+ ## Kissmetrics Threadsafe Ruby library
2
2
 
3
3
  This gem is a threadsafe fork of the original `km` gem.
4
4
 
@@ -11,7 +11,7 @@ Version 1.0.2 of the `kmts` gem had an issue where it was found to not actually
11
11
  The best way to install the gem is using `gem install kmts` or by adding it to your `Gemfile`:
12
12
 
13
13
  ```ruby
14
- gem 'kmts', '~> 2.0.0'
14
+ gem 'kmts', '~> 3.0.0'
15
15
  ```
16
16
 
17
17
  Otherwise, the gem is available on GitHub:
@@ -31,9 +31,9 @@ KMTS.init('KM_KEY' [, options])
31
31
  The available options are:
32
32
 
33
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.com` URLs - please refer to [API Specifications](http://support.kissmetrics.com/apis/specifications.html).
34
- * `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). Default is `false`, which means data is sent directly to KISSmetrics. Using cron is optional, but **recommended**.
34
+ * `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
35
  * `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 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.
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
38
 
39
39
  ### Sample:
@@ -56,7 +56,7 @@ KMTS.alias('bob', 'bob@bob.com')
56
56
 
57
57
  ## Troubleshooting
58
58
 
59
- If you were watching for the events in [KISSmetrics Live](http://support.kissmetrics.com/tools/live) and did not see them, it helps to review what our library logged. In the log directory, you may see these files:
59
+ If you were watching for the events in [Kissmetrics Live](http://support.kissmetrics.com/tools/live) and did not see them, it helps to review what our library logged. In the log directory, you may see these files:
60
60
 
61
61
  * `kissmetrics_production_sent.log`
62
62
  * `kissmetrics_production_query.log`
data/Rakefile CHANGED
@@ -1,5 +1,10 @@
1
1
  require 'bundler'
2
- require 'rspec/core/rake_task'
3
2
  Bundler::GemHelper.install_tasks
4
3
 
5
- RSpec::Core::RakeTask.new(:spec)
4
+ begin
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ rescue LoadError
8
+ end
9
+
10
+ task default: 'spec'
@@ -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.authors = ["KISSmetrics"]
8
+ s.license = "Apache-2.0"
9
+ s.authors = ["Kissmetrics"]
9
10
  s.email = ["support@kissmetrics.com"]
10
11
  s.homepage = "https://github.com/kissmetrics/kmts"
11
- s.summary = "KISSmetrics threadsafe ruby API gem"
12
- s.description = "KISSmetrics threadsafe ruby API gem"
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", ">= 1.0.0"
18
- s.add_development_dependency "rspec", "~> 2.4.0"
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")
@@ -7,12 +7,15 @@ require 'kmts/saas'
7
7
  class KMError < StandardError; end
8
8
 
9
9
  class KMTS
10
+ DEFAULT_TRACKING_SERVER = 'https://trk.kissmetrics.com'.freeze
11
+ PROTOCOL_MATCHER = %r(://)
12
+
10
13
  @key = nil
11
14
  @logs = {}
12
- @host = 'trk.kissmetrics.com:80'
15
+ @host = DEFAULT_TRACKING_SERVER
13
16
  @log_dir = '/tmp'
14
17
  @to_stderr = true
15
- @use_cron = false
18
+ @use_cron = true
16
19
  @dryrun = false
17
20
 
18
21
  class << self
@@ -121,7 +124,7 @@ class KMTS
121
124
  @id = nil
122
125
  @key = nil
123
126
  @logs = {}
124
- @host = 'trk.kissmetrics.com:80'
127
+ @host = DEFAULT_TRACKING_SERVER
125
128
  @log_dir = '/tmp'
126
129
  @to_stderr = true
127
130
  @use_cron = false
@@ -189,11 +192,11 @@ class KMTS
189
192
  query = ''
190
193
  data.update('_p' => id) if id
191
194
  data.update('_k' => @key)
192
- data.update '_d' => 1 if data['_t']
195
+ data.update '_d' => 1 if data['_t'] || @use_cron
193
196
  data['_t'] ||= Time.now.to_i
194
-
197
+
195
198
  unsafe = Regexp.new("[^#{URI::REGEXP::PATTERN::UNRESERVED}]", false, 'N')
196
-
199
+
197
200
  data.inject(query) do |query,key_val|
198
201
  query_arr << key_val.collect { |i| URI.escape(i.to_s, unsafe) }.join('=')
199
202
  end
@@ -215,11 +218,13 @@ class KMTS
215
218
  log_sent(line)
216
219
  else
217
220
  begin
218
- host,port = @host.split(':')
219
- proxy = URI.parse(ENV['http_proxy'] || ENV['HTTP_PROXY'] || '')
220
- res = Net::HTTP::Proxy(proxy.host, proxy.port, proxy.user, proxy.password).start(host, port) do |http|
221
- http.get(line)
222
- end
221
+ host = @host
222
+ host = "http://#{host}" unless host =~ PROTOCOL_MATCHER
223
+ uri = URI.parse(host)
224
+
225
+ http = Net::HTTP.new(uri.host, uri.port)
226
+ http.use_ssl = uri.is_a?(URI::HTTPS)
227
+ http.get(line)
223
228
  rescue Exception => e
224
229
  raise KMError.new("#{e} for host #{@host}")
225
230
  end
@@ -1,3 +1,3 @@
1
1
  class KMTS
2
- VERSION = "2.0.1"
2
+ VERSION = "3.0.0"
3
3
  end
@@ -17,7 +17,7 @@ class Accept
17
17
 
18
18
  puts "Starting up server on port #{opts[:port]} ..."
19
19
  @opts = opts
20
- @server = TCPServer.new(opts[:port])
20
+ @server = TCPServer.new('127.0.0.1', opts[:port])
21
21
  @@input_history = []
22
22
  @handle = Thread.start do
23
23
  loop do
@@ -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'
@@ -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
@@ -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]['_t'].first.should == Time.now.to_i.to_s
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]['_t'].first.should == Time.now.to_i.to_s
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
@@ -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 == Time.now.to_i.to_s
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 == Time.now.to_i.to_s
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.com/'
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 == Time.now.to_i.to_s
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 == Time.now.to_i.to_s
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 == Time.now.to_i.to_s
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 == Time.now.to_i.to_s
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 == Time.now.to_i.to_s
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 == Time.now.to_i.to_s
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 == Time.now.to_i.to_s
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 == Time.now.to_i.to_s
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 == Time.now.to_i.to_s
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,7 @@ 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 == Time.now.to_i.to_s
158
+ res[:query]['_t'].first.to_i.should be_within(2.0).of(Time.now.to_i)
153
159
  end
154
160
  end
155
161
  context "reading from files" do
@@ -160,14 +166,14 @@ describe KMTS do
160
166
  KMTS.reset
161
167
  end
162
168
  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
169
+ KMTS::init 'KM_OTHER', :log_dir => __('log'), :host => '127.0.0.1:9291', :to_stderr => false, :env => 'production'
164
170
  KMTS::record 'bob', 'My Action' # records an action with no action-specific properties;
165
171
  Helper.accept(:history).size.should == 0
166
172
  File.exists?(__('log/kissmetrics_production_query.log')).should == true
167
173
  File.exists?(__('log/kissmetrics_production_error.log')).should == true
168
174
  end
169
175
  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
176
+ KMTS::init 'KM_OTHER', :log_dir => __('log'), :host => 'http://127.0.0.1:9292', :to_stderr => false, :use_cron => true
171
177
  KMTS::record 'bob', 'prop_with_@_in' # records an action with no action-specific properties;
172
178
  IO.readlines(KMTS::log_name(:query)).join.should_not contain_string('@')
173
179
  end
@@ -17,7 +17,7 @@ end
17
17
 
18
18
  class Helper
19
19
  def self.accept(cmd)
20
- c = TCPSocket.new('localhost', 9292)
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,72 +1,73 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kmts
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - KISSmetrics
7
+ - Kissmetrics
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-08 00:00:00.000000000 Z
11
+ date: 2017-01-04 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.0.0
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.0.0
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: 2.4.0
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: 2.4.0
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: KISSmetrics threadsafe ruby API gem
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
72
  - support@kissmetrics.com
72
73
  executables:
@@ -74,13 +75,13 @@ executables:
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,20 @@ 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
169
  rubyforge_project: kissmetrics
168
- rubygems_version: 2.0.3
170
+ rubygems_version: 2.5.1
169
171
  signing_key:
170
172
  specification_version: 4
171
- summary: KISSmetrics threadsafe ruby API gem
173
+ summary: Threadsafe Ruby gem for Kissmetrics tracking API
172
174
  test_files:
173
175
  - spec/accept.rb
174
176
  - spec/km_old.rb
@@ -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]