km 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/bin/km_send +9 -2
- data/lib/km.rb +23 -18
- data/lib/km/version.rb +1 -1
- data/spec/km_send_spec.rb +74 -56
- data/spec/km_spec.rb +0 -1
- metadata +79 -80
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/bin/km_send
CHANGED
@@ -4,11 +4,17 @@ require 'optparse'
|
|
4
4
|
require 'km'
|
5
5
|
|
6
6
|
env = 'production'
|
7
|
+
force = false
|
7
8
|
begin
|
8
9
|
parser = OptionParser.new()
|
9
10
|
parser.banner = "#{File.basename($0)} [<log_dir>]\n\n"
|
11
|
+
|
12
|
+
parser.on("-f", "--force", "Force sending the data to KM, ignoring the environment.") do |e|
|
13
|
+
force = true
|
14
|
+
end
|
15
|
+
|
10
16
|
parser.on("-e", "--env ENVIRONMENT", "The environment to run in. Default: production") do |e|
|
11
|
-
puts "Note, only production will actually send queries to the kissmetrics servers."
|
17
|
+
puts "Note, only production will actually send queries to the kissmetrics servers unless the --force flag is used." unless force
|
12
18
|
env = e
|
13
19
|
end
|
14
20
|
|
@@ -24,5 +30,6 @@ rescue => e
|
|
24
30
|
exit(-1)
|
25
31
|
end
|
26
32
|
|
27
|
-
|
33
|
+
|
34
|
+
KM.init('', :log_dir => opts[0] || KM.log_dir, :host => opts[1] || KM.host, :force => force, :env => env)
|
28
35
|
KM.send_logged_queries
|
data/lib/km.rb
CHANGED
@@ -14,6 +14,7 @@ class KM
|
|
14
14
|
@log_dir = '/tmp'
|
15
15
|
@to_stderr = true
|
16
16
|
@use_cron = false
|
17
|
+
@dryrun = false
|
17
18
|
|
18
19
|
class << self
|
19
20
|
class IdentError < StandardError; end
|
@@ -25,6 +26,7 @@ class KM
|
|
25
26
|
:log_dir => @log_dir,
|
26
27
|
:to_stderr => @to_stderr,
|
27
28
|
:use_cron => @use_cron,
|
29
|
+
:dryrun => @dryrun,
|
28
30
|
:env => set_env,
|
29
31
|
}
|
30
32
|
options = default.merge(options)
|
@@ -35,6 +37,7 @@ class KM
|
|
35
37
|
@log_dir = options[:log_dir]
|
36
38
|
@use_cron = options[:use_cron]
|
37
39
|
@to_stderr = options[:to_stderr]
|
40
|
+
@dryrun = options[:dryrun]
|
38
41
|
@env = options[:env]
|
39
42
|
log_dir_writable?
|
40
43
|
rescue Exception => e
|
@@ -120,13 +123,15 @@ class KM
|
|
120
123
|
Hash[*hash.map { |k,v| k.class == Symbol ? [k.to_s,v] : [k,v] }.flatten] # convert all keys to strings
|
121
124
|
end
|
122
125
|
def reset
|
123
|
-
@id
|
124
|
-
@key
|
125
|
-
@logs
|
126
|
-
@host
|
127
|
-
@log_dir
|
128
|
-
@to_stderr
|
129
|
-
@use_cron
|
126
|
+
@id = nil
|
127
|
+
@key = nil
|
128
|
+
@logs = {}
|
129
|
+
@host = 'trk.kissmetrics.com:80'
|
130
|
+
@log_dir = '/tmp'
|
131
|
+
@to_stderr = true
|
132
|
+
@use_cron = false
|
133
|
+
@env = nil
|
134
|
+
@force = false
|
130
135
|
end
|
131
136
|
|
132
137
|
def log_name(type)
|
@@ -210,20 +215,20 @@ class KM
|
|
210
215
|
end
|
211
216
|
|
212
217
|
def send_query(line)
|
213
|
-
if @
|
218
|
+
if @dryrun
|
214
219
|
log_sent(line)
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
220
|
+
else
|
221
|
+
begin
|
222
|
+
host,port = @host.split(':')
|
223
|
+
proxy = URI.parse(ENV['http_proxy'] || ENV['HTTP_PROXY'] || '')
|
224
|
+
res = Net::HTTP::Proxy(proxy.host, proxy.port, proxy.user, proxy.password).start(host, port) do |http|
|
225
|
+
http.get(line)
|
226
|
+
end
|
227
|
+
rescue Exception => e
|
228
|
+
raise KMError.new("#{e} for host #{@host}")
|
222
229
|
end
|
223
|
-
|
224
|
-
raise KMError.new("#{e} for host #{@host}")
|
230
|
+
log_sent(line)
|
225
231
|
end
|
226
|
-
log_sent(line)
|
227
232
|
end
|
228
233
|
|
229
234
|
def log_dir_writable?
|
data/lib/km/version.rb
CHANGED
data/spec/km_send_spec.rb
CHANGED
@@ -11,11 +11,82 @@ describe 'km_send' do
|
|
11
11
|
KM.reset
|
12
12
|
Helper.clear
|
13
13
|
end
|
14
|
-
|
15
|
-
|
14
|
+
context "with default environment" do
|
15
|
+
before do
|
16
|
+
KM::init 'KM_KEY', :log_dir => __('log'), :host => '127.0.0.1:9292', :use_cron => true
|
17
|
+
end
|
18
|
+
it "should test commandline version" do
|
19
|
+
KM::identify 'bob'
|
20
|
+
KM::record 'Signup', 'age' => 26
|
21
|
+
`bundle exec km_send #{__('log/')} 127.0.0.1:9292`
|
22
|
+
sleep 0.1
|
23
|
+
res = Helper.accept(:history).first.indifferent
|
24
|
+
res[:path].should == '/e'
|
25
|
+
res[:query]['_k'].first.should == 'KM_KEY'
|
26
|
+
res[:query]['_p'].first.should == 'bob'
|
27
|
+
res[:query]['_n'].first.should == 'Signup'
|
28
|
+
res[:query]['_t'].first.should == Time.now.to_i.to_s
|
29
|
+
res[:query]['age'].first.should == '26'
|
30
|
+
end
|
31
|
+
it "should send from query_log" do
|
32
|
+
write_log :query, "/e?_t=1297105499&_n=Signup&_p=bob&_k=KM_KEY&age=26"
|
33
|
+
`bundle exec km_send #{__('log/')} 127.0.0.1:9292`
|
34
|
+
sleep 0.1
|
35
|
+
res = Helper.accept(:history).first.indifferent
|
36
|
+
res[:path].should == '/e'
|
37
|
+
res[:query]['_k'].first.should == 'KM_KEY'
|
38
|
+
res[:query]['_p'].first.should == 'bob'
|
39
|
+
res[:query]['_n'].first.should == 'Signup'
|
40
|
+
res[:query]['_t'].first.should == '1297105499'
|
41
|
+
res[:query]['age'].first.should == '26'
|
42
|
+
end
|
43
|
+
it "should send from query_log_old" do
|
44
|
+
write_log :query_old, "/e?_t=1297105499&_n=Signup&_p=bob&_k=KM_KEY&age=26"
|
45
|
+
`bundle exec km_send #{__('log/')} 127.0.0.1:9292`
|
46
|
+
sleep 0.1
|
47
|
+
res = Helper.accept(:history).first.indifferent
|
48
|
+
res[:path].should == '/e'
|
49
|
+
res[:query]['_k'].first.should == 'KM_KEY'
|
50
|
+
res[:query]['_p'].first.should == 'bob'
|
51
|
+
res[:query]['_n'].first.should == 'Signup'
|
52
|
+
res[:query]['_t'].first.should == '1297105499'
|
53
|
+
res[:query]['age'].first.should == '26'
|
54
|
+
end
|
55
|
+
it "should send from both query_log and query_log_old" do
|
56
|
+
File.open(__('log/kissmetrics_query.log'), 'w+') { |h| h.puts "/e?_t=1297105499&_n=Signup&_p=bob&_k=KM_KEY&age=27" }
|
57
|
+
File.open(__('log/kissmetrics_production_query.log'), 'w+') { |h| h.puts "/e?_t=1297105499&_n=Signup&_p=bob&_k=KM_KEY&age=26" }
|
58
|
+
`bundle exec km_send #{__('log/')} 127.0.0.1:9292`
|
59
|
+
sleep 0.1
|
60
|
+
res = Helper.accept(:history).first.indifferent
|
61
|
+
res[:path].should == '/e'
|
62
|
+
res[:query]['_k'].first.should == 'KM_KEY'
|
63
|
+
res[:query]['_p'].first.should == 'bob'
|
64
|
+
res[:query]['_n'].first.should == 'Signup'
|
65
|
+
res[:query]['_t'].first.should == '1297105499'
|
66
|
+
res[:query]['age'].first.should == '27'
|
67
|
+
Helper.clear
|
68
|
+
`bundle exec km_send #{__('log/')} 127.0.0.1:9292`
|
69
|
+
sleep 0.1
|
70
|
+
res = Helper.accept(:history).first.indifferent
|
71
|
+
res[:path].should == '/e'
|
72
|
+
res[:query]['_k'].first.should == 'KM_KEY'
|
73
|
+
res[:query]['_p'].first.should == 'bob'
|
74
|
+
res[:query]['_n'].first.should == 'Signup'
|
75
|
+
res[:query]['_t'].first.should == '1297105499'
|
76
|
+
res[:query]['age'].first.should == '26'
|
77
|
+
end
|
78
|
+
it "sends unless dryrun is specified" do
|
79
|
+
File.open(__('log/kissmetrics_alpha_query.log'), 'w+') { |h| h.puts "/e?_t=1297105499&_n=Signup&_p=bob&_k=KM_KEY&age=26" }
|
80
|
+
`bundle exec km_send -e alpha #{__('log/')} 127.0.0.1:9292`
|
81
|
+
sleep 0.1
|
82
|
+
res = Helper.accept(:history).first.should_not be_nil
|
83
|
+
end
|
84
|
+
end
|
85
|
+
it "should send from diff environment when force flag is used" do
|
86
|
+
KM::init 'KM_KEY', :log_dir => __('log'), :host => '127.0.0.1:9292', :use_cron => true, :env => 'development', :force => true
|
16
87
|
KM::identify 'bob'
|
17
88
|
KM::record 'Signup', 'age' => 26
|
18
|
-
`bundle exec km_send #{__('log/')} 127.0.0.1:9292`
|
89
|
+
`bundle exec km_send -f -e development #{__('log/')} 127.0.0.1:9292`
|
19
90
|
sleep 0.1
|
20
91
|
res = Helper.accept(:history).first.indifferent
|
21
92
|
res[:path].should == '/e'
|
@@ -25,58 +96,5 @@ describe 'km_send' do
|
|
25
96
|
res[:query]['_t'].first.should == Time.now.to_i.to_s
|
26
97
|
res[:query]['age'].first.should == '26'
|
27
98
|
end
|
28
|
-
it "should send from query_log" do
|
29
|
-
write_log :query, "/e?_t=1297105499&_n=Signup&_p=bob&_k=KM_KEY&age=26"
|
30
|
-
`bundle exec km_send #{__('log/')} 127.0.0.1:9292`
|
31
|
-
sleep 0.1
|
32
|
-
res = Helper.accept(:history).first.indifferent
|
33
|
-
res[:path].should == '/e'
|
34
|
-
res[:query]['_k'].first.should == 'KM_KEY'
|
35
|
-
res[:query]['_p'].first.should == 'bob'
|
36
|
-
res[:query]['_n'].first.should == 'Signup'
|
37
|
-
res[:query]['_t'].first.should == '1297105499'
|
38
|
-
res[:query]['age'].first.should == '26'
|
39
|
-
end
|
40
|
-
it "should send from query_log_old" do
|
41
|
-
write_log :query_old, "/e?_t=1297105499&_n=Signup&_p=bob&_k=KM_KEY&age=26"
|
42
|
-
`bundle exec km_send #{__('log/')} 127.0.0.1:9292`
|
43
|
-
sleep 0.1
|
44
|
-
res = Helper.accept(:history).first.indifferent
|
45
|
-
res[:path].should == '/e'
|
46
|
-
res[:query]['_k'].first.should == 'KM_KEY'
|
47
|
-
res[:query]['_p'].first.should == 'bob'
|
48
|
-
res[:query]['_n'].first.should == 'Signup'
|
49
|
-
res[:query]['_t'].first.should == '1297105499'
|
50
|
-
res[:query]['age'].first.should == '26'
|
51
|
-
end
|
52
|
-
it "should send from both query_log and query_log_old" do
|
53
|
-
File.open(__('log/kissmetrics_query.log'), 'w+') { |h| h.puts "/e?_t=1297105499&_n=Signup&_p=bob&_k=KM_KEY&age=27" }
|
54
|
-
File.open(__('log/kissmetrics_production_query.log'), 'w+') { |h| h.puts "/e?_t=1297105499&_n=Signup&_p=bob&_k=KM_KEY&age=26" }
|
55
|
-
`bundle exec km_send #{__('log/')} 127.0.0.1:9292`
|
56
|
-
sleep 0.1
|
57
|
-
res = Helper.accept(:history).first.indifferent
|
58
|
-
res[:path].should == '/e'
|
59
|
-
res[:query]['_k'].first.should == 'KM_KEY'
|
60
|
-
res[:query]['_p'].first.should == 'bob'
|
61
|
-
res[:query]['_n'].first.should == 'Signup'
|
62
|
-
res[:query]['_t'].first.should == '1297105499'
|
63
|
-
res[:query]['age'].first.should == '27'
|
64
|
-
Helper.clear
|
65
|
-
`bundle exec km_send #{__('log/')} 127.0.0.1:9292`
|
66
|
-
sleep 0.1
|
67
|
-
res = Helper.accept(:history).first.indifferent
|
68
|
-
res[:path].should == '/e'
|
69
|
-
res[:query]['_k'].first.should == 'KM_KEY'
|
70
|
-
res[:query]['_p'].first.should == 'bob'
|
71
|
-
res[:query]['_n'].first.should == 'Signup'
|
72
|
-
res[:query]['_t'].first.should == '1297105499'
|
73
|
-
res[:query]['age'].first.should == '26'
|
74
|
-
end
|
75
|
-
it "should not send from diff environment as we only send when env is production" do
|
76
|
-
File.open(__('log/kissmetrics_alpha_query.log'), 'w+') { |h| h.puts "/e?_t=1297105499&_n=Signup&_p=bob&_k=KM_KEY&age=26" }
|
77
|
-
`bundle exec km_send -e alpha #{__('log/')} 127.0.0.1:9292`
|
78
|
-
sleep 0.1
|
79
|
-
res = Helper.accept(:history).first.should == nil
|
80
|
-
end
|
81
99
|
end
|
82
100
|
end
|
data/spec/km_spec.rb
CHANGED
@@ -175,7 +175,6 @@ describe KM do
|
|
175
175
|
File.exists?(__('log/kissmetrics_production_query.log')).should == true
|
176
176
|
File.exists?(__('log/kissmetrics_production_error.log')).should == true
|
177
177
|
end
|
178
|
-
|
179
178
|
it "should escape @ properly" do
|
180
179
|
KM::init 'KM_OTHER', :log_dir => __('log'), :host => '127.0.0.1:9292', :to_stderr => false, :use_cron => true
|
181
180
|
KM::identify 'bob'
|
metadata
CHANGED
@@ -1,84 +1,88 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: km
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 1
|
8
|
-
- 2
|
9
|
-
version: 1.1.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.3
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- KISSmetrics
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-01-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: bundler
|
22
|
-
|
23
|
-
|
24
|
-
requirements:
|
25
|
-
- -
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 1
|
29
|
-
- 0
|
30
|
-
- 0
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
31
21
|
version: 1.0.0
|
32
22
|
type: :development
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: rspec
|
36
23
|
prerelease: false
|
37
|
-
|
38
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
39
35
|
- - ~>
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 2
|
43
|
-
- 4
|
44
|
-
- 0
|
36
|
+
- !ruby/object:Gem::Version
|
45
37
|
version: 2.4.0
|
46
38
|
type: :development
|
47
|
-
version_requirements: *id002
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: rake
|
50
39
|
prerelease: false
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.4.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
58
54
|
type: :development
|
59
|
-
version_requirements: *id003
|
60
|
-
- !ruby/object:Gem::Dependency
|
61
|
-
name: json
|
62
55
|
prerelease: false
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: json
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
70
|
type: :development
|
71
|
-
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
72
78
|
description: KISSmetrics ruby API gem
|
73
|
-
email:
|
79
|
+
email:
|
74
80
|
- support@kissmetrics.com
|
75
|
-
executables:
|
81
|
+
executables:
|
76
82
|
- km_send
|
77
83
|
extensions: []
|
78
|
-
|
79
84
|
extra_rdoc_files: []
|
80
|
-
|
81
|
-
files:
|
85
|
+
files:
|
82
86
|
- .gitignore
|
83
87
|
- CHANGELOG
|
84
88
|
- Gemfile
|
@@ -149,39 +153,34 @@ files:
|
|
149
153
|
- spec/log/.hold
|
150
154
|
- spec/setup.rb
|
151
155
|
- spec/watchr.rb
|
152
|
-
has_rdoc: true
|
153
156
|
homepage: https://github.com/kissmetrics/km
|
154
157
|
licenses: []
|
155
|
-
|
156
158
|
post_install_message:
|
157
159
|
rdoc_options: []
|
158
|
-
|
159
|
-
require_paths:
|
160
|
+
require_paths:
|
160
161
|
- lib
|
161
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
162
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
163
|
+
none: false
|
164
|
+
requirements:
|
165
|
+
- - ! '>='
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
segments:
|
166
169
|
- 0
|
167
|
-
|
168
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
- 1
|
174
|
-
- 3
|
175
|
-
- 6
|
170
|
+
hash: -3712010892193717644
|
171
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
|
+
none: false
|
173
|
+
requirements:
|
174
|
+
- - ! '>='
|
175
|
+
- !ruby/object:Gem::Version
|
176
176
|
version: 1.3.6
|
177
177
|
requirements: []
|
178
|
-
|
179
178
|
rubyforge_project: kissmetrics
|
180
|
-
rubygems_version: 1.
|
179
|
+
rubygems_version: 1.8.24
|
181
180
|
signing_key:
|
182
181
|
specification_version: 3
|
183
182
|
summary: KISSmetrics ruby API gem
|
184
|
-
test_files:
|
183
|
+
test_files:
|
185
184
|
- spec/accept.rb
|
186
185
|
- spec/km_old.rb
|
187
186
|
- spec/km_saas_spec.rb
|