configcat 6.1.0 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,45 @@
1
1
  module ConfigCat
2
- # The user object for variation evaluation
2
+ # User Object. Contains user attributes which are used for evaluating targeting rules and percentage options.
3
3
  class User
4
4
  PREDEFINED = ["Identifier", "Email", "Country"]
5
5
 
6
6
  attr_reader :identifier
7
7
 
8
+ # Initialize a User object.
9
+ # Args:
10
+ # identifier: The unique identifier of the user or session (e.g. email address, primary key, session ID, etc.)
11
+ # email: Email address of the user.
12
+ # country: Country of the user.
13
+ # custom: Custom attributes of the user for advanced targeting rule definitions (e.g. role, subscription type, etc.)
14
+ # All comparators support string values as User Object attribute (in some cases they need to be provided in a
15
+ # specific format though, see below), but some of them also support other types of values. It depends on the
16
+ # comparator how the values will be handled. The following rules apply:
17
+ # Text-based comparators (EQUALS, IS_ONE_OF, etc.)
18
+ # * accept string values,
19
+ # * all other values are automatically converted to string
20
+ # (a warning will be logged but evaluation will continue as normal).
21
+ # SemVer-based comparators (IS_ONE_OF_SEMVER, LESS_THAN_SEMVER, GREATER_THAN_SEMVER, etc.)
22
+ # * accept string values containing a properly formatted, valid semver value,
23
+ # * all other values are considered invalid
24
+ # (a warning will be logged and the currently evaluated targeting rule will be skipped).
25
+ # Number-based comparators (EQUALS_NUMBER, LESS_THAN_NUMBER, GREATER_THAN_OR_EQUAL_NUMBER, etc.)
26
+ # * accept float values and all other numeric values which can safely be converted to float,
27
+ # * accept string values containing a properly formatted, valid float value,
28
+ # * all other values are considered invalid
29
+ # (a warning will be logged and the currently evaluated targeting rule will be skipped).
30
+ # Date time-based comparators (BEFORE_DATETIME / AFTER_DATETIME)
31
+ # * accept datetime values, which are automatically converted to a second-based Unix timestamp
32
+ # (datetime values with naive timezone are considered to be in UTC),
33
+ # * accept float values representing a second-based Unix timestamp
34
+ # and all other numeric values which can safely be converted to float,
35
+ # * accept string values containing a properly formatted, valid float value,
36
+ # * all other values are considered invalid
37
+ # (a warning will be logged and the currently evaluated targeting rule will be skipped).
38
+ # String array-based comparators (ARRAY_CONTAINS_ANY_OF / ARRAY_NOT_CONTAINS_ANY_OF)
39
+ # * accept arrays of strings,
40
+ # * accept string values containing a valid JSON string which can be deserialized to an array of strings,
41
+ # * all other values are considered invalid
42
+ # (a warning will be logged and the currently evaluated targeting rule will be skipped).
8
43
  def initialize(identifier, email: nil, country: nil, custom: nil)
9
44
  @identifier = (!identifier.equal?(nil)) ? identifier : ""
10
45
  @data = { "Identifier" => identifier, "Email" => email, "Country" => country }
@@ -26,10 +61,14 @@ module ConfigCat
26
61
  dump = {
27
62
  'Identifier': @identifier,
28
63
  'Email': @data['Email'],
29
- 'Country': @data['Country'],
30
- 'Custom': @custom,
64
+ 'Country': @data['Country']
31
65
  }
32
- return dump.to_json
66
+ dump.merge!(@custom) if @custom
67
+ filtered_dump = dump.reject { |_, v| v.nil? }
68
+ formatted_dump = filtered_dump.transform_values do |value|
69
+ value.is_a?(DateTime) ? value.strftime('%Y-%m-%dT%H:%M:%S.%L%z') : value
70
+ end
71
+ return JSON.generate(formatted_dump, ascii_only: false, separators: %w[, :])
33
72
  end
