optimizely-sdk 3.10.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +202 -202
  3. data/lib/optimizely/audience.rb +127 -97
  4. data/lib/optimizely/bucketer.rb +156 -156
  5. data/lib/optimizely/condition_tree_evaluator.rb +123 -123
  6. data/lib/optimizely/config/datafile_project_config.rb +539 -552
  7. data/lib/optimizely/config/proxy_config.rb +34 -34
  8. data/lib/optimizely/config_manager/async_scheduler.rb +95 -95
  9. data/lib/optimizely/config_manager/http_project_config_manager.rb +330 -329
  10. data/lib/optimizely/config_manager/project_config_manager.rb +24 -24
  11. data/lib/optimizely/config_manager/static_project_config_manager.rb +53 -52
  12. data/lib/optimizely/decide/optimizely_decide_option.rb +28 -28
  13. data/lib/optimizely/decide/optimizely_decision.rb +60 -60
  14. data/lib/optimizely/decide/optimizely_decision_message.rb +26 -26
  15. data/lib/optimizely/decision_service.rb +563 -563
  16. data/lib/optimizely/error_handler.rb +39 -39
  17. data/lib/optimizely/event/batch_event_processor.rb +235 -234
  18. data/lib/optimizely/event/entity/conversion_event.rb +44 -43
  19. data/lib/optimizely/event/entity/decision.rb +38 -38
  20. data/lib/optimizely/event/entity/event_batch.rb +86 -86
  21. data/lib/optimizely/event/entity/event_context.rb +50 -50
  22. data/lib/optimizely/event/entity/impression_event.rb +48 -47
  23. data/lib/optimizely/event/entity/snapshot.rb +33 -33
  24. data/lib/optimizely/event/entity/snapshot_event.rb +48 -48
  25. data/lib/optimizely/event/entity/user_event.rb +22 -22
  26. data/lib/optimizely/event/entity/visitor.rb +36 -35
  27. data/lib/optimizely/event/entity/visitor_attribute.rb +38 -37
  28. data/lib/optimizely/event/event_factory.rb +156 -155
  29. data/lib/optimizely/event/event_processor.rb +25 -25
  30. data/lib/optimizely/event/forwarding_event_processor.rb +44 -43
  31. data/lib/optimizely/event/user_event_factory.rb +88 -88
  32. data/lib/optimizely/event_builder.rb +221 -228
  33. data/lib/optimizely/event_dispatcher.rb +71 -71
  34. data/lib/optimizely/exceptions.rb +135 -139
  35. data/lib/optimizely/helpers/constants.rb +415 -397
  36. data/lib/optimizely/helpers/date_time_utils.rb +30 -30
  37. data/lib/optimizely/helpers/event_tag_utils.rb +132 -132
  38. data/lib/optimizely/helpers/group.rb +31 -31
  39. data/lib/optimizely/helpers/http_utils.rb +65 -64
  40. data/lib/optimizely/helpers/validator.rb +183 -183
  41. data/lib/optimizely/helpers/variable_type.rb +67 -67
  42. data/lib/optimizely/logger.rb +46 -45
  43. data/lib/optimizely/notification_center.rb +174 -176
  44. data/lib/optimizely/optimizely_config.rb +271 -272
  45. data/lib/optimizely/optimizely_factory.rb +181 -181
  46. data/lib/optimizely/optimizely_user_context.rb +204 -179
  47. data/lib/optimizely/params.rb +31 -31
  48. data/lib/optimizely/project_config.rb +99 -91
  49. data/lib/optimizely/semantic_version.rb +166 -166
  50. data/lib/optimizely/{custom_attribute_condition_evaluator.rb → user_condition_evaluator.rb} +391 -369
  51. data/lib/optimizely/user_profile_service.rb +35 -35
  52. data/lib/optimizely/version.rb +21 -21
  53. data/lib/optimizely.rb +1130 -1145
  54. metadata +13 -13
