statsig 1.9.2 → 1.10.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: afbf6d972c5aeead4eeaa8c352155c41b02a3710f55d80309939d5acc0fd1e80
4
- data.tar.gz: c83f0399868af1d7978aeb2d2723f4bfbc860646de3ea0a7aaf840903489b92a
3
+ metadata.gz: dd12cded3010fd966063f91670f1a8f0531196afb96d81f4470311a8d978606d
4
+ data.tar.gz: f5e3f6715c245263cc1702172da20ad164d20e76dc69a285bcfafe72f7e809ef
5
5
  SHA512:
6
- metadata.gz: babe4ac6dc398bd87df7537ea7c9391e72e4a32c4ec80944895adb507351a02042dd2bfc28deb2336e706fcf531ba4d30dfdeeb280404b108a25505fcd749ed8
7
- data.tar.gz: c1bad8f27c2675b7dbc125090a56062e71c5fddb6f0cc8464c0e9ea03b910f9ca918a9ccf4e6c8db99815b7964aaf543d0cc69db5a873bcf58ddc806ef8932cc
6
+ metadata.gz: 1dde66bd943e314af8359a243eab9251c2b6bff7a11cb7d988f9ce02d5608b740f0aeb82030e751b553fe355b2a65a41ecc6ac7a23f84dc64c382926a73c72da
7
+ data.tar.gz: b3d22016c1753ba81daab0039b67a51109fcd240d38514458701c73fb1af0c2cd6a7ac219cd9ef5a34ff2bbac760fe595d17cc4410297799fecfff8a0211bb4f
data/lib/evaluator.rb CHANGED
@@ -12,8 +12,8 @@ $type_dynamic_config = 'dynamic_config'
12
12
 
13
13
  module Statsig
14
14
  class Evaluator
15
- def initialize(network, error_callback)
16
- @spec_store = Statsig::SpecStore.new(network, error_callback)
15
+ def initialize(network, options, error_callback)
16
+ @spec_store = Statsig::SpecStore.new(network, error_callback, options.rulesets_sync_interval, options.idlists_sync_interval)
17
17
  @ua_parser = UserAgentParser::Parser.new
18
18
  CountryLookup.initialize
19
19
  @initialized = true
data/lib/spec_store.rb CHANGED
@@ -5,10 +5,10 @@ require 'id_list'
5
5
 
6
6
  module Statsig
7
7
  class SpecStore
8
- def initialize(network, error_callback = nil, config_sync_interval = 10, id_lists_sync_interval = 60)
8
+ def initialize(network, error_callback = nil, rulesets_sync_interval = 10, id_lists_sync_interval = 60)
9
9
  @network = network
10
10
  @last_sync_time = 0
11
- @config_sync_interval = config_sync_interval
11
+ @rulesets_sync_interval = rulesets_sync_interval
12
12
  @id_lists_sync_interval = id_lists_sync_interval
13
13
  @store = {
14
14
  :gates => {},
@@ -65,7 +65,7 @@ module Statsig
65
65
  def sync_config_specs
66
66
  Thread.new do
67
67
  loop do
68
- sleep @config_sync_interval
68
+ sleep @rulesets_sync_interval
69
69
  download_config_specs
70
70
  end
71
71
  end
@@ -145,7 +145,7 @@ module Statsig
145
145
  next
146
146
  end
147
147
 
148
- # skip if server list returns a newer file
148
+ # reset local list if server list returns a newer file
149
149
  if server_list.file_id != local_list.file_id && server_list.creation_time >= local_list.creation_time
150
150
  local_list = IDList.new(list)
151
151
  local_list.size = 0
data/lib/statsig.rb CHANGED
@@ -30,7 +30,7 @@ module Statsig
30
30
  @shared_instance&.get_layer(user, layer_name)
31
31
  end
32
32
 
33
- def self.log_event(user, event_name, value, metadata)
33
+ def self.log_event(user, event_name, value = nil, metadata = nil)
34
34
  ensure_initialized
35
35
  @shared_instance&.log_event(user, event_name, value, metadata)
36
36
  end
@@ -45,7 +45,7 @@ module Statsig
45
45
  def self.get_statsig_metadata
46
46
  {
47
47
  'sdkType' => 'ruby-server',
48
- 'sdkVersion' => '1.9.2',
48
+ 'sdkVersion' => '1.10.0',
49
49
  }
50
50
  end
51
51
 
@@ -24,7 +24,7 @@ class StatsigDriver
24
24
  @secret_key = secret_key
25
25
  @net = Statsig::Network.new(secret_key, @options.api_url_base)
26
26
  @logger = Statsig::StatsigLogger.new(@net)
27
- @evaluator = Statsig::Evaluator.new(@net, error_callback)
27
+ @evaluator = Statsig::Evaluator.new(@net, @options, error_callback)
28
28
  end
29
29
 
30
30
  def check_gate(user, gate_name)
@@ -127,8 +127,14 @@ class StatsigDriver
127
127
  end
128
128
 
129
129
  def validate_user(user)
130
- if user.nil? || !user.instance_of?(StatsigUser) || !user.user_id.is_a?(String)
131
- raise 'Must provide a valid StatsigUser with a user_id to use the server SDK. See https://docs.statsig.com/messages/serverRequiredUserID/ for more details.'
130
+ if user.nil? ||
131
+ !user.instance_of?(StatsigUser) ||
132
+ (
133
+ # user_id is nil and custom_ids is not a hash with entries
134
+ !user.user_id.is_a?(String) &&
135
+ (!user.custom_ids.is_a?(Hash) || user.custom_ids.size == 0)
136
+ )
137
+ raise 'Must provide a valid StatsigUser with a user_id or at least a custom ID. See https://docs.statsig.com/messages/serverRequiredUserID/ for more details.'
132
138
  end
133
139
  end
134
140
 
@@ -14,7 +14,7 @@ module Statsig
14
14
 
15
15
  def log_event(event)
16
16
  @events.push(event)
17
- if @events.length >= 500
17
+ if @events.length >= 1000
18
18
  flush
19
19
  end
20
20
  end
@@ -83,8 +83,9 @@ module Statsig
83
83
  if @events.length == 0
84
84
  return
85
85
  end
86
- flush_events = @events.map { |e| e.serialize }
86
+ events_clone = @events
87
87
  @events = []
88
+ flush_events = events_clone.map { |e| e.serialize }
88
89
 
89
90
  @network.post_logs(flush_events)
90
91
  end
@@ -1,9 +1,17 @@
1
1
  class StatsigOptions
2
2
  attr_reader :environment
3
3
  attr_reader :api_url_base
4
+ attr_reader :rulesets_sync_interval
5
+ attr_reader :idlists_sync_interval
4
6
 
5
- def initialize(environment = nil, api_url_base = 'https://statsigapi.net/v1')
7
+ def initialize(
8
+ environment=nil,
9
+ api_url_base='https://statsigapi.net/v1',
10
+ rulesets_sync_interval: 10,
11
+ idlists_sync_interval: 60)
6
12
  @environment = environment.is_a?(Hash) ? environment : nil
7
13
  @api_url_base = api_url_base
14
+ @rulesets_sync_interval = rulesets_sync_interval
15
+ @idlists_sync_interval = idlists_sync_interval
8
16
  end
9
17
  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.9.2
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Statsig, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-29 00:00:00.000000000 Z
11
+ date: 2022-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler