statsig 1.4.0 → 1.5.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
  SHA256:
3
- metadata.gz: 3ac164a57fadf37c1c9ce2b978df30da43901cc3b53e03e1b3e52a72e19981cb
4
- data.tar.gz: aad0387cd6a80bfd3cbf501118466f444790ec387b45a96d562a3256331ae034
3
+ metadata.gz: a7fc845aabeb9119437279ba79db3970aecf676229ea36c0fd5af08186cb87af
4
+ data.tar.gz: d81e0e6b0ae19959b95bfbd56d0dfb55c8baaab0bfa393a099e84226bb5a8fb5
5
5
  SHA512:
6
- metadata.gz: f7eeefd82a45217becadee9783d2616de5e6997d29236fecea526947a34e54f921125fbf018f57a1fbf2f7560c00d80721f632a9498e0f065b6914b035beef5f
7
- data.tar.gz: 24b8c55535b7656109b669d898351e536953c83ecc6858e94eabacbdb36f8c9e600b55bb9cd06fc8b043a84305f351e645c07a673a85c1688668de6181c125f3
6
+ metadata.gz: 1d9d50f2f01599da2d6a5694c049e4a9ff1caca997563d69849588068e8505878678c5bbc7d8be2b7f887eb1ce36acea6e0f465246f4ce77117860ce77c34f7c
7
+ data.tar.gz: e3da88258f99e6579a9b07cd0a5d715587a56dc78b0c99cc490a52d0a12962bb7a74c783458b8cf85f497cf92d74b75a5eca9ae3053a37a84cfb5609b8252067
data/lib/evaluator.rb CHANGED
@@ -84,10 +84,10 @@ class Evaluator
84
84
  return $fetch_from_server if other_gate_result == $fetch_from_server
85
85
  return type == 'pass_gate' ? other_gate_result.gate_value : !other_gate_result.gate_value
86
86
  when 'ip_based'
87
- value = get_value_from_user(user, field) || get_value_from_ip(user&.value_lookup['ip'], field)
87
+ value = get_value_from_user(user, field) || get_value_from_ip(user, field)
88
88
  return $fetch_from_server if value == $fetch_from_server
89
89
  when 'ua_based'
90
- value = get_value_from_user(user, field) || get_value_from_ua(user&.value_lookup['userAgent'], field)
90
+ value = get_value_from_user(user, field) || get_value_from_ua(user, field)
91
91
  return $fetch_from_server if value == $fetch_from_server
92
92
  when 'user_field'
93
93
  value = get_value_from_user(user, field)
@@ -177,13 +177,22 @@ class Evaluator
177
177
 
178
178
  user_lookup_table = user&.value_lookup
179
179
  return nil unless user_lookup_table.is_a?(Hash)
180
- return user_lookup_table[field.downcase] if user_lookup_table.has_key?(field.downcase)
180
+ return user_lookup_table[field.downcase] if user_lookup_table.has_key?(field.downcase) && !user_lookup_table[field.downcase].nil?
181
181
 
182
182
  user_custom = user_lookup_table['custom']
183
- return nil unless user_custom.is_a?(Hash)
184
- user_custom.each do |key, value|
185
- return value if key.downcase.casecmp?(field.downcase)
183
+ if user_custom.is_a?(Hash)
184
+ user_custom.each do |key, value|
185
+ return value if key.downcase.casecmp?(field.downcase) && !value.nil?
186
+ end
187
+ end
188
+
189
+ private_attributes = user_lookup_table['privateAttributes']
190
+ if private_attributes.is_a?(Hash)
191
+ private_attributes.each do |key, value|
192
+ return value if key.downcase.casecmp?(field.downcase) && !value.nil?
193
+ end
186
194
  end
195
+
187
196
  nil
188
197
  end
189
198
 
@@ -197,17 +206,19 @@ class Evaluator
197
206
  nil
198
207
  end
199
208
 
200
- def get_value_from_ip(ip, field)
201
- return nil unless ip.is_a?(String) && field.is_a?(String)
209
+ def get_value_from_ip(user, field)
210
+ return nil unless user.is_a?(StatsigUser) && field.is_a?(String) && field.downcase == 'country'
211
+ ip = get_value_from_user(user, 'ip')
212
+ return nil unless ip.is_a?(String)
202
213
 
203
- if field.downcase != 'country'
204
- return $fetch_from_server
205
- end
206
214
  CountryLookup.lookup_ip_string(ip)
