thinkingdata-ruby 1.0.0 → 1.1.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/demo/demo.rb +66 -44
- data/lib/thinkingdata-ruby/batch_consumer.rb +23 -15
- data/lib/thinkingdata-ruby/debug_consumer.rb +5 -6
- data/lib/thinkingdata-ruby/tracker.rb +59 -35
- data/lib/thinkingdata-ruby/version.rb +1 -1
- 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: af3bee9acd623d7588b142a62e6ecef998c359c5
|
4
|
+
data.tar.gz: d9f7170bfc7dc600a58fcafbbfba45f92049f6d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6adee954d6aee35f30ed2a97074ce00500a71b4c02f3b4c1dded0ca44bcfc0e1636a0a564b49b4640114eae5d5a34c978630a8247d59bc6d0547f47deacd2ba6
|
7
|
+
data.tar.gz: d9052f017aae1f57252b7a15abd921f4e23d026c6010bba6d868b39f638a63f782a6a47c1f2faaa46352da11372aae62769601c65e53cde3895ec8d12cbd3be6
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
**v1.1.0** (2020/02/11)
|
2
|
+
- 数据类型支持array类型
|
3
|
+
- 新增 user_append 接口,支持用户的数组类型的属性追加
|
4
|
+
- BatchConsumer 性能优化:支持选择是否压缩;移除 Base64 编码
|
5
|
+
- DebugConsumer 优化: 在服务端对数据进行更完备准确地校验
|
6
|
+
|
1
7
|
**v1.0.0** (2019-11-20)
|
2
8
|
- 支持三种模式的上报: DebugConsumer, BatchConsumer, LoggerConsumer.
|
3
9
|
- 支持事件上报和用户属性上报.
|
data/demo/demo.rb
CHANGED
@@ -6,10 +6,9 @@ require 'time'
|
|
6
6
|
|
7
7
|
if __FILE__ == $0
|
8
8
|
# 替换 DEMO_APPID 为您项目的 APP ID
|
9
|
-
DEMO_APPID = '
|
9
|
+
DEMO_APPID = 'APPID'
|
10
10
|
# 替换 SERVER_URL 为您项目的 URL
|
11
11
|
SERVER_URL = 'https://sdk.tga.thinkinggame.cn'
|
12
|
-
|
13
12
|
# 账号 ID
|
14
13
|
DEMO_ACCOUNT_ID = 'ruby_demo_aid'
|
15
14
|
# 访客 ID
|
@@ -18,24 +17,29 @@ if __FILE__ == $0
|
|
18
17
|
# (可选) 定义一个错误处理器,当出现 Error 时会调用
|
19
18
|
class MyErrorHandler < TDAnalytics::ErrorHandler
|
20
19
|
def handle(error)
|
21
|
-
|
22
|
-
|
20
|
+
puts error
|
21
|
+
raise error
|
23
22
|
end
|
24
23
|
end
|
25
24
|
my_error_handler = MyErrorHandler.new
|
26
25
|
|
27
26
|
# 定义 consumer: consumer 实现了 add、flush、close 等接口,将经过 SDK 格式化的数据以不同的方式存储或者发送到接收端
|
28
27
|
consumer = nil
|
29
|
-
|
30
|
-
|
28
|
+
$ARGV = 1
|
29
|
+
case $ARGV
|
30
|
+
when 0
|
31
31
|
# LoggerConsumer,数据将写入本地文件(当前目录,按小时切分,前缀为 demolog),需要配合 Logbus 上传数据到 TA 服务器
|
32
32
|
consumer = TDAnalytics::LoggerConsumer.new '.', 'hourly', prefix: 'demolog'
|
33
|
-
when
|
33
|
+
when 1
|
34
34
|
# DebugConsumer,数据将被逐条同步的上报到 TA 服务器。出错时会返回详细的错误信息
|
35
35
|
consumer = TDAnalytics::DebugConsumer.new(SERVER_URL, DEMO_APPID)
|
36
|
-
|
36
|
+
# 如果不想上传到TA,只想校验数据格式,可以如下初始化
|
37
|
+
# consumer = TDAnalytics::DebugConsumer.new(SERVER_URL, DEMO_APPID,false)
|
38
|
+
when 2
|
37
39
|
# BatchConsumer,数据将先存入缓冲区,达到指定条数时上报,默认为 20 条
|
38
|
-
consumer = TDAnalytics::BatchConsumer.new(SERVER_URL, DEMO_APPID,
|
40
|
+
consumer = TDAnalytics::BatchConsumer.new(SERVER_URL, DEMO_APPID, 30)
|
41
|
+
#设置是否压缩数据,默认gzip压缩,内网可以这样设置
|
42
|
+
#consumer._set_compress(false)
|
39
43
|
else
|
40
44
|
# LoggerConsumer,数据将写入本地文件(当前目录,按天切分,前缀为 tda.log),需要配合 Logbus 上传数据到 TA 服务器
|
41
45
|
consumer = TDAnalytics::LoggerConsumer.new
|
@@ -46,10 +50,10 @@ if __FILE__ == $0
|
|
46
50
|
|
47
51
|
# 定义公共属性
|
48
52
|
super_properties = {
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
+
super_string: 'super_string',
|
54
|
+
super_int: 1,
|
55
|
+
super_bool: false,
|
56
|
+
super_date: Time.rfc2822("Thu, 26 Oct 2019 02:26:12 +0545")
|
53
57
|
}
|
54
58
|
|
55
59
|
# 设置公共事件属性,公共事件属性会添加到每个事件中
|
@@ -57,23 +61,24 @@ if __FILE__ == $0
|
|
57
61
|
|
58
62
|
# 定义事件数据
|
59
63
|
event = {
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
64
|
+
# 事件名称 (必填)
|
65
|
+
event_name: 'test_event',
|
66
|
+
# 账号 ID (可选)
|
67
|
+
account_id: DEMO_ACCOUNT_ID,
|
68
|
+
# 访客 ID (可选),账号 ID 和访客 ID 不可以都为空
|
69
|
+
distinct_id: DEMO_DISTINCT_ID,
|
70
|
+
# 事件时间 (可选) 如果不填,将以调用接口时的时间作为事件时间
|
71
|
+
time: Time.now,
|
72
|
+
# 事件 IP (可选) 当传入 IP 地址时,后台可以解析所在地
|
73
|
+
ip: '202.38.64.1',
|
74
|
+
# 事件属性 (可选)
|
75
|
+
properties: {
|
76
|
+
array: ["str1", "11", "22.22", "2020-02-11 17:02:52.415"],
|
77
|
+
prop_date: Time.now,
|
78
|
+
prop_double: 134.1,
|
79
|
+
prop_string: 'hello world',
|
80
|
+
prop_bool: true,
|
81
|
+
},
|
77
82
|
}
|
78
83
|
|
79
84
|
# 上报事件
|
@@ -84,31 +89,48 @@ if __FILE__ == $0
|
|
84
89
|
|
85
90
|
# 定义用户属性数据
|
86
91
|
user_data = {
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
92
|
+
# 账号 ID (可选)
|
93
|
+
account_id: DEMO_ACCOUNT_ID,
|
94
|
+
# 访客 ID (可选),账号 ID 和访客 ID 不可以都为空
|
95
|
+
distinct_id: DEMO_DISTINCT_ID,
|
96
|
+
# 用户属性
|
97
|
+
properties: {
|
98
|
+
array: ["str1", 11, 22.22],
|
99
|
+
prop_date: Time.now,
|
100
|
+
prop_double: 134.12,
|
101
|
+
prop_string: 'hello',
|
102
|
+
prop_int: 666,
|
103
|
+
},
|
98
104
|
}
|
99
105
|
# 设置用户属性, 覆盖同名属性
|
100
106
|
ta.user_set(user_data)
|
101
107
|
|
108
|
+
#追加user的一个或者多个列表的属性
|
109
|
+
user_data_arr = {
|
110
|
+
# 账号 ID (可选)
|
111
|
+
account_id: DEMO_ACCOUNT_ID,
|
112
|
+
# 访客 ID (可选),账号 ID 和访客 ID 不可以都为空
|
113
|
+
distinct_id: DEMO_DISTINCT_ID,
|
114
|
+
# 用户属性
|
115
|
+
properties: {
|
116
|
+
array: ["33", "44"],
|
117
|
+
},
|
118
|
+
}
|
119
|
+
|
120
|
+
ta.user_append(user_data_arr)
|
121
|
+
|
102
122
|
# 设置用户属性,不会覆盖已经设置的同名属性
|
103
123
|
user_data[:properties][:prop_int_new] = 800
|
104
124
|
ta.user_set_once(user_data)
|
105
125
|
|
106
|
-
# 删除某个用户属性
|
107
|
-
# ta.user_unset(distinct_id: DEMO_DISTINCT_ID, property: :prop_string)
|
108
|
-
|
109
126
|
# 累加用户属性
|
110
127
|
ta.user_add(distinct_id: DEMO_DISTINCT_ID, properties: {prop_int: 10, prop_double: 15.88})
|
111
128
|
|
129
|
+
|
130
|
+
# 删除某个用户属性
|
131
|
+
ta.user_unset(distinct_id: DEMO_DISTINCT_ID, property: [:prop_string, :prop_int])
|
132
|
+
|
133
|
+
|
112
134
|
# 删除用户。此操作之前的事件数据不会被删除
|
113
135
|
# ta.user_del(distinct_id: DEMO_DISTINCT_ID)
|
114
136
|
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'base64'
|
2
1
|
require 'json'
|
3
2
|
require 'net/http'
|
4
3
|
|
@@ -9,14 +8,19 @@ module TDAnalytics
|
|
9
8
|
# 默认缓冲区大小
|
10
9
|
MAX_LENGTH = 20
|
11
10
|
|
12
|
-
def initialize(server_url, app_id, max_buffer_length=MAX_LENGTH)
|
11
|
+
def initialize(server_url, app_id, max_buffer_length = MAX_LENGTH)
|
13
12
|
@server_uri = URI.parse(server_url)
|
14
|
-
@server_uri.path = '/
|
13
|
+
@server_uri.path = '/sync_server'
|
15
14
|
@app_id = app_id
|
15
|
+
@compress = true
|
16
16
|
@max_length = [max_buffer_length, MAX_LENGTH].min
|
17
17
|
@buffers = []
|
18
18
|
end
|
19
19
|
|
20
|
+
def _set_compress(compress)
|
21
|
+
@compress = compress
|
22
|
+
end
|
23
|
+
|
20
24
|
def add(message)
|
21
25
|
@buffers << message
|
22
26
|
flush if @buffers.length >= @max_length
|
@@ -29,13 +33,17 @@ module TDAnalytics
|
|
29
33
|
def flush
|
30
34
|
begin
|
31
35
|
@buffers.each_slice(@max_length) do |chunk|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
if @compress
|
37
|
+
wio = StringIO.new("w")
|
38
|
+
gzip_io = Zlib::GzipWriter.new(wio)
|
39
|
+
gzip_io.write(chunk.to_json)
|
40
|
+
gzip_io.close
|
41
|
+
data = wio.string
|
42
|
+
else
|
43
|
+
data = chunk.to_json
|
44
|
+
end
|
45
|
+
compress_type = @compress ? 'gzip' : 'none'
|
46
|
+
headers = {'Content-Type' => 'application/plaintext', 'appid' => @app_id, 'compress' => compress_type}
|
39
47
|
request = CaseSensitivePost.new(@server_uri.request_uri, headers)
|
40
48
|
request.body = data
|
41
49
|
|
@@ -44,7 +52,7 @@ module TDAnalytics
|
|
44
52
|
rescue => e
|
45
53
|
raise ConnectionError.new("Could not connect to TA server, with error \"#{e.message}\".")
|
46
54
|
end
|
47
|
-
|
55
|
+
|
48
56
|
result = {}
|
49
57
|
if response_code.to_i == 200
|
50
58
|
begin
|
@@ -53,7 +61,7 @@ module TDAnalytics
|
|
53
61
|
raise ServerError.new("Could not interpret TA server response: '#{response_body}'")
|
54
62
|
end
|
55
63
|
end
|
56
|
-
|
64
|
+
|
57
65
|
if result['code'] != 0
|
58
66
|
raise ServerError.new("Could not write to TA, server responded with #{response_code} returning: '#{response_body}'")
|
59
67
|
end
|
@@ -84,11 +92,11 @@ module TDAnalytics
|
|
84
92
|
@header = {}
|
85
93
|
headers.each{|k,v| @header[k.to_s] = [v] }
|
86
94
|
end
|
87
|
-
|
95
|
+
|
88
96
|
def [](name)
|
89
97
|
@header[name.to_s]
|
90
98
|
end
|
91
|
-
|
99
|
+
|
92
100
|
def []=(name, val)
|
93
101
|
if val
|
94
102
|
@header[name.to_s] = [val]
|
@@ -96,7 +104,7 @@ module TDAnalytics
|
|
96
104
|
@header.delete(name.to_s)
|
97
105
|
end
|
98
106
|
end
|
99
|
-
|
107
|
+
|
100
108
|
def capitalize(name)
|
101
109
|
name
|
102
110
|
end
|
@@ -6,15 +6,16 @@ module TDAnalytics
|
|
6
6
|
# DebugConsumer 会返回详细的报错信息,建议在集成阶段先使用 DebugConsumer 调试接口
|
7
7
|
class DebugConsumer
|
8
8
|
|
9
|
-
def initialize(server_url, app_id)
|
9
|
+
def initialize(server_url, app_id, write_data = true)
|
10
10
|
@server_uri = URI.parse(server_url)
|
11
|
-
@server_uri.path = '/
|
11
|
+
@server_uri.path = '/data_debug'
|
12
12
|
@app_id = app_id
|
13
|
+
@write_data = write_data
|
13
14
|
end
|
14
15
|
|
15
16
|
def add(message)
|
16
17
|
puts message.to_json
|
17
|
-
form_data = {"data" => message.to_json, "appid" => @app_id, "
|
18
|
+
form_data = {"data" => message.to_json, "appid" => @app_id, "dryRun" => @write_data ? "0" : "1", "source" => "server"}
|
18
19
|
begin
|
19
20
|
response_code, response_body = request(@server_uri, form_data)
|
20
21
|
rescue => e
|
@@ -30,9 +31,7 @@ module TDAnalytics
|
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
if result['code'] != 0
|
34
|
+
if result['errorLevel'] != 0
|
36
35
|
raise ServerError.new("Could not write to TA, server responded with #{response_code} returning: '#{response_body}'")
|
37
36
|
end
|
38
37
|
end
|
@@ -31,7 +31,7 @@ module TDAnalytics
|
|
31
31
|
# ErrorHandler 的定义可以参考 thinkingdata-ruby/errors.rb
|
32
32
|
#
|
33
33
|
# uuid 如果为 true,每条数据都会被带上随机 UUID 作为 #uuid 属性的值上报,该值不会入库,仅仅用于后台做数据重复检测
|
34
|
-
def initialize(consumer, error_handler=nil, uuid: false)
|
34
|
+
def initialize(consumer, error_handler = nil, uuid: false)
|
35
35
|
@error_handler = error_handler || ErrorHandler.new
|
36
36
|
@consumer = consumer
|
37
37
|
@super_properties = {}
|
@@ -67,7 +67,7 @@ module TDAnalytics
|
|
67
67
|
# time: (可选)Time 事件发生时间,如果不传默认为系统当前时间
|
68
68
|
# ip: (可选) 事件 IP,如果传入 IP 地址,后端可以通过 IP 地址解析事件发生地点
|
69
69
|
# skip_local_check: (可选) boolean 表示是否跳过本地检测
|
70
|
-
def track(event_name:nil, distinct_id:nil, account_id:nil, properties:{}, time:nil, ip:nil, skip_local_check: false)
|
70
|
+
def track(event_name: nil, distinct_id: nil, account_id: nil, properties: {}, time: nil, ip: nil, skip_local_check: false)
|
71
71
|
begin
|
72
72
|
_check_name event_name
|
73
73
|
_check_id(distinct_id, account_id)
|
@@ -94,7 +94,7 @@ module TDAnalytics
|
|
94
94
|
# distinct_id: (可选) 访客 ID
|
95
95
|
# account_id: (可选) 账号ID distinct_id 和 account_id 不能同时为空
|
96
96
|
# properties: (可选) Hash 用户属性。支持四种类型的值:字符串、数值、Time、boolean
|
97
|
-
def user_set(distinct_id:nil, account_id:nil, properties:{}, ip:nil)
|
97
|
+
def user_set(distinct_id: nil, account_id: nil, properties: {}, ip: nil)
|
98
98
|
begin
|
99
99
|
_check_id(distinct_id, account_id)
|
100
100
|
_check_properties(:user_set, properties)
|
@@ -104,15 +104,15 @@ module TDAnalytics
|
|
104
104
|
end
|
105
105
|
|
106
106
|
_internal_track(:user_set,
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
107
|
+
distinct_id: distinct_id,
|
108
|
+
account_id: account_id,
|
109
|
+
properties: properties,
|
110
|
+
ip: ip,
|
111
111
|
)
|
112
112
|
end
|
113
113
|
|
114
114
|
# 设置用户属性. 如果有重名属性,则丢弃, 参数与 user_set 相同
|
115
|
-
def user_set_once(distinct_id:nil, account_id:nil, properties:{}, ip:nil)
|
115
|
+
def user_set_once(distinct_id: nil, account_id: nil, properties: {}, ip: nil)
|
116
116
|
begin
|
117
117
|
_check_id(distinct_id, account_id)
|
118
118
|
_check_properties(:user_setOnce, properties)
|
@@ -122,15 +122,32 @@ module TDAnalytics
|
|
122
122
|
end
|
123
123
|
|
124
124
|
_internal_track(:user_setOnce,
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
125
|
+
distinct_id: distinct_id,
|
126
|
+
account_id: account_id,
|
127
|
+
properties: properties,
|
128
|
+
ip: ip,
|
129
129
|
)
|
130
130
|
end
|
131
131
|
|
132
|
+
# 追加用户的一个或多个列表类型的属性
|
133
|
+
def user_append(distinct_id: nil, account_id: nil, properties: {})
|
134
|
+
begin
|
135
|
+
_check_id(distinct_id, account_id)
|
136
|
+
_check_properties(:user_append, properties)
|
137
|
+
rescue TDAnalyticsError => e
|
138
|
+
@error_handler.handle(e)
|
139
|
+
return false
|
140
|
+
end
|
141
|
+
|
142
|
+
_internal_track(:user_append,
|
143
|
+
distinct_id: distinct_id,
|
144
|
+
account_id: account_id,
|
145
|
+
properties: properties,
|
146
|
+
)
|
147
|
+
end
|
148
|
+
|
132
149
|
# 删除用户属性, property 可以传入需要删除的用户属性的 key 值,或者 key 值数组
|
133
|
-
def user_unset(distinct_id:nil, account_id:nil, property:nil)
|
150
|
+
def user_unset(distinct_id: nil, account_id: nil, property: nil)
|
134
151
|
properties = {}
|
135
152
|
if property.is_a?(Array)
|
136
153
|
property.each do |k|
|
@@ -149,9 +166,9 @@ module TDAnalytics
|
|
149
166
|
end
|
150
167
|
|
151
168
|
_internal_track(:user_unset,
|
152
|
-
|
153
|
-
|
154
|
-
|
169
|
+
distinct_id: distinct_id,
|
170
|
+
account_id: account_id,
|
171
|
+
properties: properties,
|
155
172
|
)
|
156
173
|
end
|
157
174
|
|
@@ -159,7 +176,7 @@ module TDAnalytics
|
|
159
176
|
# distinct_id: (可选) 访客 ID
|
160
177
|
# account_id: (可选) 账号ID distinct_id 和 account_id 不能同时为空
|
161
178
|
# properties: (可选) Hash 数值类型的用户属性
|
162
|
-
def user_add(distinct_id:nil, account_id:nil, properties:{})
|
179
|
+
def user_add(distinct_id: nil, account_id: nil, properties: {})
|
163
180
|
begin
|
164
181
|
_check_id(distinct_id, account_id)
|
165
182
|
_check_properties(:user_add, properties)
|
@@ -169,14 +186,14 @@ module TDAnalytics
|
|
169
186
|
end
|
170
187
|
|
171
188
|
_internal_track(:user_add,
|
172
|
-
|
173
|
-
|
174
|
-
|
189
|
+
distinct_id: distinct_id,
|
190
|
+
account_id: account_id,
|
191
|
+
properties: properties,
|
175
192
|
)
|
176
193
|
end
|
177
194
|
|
178
195
|
# 删除用户,用户之前的事件数据不会被删除
|
179
|
-
def user_del(distinct_id:nil, account_id:nil)
|
196
|
+
def user_del(distinct_id: nil, account_id: nil)
|
180
197
|
begin
|
181
198
|
_check_id(distinct_id, account_id)
|
182
199
|
rescue TDAnalyticsError => e
|
@@ -185,8 +202,8 @@ module TDAnalytics
|
|
185
202
|
end
|
186
203
|
|
187
204
|
_internal_track(:user_del,
|
188
|
-
|
189
|
-
|
205
|
+
distinct_id: distinct_id,
|
206
|
+
account_id: account_id,
|
190
207
|
)
|
191
208
|
end
|
192
209
|
|
@@ -219,7 +236,7 @@ module TDAnalytics
|
|
219
236
|
private
|
220
237
|
|
221
238
|
# 出现异常的时候返回 false, 否则 true
|
222
|
-
def _internal_track(type, properties:{}, event_name:nil, account_id:nil, distinct_id:nil, ip:nil, time:Time.now)
|
239
|
+
def _internal_track(type, properties: {}, event_name: nil, account_id: nil, distinct_id: nil, ip: nil, time: Time.now)
|
223
240
|
if account_id == nil && distinct_id == nil
|
224
241
|
raise IllegalParameterError.new('account id or distinct id must be provided.')
|
225
242
|
end
|
@@ -231,22 +248,22 @@ module TDAnalytics
|
|
231
248
|
|
232
249
|
# 格式化 Time 类型
|
233
250
|
properties.each do |k, v|
|
234
|
-
|
235
|
-
|
236
|
-
|
251
|
+
if v.is_a?(Time)
|
252
|
+
properties[k] = _format_time(v)
|
253
|
+
end
|
237
254
|
end
|
238
255
|
|
239
256
|
data = {
|
240
|
-
|
241
|
-
|
242
|
-
|
257
|
+
'#type' => type,
|
258
|
+
'#time' => _format_time(time),
|
259
|
+
'properties' => properties,
|
243
260
|
}
|
244
261
|
|
245
262
|
data['#event_name'] = event_name if type == :track
|
246
263
|
data['#account_id'] = account_id if account_id
|
247
264
|
data['#distinct_id'] = distinct_id if distinct_id
|
248
265
|
data['#ip'] = ip if ip
|
249
|
-
data['#uuid'] =
|
266
|
+
data['#uuid'] = SecureRandom.uuid if @uuid
|
250
267
|
|
251
268
|
ret = true
|
252
269
|
begin
|
@@ -286,13 +303,20 @@ module TDAnalytics
|
|
286
303
|
|
287
304
|
properties.each do |k, v|
|
288
305
|
_check_name k
|
289
|
-
unless v.is_a?(Integer) || v.is_a?(Float) || v.is_a?(Symbol) || v.is_a?(String) || v.is_a?(Time) || !!v == v
|
290
|
-
raise IllegalParameterError.new("The value of properties must be type in Integer, Float, Symbol, String, and Time")
|
306
|
+
unless v.is_a?(Integer) || v.is_a?(Float) || v.is_a?(Symbol) || v.is_a?(String) || v.is_a?(Time) || !!v == v || v.is_a?(Array)
|
307
|
+
raise IllegalParameterError.new("The value of properties must be type in Integer, Float, Symbol, String, Array,and Time")
|
291
308
|
end
|
292
309
|
|
293
310
|
if type == :user_add
|
294
311
|
raise IllegalParameterError.new("Property value for user add must be numbers") unless v.is_a?(Integer) || v.is_a?(Float)
|
295
312
|
end
|
313
|
+
if v.is_a?(Array)
|
314
|
+
v.each_index do |i|
|
315
|
+
if v[i].is_a?(Time)
|
316
|
+
v[i] = _format_time(v[i])
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
296
320
|
end
|
297
321
|
true
|
298
322
|
end
|
@@ -302,11 +326,11 @@ module TDAnalytics
|
|
302
326
|
raise IllegalParameterError.new("account id or distinct id must be provided.") if distinct_id.nil? && account_id.nil?
|
303
327
|
|
304
328
|
unless distinct_id.nil?
|
305
|
-
raise IllegalParameterError.new("The length of distinct id should in (0, 64]")
|
329
|
+
raise IllegalParameterError.new("The length of distinct id should in (0, 64]") if distinct_id.to_s.length < 1 || distinct_id.to_s.length > 64
|
306
330
|
end
|
307
331
|
|
308
332
|
unless account_id.nil?
|
309
|
-
raise IllegalParameterError.new("The length of account id should in (0, 64]")
|
333
|
+
raise IllegalParameterError.new("The length of account id should in (0, 64]") if account_id.to_s.length < 1 || account_id.to_s.length > 64
|
310
334
|
end
|
311
335
|
end
|
312
336
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thinkingdata-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ThinkingData
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: The official ThinkingData Analytics API for ruby
|
14
14
|
email: sdk@thinkingdata.cn
|