@@ -1,181 +1,181 @@
1
- # frozen_string_literal: true
2
-
3
- #
4
- # Copyright 2019, Optimizely and contributors
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require 'optimizely'
20
- require 'optimizely/error_handler'
21
- require 'optimizely/event_dispatcher'
22
- require 'optimizely/event/batch_event_processor'
23
- require 'optimizely/logger'
24
- require 'optimizely/notification_center'
25
-
26
- module Optimizely
27
- class OptimizelyFactory
28
- # Convenience method for setting the maximum number of events contained within a batch.
29
- # @param batch_size Integer - Sets size of EventQueue.
30
- # @param logger - Optional LoggerInterface Provides a log method to log messages.
31
- def self.max_event_batch_size(batch_size, logger = NoOpLogger.new)
32
- unless batch_size.is_a? Integer
33
- logger.log(
34
- Logger::ERROR,
35
- "Batch size is invalid, setting to default batch size #{BatchEventProcessor::DEFAULT_BATCH_SIZE}."
36
- )
37
- return
38
- end
39
-
40
- unless batch_size.positive?
41
- logger.log(
42
- Logger::ERROR,
43
- "Batch size is negative, setting to default batch size #{BatchEventProcessor::DEFAULT_BATCH_SIZE}."
44
- )
45
- return
46
- end
47
- @max_event_batch_size = batch_size
48
- end
49
-
50
- # Convenience method for setting the maximum time interval in milliseconds between event dispatches.
51
- # @param flush_interval Numeric - Time interval between event dispatches.
52
- # @param logger - Optional LoggerInterface Provides a log method to log messages.
53
- def self.max_event_flush_interval(flush_interval, logger = NoOpLogger.new)
54
- unless flush_interval.is_a? Numeric
55
- logger.log(
56
- Logger::ERROR,
57
- "Flush interval is invalid, setting to default flush interval #{BatchEventProcessor::DEFAULT_BATCH_INTERVAL}."
58
- )
59
- return
60
- end
61
-
62
- unless flush_interval.positive?
63
- logger.log(
64
- Logger::ERROR,
65
- "Flush interval is negative, setting to default flush interval #{BatchEventProcessor::DEFAULT_BATCH_INTERVAL}."
66
- )
67
- return
68
- end
69
- @max_event_flush_interval = flush_interval
70
- end
71
-
72
- # Convenience method for setting frequency at which datafile has to be polled and ProjectConfig updated.
73
- #
74
- # @param polling_interval Numeric - Time in seconds after which to update datafile.
75
- def self.polling_interval(polling_interval)
76
- @polling_interval = polling_interval
77
- end
78
-
79
- # Convenience method for setting timeout to block the config call until config has been initialized.
80
- #
81
- # @param blocking_timeout Numeric - Time in seconds.
82
- def self.blocking_timeout(blocking_timeout)
83
- @blocking_timeout = blocking_timeout
84
- end
85
-
86
- # Returns a new optimizely instance.
87
- #
88
- # @params sdk_key - Required String uniquely identifying the fallback datafile corresponding to project.
89
- # @param fallback datafile - Optional JSON string datafile.
90
- def self.default_instance(sdk_key, datafile = nil)
91
- error_handler = NoOpErrorHandler.new
92
- logger = NoOpLogger.new
93
- notification_center = NotificationCenter.new(logger, error_handler)
94
-
95
- config_manager = Optimizely::HTTPProjectConfigManager.new(
96
- sdk_key: sdk_key,
97
- polling_interval: @polling_interval,
98
- blocking_timeout: @blocking_timeout,
99
- datafile: datafile,
100
- logger: logger,
101
- error_handler: error_handler,
102
- notification_center: notification_center
103
- )
104
-
105
- Optimizely::Project.new(
106
- datafile, nil, logger, error_handler, nil, nil, sdk_key, config_manager, notification_center
107
- )
108
- end
109
-
110
- # Returns a new optimizely instance.
111
- #
112
- # @param config_manager - Required ConfigManagerInterface Responds to 'config' method.
113
- def self.default_instance_with_config_manager(config_manager)
114
- Optimizely::Project.new(nil, nil, nil, nil, nil, nil, nil, config_manager)
115
- end
116
-
117
- # Returns a new optimizely instance.
118
- #
119
- # @params sdk_key - Required String uniquely identifying the datafile corresponding to project.
120
- # @param fallback datafile - Optional JSON string datafile.
121
- # @param event_dispatcher - Optional EventDispatcherInterface Provides a dispatch_event method which if given a URL and params sends a request to it.
122
- # @param logger - Optional LoggerInterface Provides a log method to log messages. By default nothing would be logged.
123
- # @param error_handler - Optional ErrorHandlerInterface which provides a handle_error method to handle exceptions.
124
- # By default all exceptions will be suppressed.
125
- # @param skip_json_validation - Optional Boolean param to skip JSON schema validation of the provided datafile.
126
- # @param user_profile_service - Optional UserProfileServiceInterface Provides methods to store and retreive user profiles.
127
- # @param config_manager - Optional ConfigManagerInterface Responds to 'config' method.
128
- # @param notification_center - Optional Instance of NotificationCenter.
129
- #
130
- # if @max_event_batch_size and @max_event_flush_interval are nil then default batchsize and flush_interval
131
- # will be used to setup batchEventProcessor.
132
- def self.custom_instance(
133
- sdk_key,
134
- datafile = nil,
135
- event_dispatcher = nil,
136
- logger = nil,
137
- error_handler = nil,
138
- skip_json_validation = false,
139
- user_profile_service = nil,
140
- config_manager = nil,
141
- notification_center = nil
142
- )
143
-
144
- error_handler ||= NoOpErrorHandler.new
145
- logger ||= NoOpLogger.new
146
- notification_center = notification_center.is_a?(Optimizely::NotificationCenter) ? notification_center : NotificationCenter.new(logger, error_handler)
147
-
148
- event_processor = BatchEventProcessor.new(
149
- event_dispatcher: event_dispatcher || EventDispatcher.new,
150
- batch_size: @max_event_batch_size,
151
- flush_interval: @max_event_flush_interval,
152
- logger: logger,
153
- notification_center: notification_center
154
- )
155
-
156
- config_manager ||= Optimizely::HTTPProjectConfigManager.new(
157
- sdk_key: sdk_key,
158
- polling_interval: @polling_interval,
159
- blocking_timeout: @blocking_timeout,
160
- datafile: datafile,
161
- logger: logger,
162
- error_handler: error_handler,
163
- skip_json_validation: skip_json_validation,
164
- notification_center: notification_center
165
- )
166
-
167
- Optimizely::Project.new(
168
- datafile,
169
- event_dispatcher,
170
- logger,
171
- error_handler,
172
- skip_json_validation,
173
- user_profile_service,
174
- sdk_key,
175
- config_manager,
176
- notification_center,
177
- event_processor
178
- )
179
- end
180
- end
181
- end
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright 2019, 2022, Optimizely and contributors
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'optimizely'
20
+ require 'optimizely/error_handler'
21
+ require 'optimizely/event_dispatcher'
22
+ require 'optimizely/event/batch_event_processor'
23
+ require 'optimizely/logger'
24
+ require 'optimizely/notification_center'
25
+
26
+ module Optimizely
27
+ class OptimizelyFactory
28
+ # Convenience method for setting the maximum number of events contained within a batch.
29
+ # @param batch_size Integer - Sets size of EventQueue.
30
+ # @param logger - Optional LoggerInterface Provides a log method to log messages.
31
+ def self.max_event_batch_size(batch_size, logger = NoOpLogger.new)
32
+ unless batch_size.is_a? Integer
33
+ logger.log(
34
+ Logger::ERROR,
35
+ "Batch size is invalid, setting to default batch size #{BatchEventProcessor::DEFAULT_BATCH_SIZE}."
36
+ )
37
+ return
38
+ end
39
+
40
+ unless batch_size.positive?
41
+ logger.log(
42
+ Logger::ERROR,
43
+ "Batch size is negative, setting to default batch size #{BatchEventProcessor::DEFAULT_BATCH_SIZE}."
44
+ )
45
+ return
46
+ end
47
+ @max_event_batch_size = batch_size
48
+ end
49
+
50
+ # Convenience method for setting the maximum time interval in milliseconds between event dispatches.
51
+ # @param flush_interval Numeric - Time interval between event dispatches.
52
+ # @param logger - Optional LoggerInterface Provides a log method to log messages.
53
+ def self.max_event_flush_interval(flush_interval, logger = NoOpLogger.new)
54
+ unless flush_interval.is_a? Numeric
55
+ logger.log(
56
+ Logger::ERROR,
57
+ "Flush interval is invalid, setting to default flush interval #{BatchEventProcessor::DEFAULT_BATCH_INTERVAL}."
58
+ )
59
+ return
60
+ end
61
+
62
+ unless flush_interval.positive?
63
+ logger.log(
64
+ Logger::ERROR,
65
+ "Flush interval is negative, setting to default flush interval #{BatchEventProcessor::DEFAULT_BATCH_INTERVAL}."
66
+ )
67
+ return
68
+ end
69
+ @max_event_flush_interval = flush_interval
70
+ end
71
+
72
+ # Convenience method for setting frequency at which datafile has to be polled and ProjectConfig updated.
73
+ #
74
+ # @param polling_interval Numeric - Time in seconds after which to update datafile.
75
+ def self.polling_interval(polling_interval)
76
+ @polling_interval = polling_interval
77
+ end
78
+
79
+ # Convenience method for setting timeout to block the config call until config has been initialized.
80
+ #
81
+ # @param blocking_timeout Numeric - Time in seconds.
82
+ def self.blocking_timeout(blocking_timeout)
83
+ @blocking_timeout = blocking_timeout
84
+ end
85
+
86
+ # Returns a new optimizely instance.
87
+ #
88
+ # @params sdk_key - Required String uniquely identifying the fallback datafile corresponding to project.
89
+ # @param fallback datafile - Optional JSON string datafile.
90
+ def self.default_instance(sdk_key, datafile = nil)
91
+ error_handler = NoOpErrorHandler.new
92
+ logger = NoOpLogger.new
93
+ notification_center = NotificationCenter.new(logger, error_handler)
94
+
95
+ config_manager = Optimizely::HTTPProjectConfigManager.new(
96
+ sdk_key: sdk_key,
97
+ polling_interval: @polling_interval,
98
+ blocking_timeout: @blocking_timeout,
99
+ datafile: datafile,
100
+ logger: logger,
101
+ error_handler: error_handler,
102
+ notification_center: notification_center
103
+ )
104
+
105
+ Optimizely::Project.new(
106
+ datafile, nil, logger, error_handler, nil, nil, sdk_key, config_manager, notification_center
107
+ )
108
+ end
109
+
110
+ # Returns a new optimizely instance.
111
+ #
112
+ # @param config_manager - Required ConfigManagerInterface Responds to 'config' method.
113
+ def self.default_instance_with_config_manager(config_manager)
114
+ Optimizely::Project.new(nil, nil, nil, nil, nil, nil, nil, config_manager)
115
+ end
116
+
117
+ # Returns a new optimizely instance.
118
+ #
119
+ # @params sdk_key - Required String uniquely identifying the datafile corresponding to project.
120
+ # @param fallback datafile - Optional JSON string datafile.
121
+ # @param event_dispatcher - Optional EventDispatcherInterface Provides a dispatch_event method which if given a URL and params sends a request to it.
122
+ # @param logger - Optional LoggerInterface Provides a log method to log messages. By default nothing would be logged.
123
+ # @param error_handler - Optional ErrorHandlerInterface which provides a handle_error method to handle exceptions.
124
+ # By default all exceptions will be suppressed.
125
+ # @param skip_json_validation - Optional Boolean param to skip JSON schema validation of the provided datafile.
126
+ # @param user_profile_service - Optional UserProfileServiceInterface Provides methods to store and retreive user profiles.
127
+ # @param config_manager - Optional ConfigManagerInterface Responds to 'config' method.
128
+ # @param notification_center - Optional Instance of NotificationCenter.
129
+ #
130
+ # if @max_event_batch_size and @max_event_flush_interval are nil then default batchsize and flush_interval
131
+ # will be used to setup batchEventProcessor.
132
+ def self.custom_instance( # rubocop:disable Metrics/ParameterLists
133
+ sdk_key,
134
+ datafile = nil,
135
+ event_dispatcher = nil,
136
+ logger = nil,
137
+ error_handler = nil,
138
+ skip_json_validation = false, # rubocop:disable Style/OptionalBooleanParameter
139
+ user_profile_service = nil,
140
+ config_manager = nil,
141
+ notification_center = nil
142
+ )
143
+
144
+ error_handler ||= NoOpErrorHandler.new
145
+ logger ||= NoOpLogger.new
146
+ notification_center = notification_center.is_a?(Optimizely::NotificationCenter) ? notification_center : NotificationCenter.new(logger, error_handler)
147
+
148
+ event_processor = BatchEventProcessor.new(
149
+ event_dispatcher: event_dispatcher || EventDispatcher.new,
150
+ batch_size: @max_event_batch_size,
151
+ flush_interval: @max_event_flush_interval,
152
+ logger: logger,
153
+ notification_center: notification_center
154
+ )
155
+
156
+ config_manager ||= Optimizely::HTTPProjectConfigManager.new(
157
+ sdk_key: sdk_key,
158
+ polling_interval: @polling_interval,
159
+ blocking_timeout: @blocking_timeout,
160
+ datafile: datafile,
161
+ logger: logger,
162
+ error_handler: error_handler,
163
+ skip_json_validation: skip_json_validation,
164
+ notification_center: notification_center
165
+ )
166
+
167
+ Optimizely::Project.new(
168
+ datafile,
169
+ event_dispatcher,
170
+ logger,
171
+ error_handler,
172
+ skip_json_validation,
173
+ user_profile_service,
174
+ sdk_key,
175
+ config_manager,
176
+ notification_center,
177
+ event_processor
178
+ )
179
+ end
180
+ end
181
+ end