34
73
  end
35
74
  end
@@ -3,8 +3,28 @@ module ConfigCat
3
3
  DISTANT_FUTURE = Float::INFINITY
4
4
  DISTANT_PAST = 0
5
5
 
6
+ def self.get_date_time(seconds_since_epoch)
7
+ Time.at(seconds_since_epoch).utc
8
+ end
9
+
6
10
  def self.get_utc_now_seconds_since_epoch
7
- return Time.now.utc.to_f
11
+ Time.now.utc.to_f
12
+ end
13
+
14
+ def self.get_seconds_since_epoch(date_time)
15
+ date_time.to_time.to_f
16
+ end
17
+
18
+ def self.is_string_list(value)
19
+ # Check if the value is an Array
20
+ return false unless value.is_a?(Array)
21
+
22
+ # Check if all elements in the Array are Strings
23
+ value.each do |item|
24
+ return false unless item.is_a?(String)
25
+ end
26
+
27
+ return true
8
28
  end
9
29
  end
10
30
  end
@@ -1,3 +1,3 @@
1
1
  module ConfigCat
2
- VERSION = "6.1.0"
2
+ VERSION = "8.0.0"
3
3
  end
data/lib/configcat.rb CHANGED
@@ -24,164 +24,4 @@ module ConfigCat
24
24
  def ConfigCat.close_all
25
25
  ConfigCatClient.close_all
26
26
  end