207
215
  end
208
216
 
209
- def get_value_from_ua(ua, field)
210
- return nil unless ua.is_a?(String) && field.is_a?(String)
217
+ def get_value_from_ua(user, field)
218
+ return nil unless user.is_a?(StatsigUser) && field.is_a?(String)
219
+ ua = get_value_from_user(user, 'userAgent')
220
+ return nil unless ua.is_a?(String)
221
+
211
222
  parsed = @ua_parser.parse ua
212
223
  os = parsed.os
213
224
  case field.downcase
data/lib/network.rb CHANGED
@@ -39,7 +39,7 @@ class Network
39
39
 
40
40
  def check_gate(user, gate_name)
41
41
  begin
42
- request_body = JSON.generate({'user' => user&.serialize, 'gateName' => gate_name})
42
+ request_body = JSON.generate({'user' => user&.serialize(false), 'gateName' => gate_name})
43
43
  response = post_helper('check_gate', request_body)
44
44
  return JSON.parse(response.body) unless response.nil?
45
45
  false
@@ -50,7 +50,7 @@ class Network
50
50
 
51
51
  def get_config(user, dynamic_config_name)
52
52
  begin
53
- request_body = JSON.generate({'user' => user&.serialize, 'configName' => dynamic_config_name})
53
+ request_body = JSON.generate({'user' => user&.serialize(false), 'configName' => dynamic_config_name})
54
54
  response = post_helper('get_config', request_body)
55
55
  return JSON.parse(response.body) unless response.nil?
56
56
  nil
@@ -96,7 +96,7 @@ class StatsigDriver
96
96
  user = normalize_user(user)
97
97
 
98
98
  event = StatsigEvent.new(event_name)
99
- event.user = user&.serialize
99
+ event.user = user
100
100
  event.value = value
101
101
  event.metadata = metadata
102
102
  event.statsig_metadata = @statsig_metadata
data/lib/statsig_event.rb CHANGED
@@ -1,15 +1,22 @@
1
1
  class StatsigEvent
2
2
  attr_accessor :value
3
- attr_accessor :user
4
3
  attr_accessor :metadata
5
4
  attr_accessor :statsig_metadata
5
+ attr_reader :user
6
+
6
7
  def initialize(event_name)
7
8
  @event_name = event_name
8
9
  @time = Time.now.to_f * 1000
9
10
  end
10
11
 
12
+ def user=(value)
13
+ if value.is_a?(StatsigUser)
14
+ @user = value.serialize(true)
15
+ end
16
+ end
17
+
11
18
  def serialize
12
- return {
19
+ {
13
20
  'eventName' => @event_name,
14
21
  'metadata' => @metadata,
15
22
  'value' => @value,
data/lib/statsig_user.rb CHANGED
@@ -7,6 +7,7 @@ class StatsigUser
7
7
  attr_accessor :locale
8
8
  attr_accessor :app_version
9
9
  attr_accessor :statsig_environment
10
+ attr_accessor :private_attributes
10
11
 
11
12
  def custom
12
13
  @custom
@@ -29,11 +30,12 @@ class StatsigUser
29
30
  @app_version = user_hash['appVersion'] || user_hash['app_version']
30
31
  @custom = user_hash['custom']
31
32
  @statsig_environment = user_hash['statsigEnvironment']
33
+ @private_attributes = user_hash['privateAttributes']
32
34
  end
33
35
  end
34
36
 
35
- def serialize
36
- {
37
+ def serialize(for_logging)
38
+ hash = {
37
39
  'userID' => @user_id,
38
40
  'email' => @email,
39
41
  'ip' => @ip,
@@ -43,7 +45,12 @@ class StatsigUser
43
45
  'appVersion' => @app_version,
44
46
  'custom' => @custom,
45
47
  'statsigEnvironment' => @statsig_environment,
48
+ 'privateAttributes' => @private_attributes,
46
49
  }
50
+ if for_logging
51
+ hash.delete('privateAttributes')
52
+ end
53
+ hash
47
54
  end
48
55
 
49
56
  def value_lookup
@@ -62,6 +69,7 @@ class StatsigUser
62
69
  'appversion' => @app_version,
63
70
  'app_version' => @app_version,
64
71
  'custom' => @custom,
72
+ 'privateAttributes' => @private_attributes,
65
73
  }
66
74
  end
67
75
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsig
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Statsig, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-13 00:00:00.000000000 Z
11
+ date: 2021-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler