Class: KMTS
- Inherits:
-
Object
show all
- Defined in:
- lib/kmts.rb,
lib/kmts/saas.rb,
lib/kmts/version.rb
Defined Under Namespace
Modules: SaaS
Classes: IdentError, InitError
Constant Summary
collapse
- DEFAULT_TRACKING_SERVER =
'https://trk.kissmetrics.io'.freeze
- PROTOCOL_MATCHER =
%r(://)
- VERSION =
"3.1.0"
Class Method Summary
collapse
Class Method Details
.alias(name, alias_to) ⇒ Object
73
74
75
76
77
78
79
80
|
# File 'lib/kmts.rb', line 73
def alias(name, alias_to)
begin
return unless is_initialized?
generate_query('a', { '_n' => alias_to, '_p' => name }, false)
rescue Exception => e
log_error(e)
end
end
|
.host ⇒ Object
118
119
120
|
# File 'lib/kmts.rb', line 118
def host
@host
end
|
.init(key, options = {}) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/kmts.rb', line 27
def init(key, options={})
default = {
:host => @host,
:log_dir => @log_dir,
:to_stderr => @to_stderr,
:use_cron => @use_cron,
:dryrun => @dryrun,
:env => set_env,
:force_key => @force_key
}
options = default.merge(options)
begin
@key = key
@host = options[:host]
@log_dir = options[:log_dir]
@use_cron = options[:use_cron]
@to_stderr = options[:to_stderr]
@dryrun = options[:dryrun]
@env = options[:env]
@force_key = options[:force_key]
log_dir_writable?
rescue Exception => e
log_error(e)
end
end
|
.log_dir ⇒ Object
115
116
117
|
# File 'lib/kmts.rb', line 115
def log_dir
@log_dir
end
|
.record(id, action, props = {}) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/kmts.rb', line 60
def record(id, action, props={})
props = hash_keys_to_str(props)
begin
return unless is_initialized?
return set(id, action) if action.class == Hash
props.update('_n' => action)
generate_query('e', props, id)
rescue Exception => e
log_error(e)
end
end
|
.send_logged_queries ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/kmts.rb', line 91
def send_logged_queries
line = nil
begin
query_log = log_name(:query_old)
query_log = log_name(:query) unless File.exists?(query_log)
return unless File.exists?(query_log)
FileUtils.move(query_log, log_name(:send))
File.open(log_name(:send)) do |fh|
while not fh.eof?
begin
line = fh.readline.chomp
send_query(line)
rescue Exception => e
log_query(line) if line
log_error(e)
end
end
end
FileUtils.rm(log_name(:send))
rescue Exception => e
log_error(e)
end
end
|
.set(id, data) ⇒ Object
82
83
84
85
86
87
88
89
|
# File 'lib/kmts.rb', line 82
def set(id, data)
begin
return unless is_initialized?
generate_query('s', data, id)
rescue Exception => e
log_error(e)
end
end
|
.set_env ⇒ Object
54
55
56
57
58
|
# File 'lib/kmts.rb', line 54
def set_env
@env = Rails.env if defined? Rails
@env ||= ENV['RACK_ENV']
@env ||= 'production'
end
|