27
-
28
- def ConfigCat.create_client(sdk_key, data_governance: DataGovernance::GLOBAL)
29
- #
30
- # Create an instance of ConfigCatClient and setup Auto Poll mode with default options
31
- #
32
- # :param sdk_key: ConfigCat SDK Key to access your configuration.
33
- # :param data_governance:
34
- # Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard:
35
- # https://app.configcat.com/organization/data-governance
36
- # (Only Organization Admins have access)
37
- #
38
- return create_client_with_auto_poll(sdk_key, data_governance: data_governance)
39
- end
40
-
41
- # Create an instance of ConfigCatClient and setup Auto Poll mode with custom options
42
- #
43
- # :param sdk_key: ConfigCat SDK Key to access your configuration.
44
- # :param poll_interval_seconds: The client's poll interval in seconds. Default: 60 seconds.
45
- # :param on_configuration_changed_callback: You can subscribe to configuration changes with this callback
46
- # :param max_init_wait_time_seconds: maximum waiting time for first configuration fetch in polling mode.
47
- # :param config_cache: If you want to use custom caching instead of the client's default,
48
- # You can provide an implementation of ConfigCache.
49
- # :param base_url: You can set a base_url if you want to use a proxy server between your application and ConfigCat
50
- # :param proxy_address: Proxy address
51
- # :param proxy_port: Proxy port
52
- # :param proxy_user: username for proxy authentication
53
- # :param proxy_pass: password for proxy authentication
54
- # :param open_timeout_seconds: The number of seconds to wait for the server to make the initial connection. Default: 10 seconds.
55
- # :param read_timeout_seconds: The number of seconds to wait for the server to respond before giving up. Default: 30 seconds.
56
- # :param flag_overrides: A FlagOverrides implementation used to override feature flags & settings.
57
- # :param data_governance:
58
- # Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard:
59
- # https://app.configcat.com/organization/data-governance
60
- # (Only Organization Admins have access)
61
- def ConfigCat.create_client_with_auto_poll(sdk_key,
62
- poll_interval_seconds: 60,
63
- max_init_wait_time_seconds: 5,
64
- on_configuration_changed_callback: nil,
65
- config_cache: nil,
66
- base_url: nil,
67
- proxy_address: nil,
68
- proxy_port: nil,
69
- proxy_user: nil,
70
- proxy_pass: nil,
71
- open_timeout_seconds: 10,
72
- read_timeout_seconds: 30,
73
- flag_overrides: nil,
74
- data_governance: DataGovernance::GLOBAL)
75
- options = ConfigCatOptions.new(
76
- base_url: base_url,
77
- polling_mode: PollingMode.auto_poll(poll_interval_seconds: poll_interval_seconds, max_init_wait_time_seconds: max_init_wait_time_seconds),
78
- config_cache: config_cache,
79
- proxy_address: proxy_address,
80
- proxy_port: proxy_port,
81
- proxy_user: proxy_user,
82
- proxy_pass: proxy_pass,
83
- open_timeout_seconds: open_timeout_seconds,
84
- read_timeout_seconds: read_timeout_seconds,
85
- flag_overrides: flag_overrides,
86
- data_governance: data_governance
87
- )
88
- ConfigCat.logger.warn('create_client_with_auto_poll is deprecated. Create the ConfigCat Client as a Singleton object with `configcatclient.get()` instead')
89
- client = ConfigCatClient.get(sdk_key, options)
90
- client.hooks.add_on_config_changed(on_configuration_changed_callback) if on_configuration_changed_callback
91
- return client
92
- end
93
-
94
- # Create an instance of ConfigCatClient and setup Lazy Load mode with custom options
95
- #
96
- # :param sdk_key: ConfigCat SDK Key to access your configuration.
97
- # :param cache_time_to_live_seconds: The cache TTL.
98
- # :param config_cache: If you want to use custom caching instead of the client's default,
99
- # You can provide an implementation of ConfigCache.
100
- # :param base_url: You can set a base_url if you want to use a proxy server between your application and ConfigCat
101
- # :param proxy_address: Proxy address
102
- # :param proxy_port: Proxy port
103
- # :param proxy_user: username for proxy authentication
104
- # :param proxy_pass: password for proxy authentication
105
- # :param open_timeout_seconds: The number of seconds to wait for the server to make the initial connection. Default: 10 seconds.
106
- # :param read_timeout_seconds: The number of seconds to wait for the server to respond before giving up. Default: 30 seconds.
107
- # :param flag_overrides: A FlagOverrides implementation used to override feature flags & settings.
108
- # :param data_governance:
109
- # Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard:
110
- # https://app.configcat.com/organization/data-governance
111
- # (Only Organization Admins have access)
112
- def ConfigCat.create_client_with_lazy_load(sdk_key,
113
- cache_time_to_live_seconds: 60,
114
- config_cache: nil,
115
- base_url: nil,
116
- proxy_address: nil,
117
- proxy_port: nil,
118
- proxy_user: nil,
119
- proxy_pass: nil,
120
- open_timeout_seconds: 10,
121
- read_timeout_seconds: 30,
122
- flag_overrides: nil,
123
- data_governance: DataGovernance::GLOBAL)
124
- options = ConfigCatOptions.new(
125
- base_url: base_url,
126
- polling_mode: PollingMode.lazy_load(cache_refresh_interval_seconds: cache_time_to_live_seconds),
127
- config_cache: config_cache,
128
- proxy_address: proxy_address,
129
- proxy_port: proxy_port,
130
- proxy_user: proxy_user,
131
- proxy_pass: proxy_pass,
132
- open_timeout_seconds: open_timeout_seconds,
133
- read_timeout_seconds: read_timeout_seconds,
134
- flag_overrides: flag_overrides,
135
- data_governance: data_governance
136
- )
137
- ConfigCat.logger.warn('create_client_with_lazy_load is deprecated. Create the ConfigCat Client as a Singleton object with `configcatclient.get()` instead')
138
- client = ConfigCatClient.get(sdk_key, options)
139
- return client
140
- end
141
-
142
- # Create an instance of ConfigCatClient and setup Manual Poll mode with custom options
143
- #
144
- # :param sdk_key: ConfigCat SDK Key to access your configuration.
145
- # :param config_cache: If you want to use custom caching instead of the client's default,
146
- # You can provide an implementation of ConfigCache.
147
- # :param base_url: You can set a base_url if you want to use a proxy server between your application and ConfigCat
148
- # :param proxy_address: Proxy address
149
- # :param proxy_port: Proxy port
150
- # :param proxy_user: username for proxy authentication
151
- # :param proxy_pass: password for proxy authentication
152
- # :param open_timeout_seconds: The number of seconds to wait for the server to make the initial connection. Default: 10 seconds.
153
- # :param read_timeout_seconds: The number of seconds to wait for the server to respond before giving up. Default: 30 seconds.
154
- # :param flag_overrides: A FlagOverrides implementation used to override feature flags & settings.
155
- # :param data_governance:
156
- # Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard:
157
- # https://app.configcat.com/organization/data-governance
158
- # (Only Organization Admins have access)
159
- def ConfigCat.create_client_with_manual_poll(sdk_key,
160
- config_cache: nil,
161
- base_url: nil,
162
- proxy_address: nil,
163
- proxy_port: nil,
164
- proxy_user: nil,
165
- proxy_pass: nil,
166
- open_timeout_seconds: 10,
167
- read_timeout_seconds: 30,
168
- flag_overrides: nil,
169
- data_governance: DataGovernance::GLOBAL)
170
- options = ConfigCatOptions.new(
171
- base_url: base_url,
172
- polling_mode: PollingMode.manual_poll(),
173
- config_cache: config_cache,
174
- proxy_address: proxy_address,
175
- proxy_port: proxy_port,
176
- proxy_user: proxy_user,
177
- proxy_pass: proxy_pass,
178
- open_timeout_seconds: open_timeout_seconds,
179
- read_timeout_seconds: read_timeout_seconds,
180
- flag_overrides: flag_overrides,
181
- data_governance: data_governance
182
- )
183
- ConfigCat.logger.warn('create_client_with_manual_poll is deprecated. Create the ConfigCat Client as a Singleton object with `configcatclient.get()` instead')
184
- client = ConfigCatClient.get(sdk_key, options)
185
- return client
186
- end
187
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configcat
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.0
4
+ version: 8.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ConfigCat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-23 00:00:00.000000000 Z
11
+ date: 2024-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -120,6 +120,7 @@ extensions: []
120
120
  extra_rdoc_files: []
121
121
  files:
122
122
  - lib/configcat.rb
123
+ - lib/configcat/config.rb
123
124
  - lib/configcat/configcache.rb
124
125
  - lib/configcat/configcatclient.rb
125
126
  - lib/configcat/configcatlogger.rb
@@ -127,9 +128,10 @@ files:
127
128
  - lib/configcat/configentry.rb
128
129
  - lib/configcat/configfetcher.rb
129
130
  - lib/configcat/configservice.rb
130
- - lib/configcat/constants.rb
131
131
  - lib/configcat/datagovernance.rb
132
+ - lib/configcat/evaluationcontext.rb
132
133
  - lib/configcat/evaluationdetails.rb
134
+ - lib/configcat/evaluationlogbuilder.rb
133
135
  - lib/configcat/interfaces.rb
134
136
  - lib/configcat/localdictionarydatasource.rb
135
137
  - lib/configcat/localfiledatasource.rb
@@ -1,17 +0,0 @@
1
- module ConfigCat
2
- CONFIG_FILE_NAME = "config_v5"
3
-
4
- PREFERENCES = "p"
5
- BASE_URL = "u"
6
- REDIRECT = "r"
7
-
8
- FEATURE_FLAGS = "f"
9
- VALUE = "v"
10
- COMPARATOR = "t"
11
- COMPARISON_ATTRIBUTE = "a"
12
- COMPARISON_VALUE = "c"
13
- ROLLOUT_PERCENTAGE_ITEMS = "p"
14
- PERCENTAGE = "p"
15
- ROLLOUT_RULES = "r"
16
- VARIATION_ID = "i"
17
- end