optimizely-sdk 5.0.0 → 5.0.1
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/LICENSE +202 -202
- data/lib/optimizely/audience.rb +127 -127
- data/lib/optimizely/bucketer.rb +156 -156
- data/lib/optimizely/condition_tree_evaluator.rb +123 -123
- data/lib/optimizely/config/datafile_project_config.rb +558 -558
- data/lib/optimizely/config/proxy_config.rb +34 -34
- data/lib/optimizely/config_manager/async_scheduler.rb +95 -95
- data/lib/optimizely/config_manager/http_project_config_manager.rb +340 -340
- data/lib/optimizely/config_manager/project_config_manager.rb +25 -25
- data/lib/optimizely/config_manager/static_project_config_manager.rb +55 -55
- data/lib/optimizely/decide/optimizely_decide_option.rb +28 -28
- data/lib/optimizely/decide/optimizely_decision.rb +60 -60
- data/lib/optimizely/decide/optimizely_decision_message.rb +26 -26
- data/lib/optimizely/decision_service.rb +563 -563
- data/lib/optimizely/error_handler.rb +39 -39
- data/lib/optimizely/event/batch_event_processor.rb +235 -235
- data/lib/optimizely/event/entity/conversion_event.rb +44 -44
- data/lib/optimizely/event/entity/decision.rb +38 -38
- data/lib/optimizely/event/entity/event_batch.rb +86 -86
- data/lib/optimizely/event/entity/event_context.rb +50 -50
- data/lib/optimizely/event/entity/impression_event.rb +48 -48
- data/lib/optimizely/event/entity/snapshot.rb +33 -33
- data/lib/optimizely/event/entity/snapshot_event.rb +48 -48
- data/lib/optimizely/event/entity/user_event.rb +22 -22
- data/lib/optimizely/event/entity/visitor.rb +36 -36
- data/lib/optimizely/event/entity/visitor_attribute.rb +38 -38
- data/lib/optimizely/event/event_factory.rb +156 -156
- data/lib/optimizely/event/event_processor.rb +25 -25
- data/lib/optimizely/event/forwarding_event_processor.rb +44 -44
- data/lib/optimizely/event/user_event_factory.rb +88 -88
- data/lib/optimizely/event_builder.rb +221 -221
- data/lib/optimizely/event_dispatcher.rb +69 -69
- data/lib/optimizely/exceptions.rb +193 -193
- data/lib/optimizely/helpers/constants.rb +459 -459
- data/lib/optimizely/helpers/date_time_utils.rb +30 -30
- data/lib/optimizely/helpers/event_tag_utils.rb +132 -132
- data/lib/optimizely/helpers/group.rb +31 -31
- data/lib/optimizely/helpers/http_utils.rb +68 -68
- data/lib/optimizely/helpers/sdk_settings.rb +61 -61
- data/lib/optimizely/helpers/validator.rb +236 -236
- data/lib/optimizely/helpers/variable_type.rb +67 -67
- data/lib/optimizely/logger.rb +46 -46
- data/lib/optimizely/notification_center.rb +174 -174
- data/lib/optimizely/notification_center_registry.rb +71 -71
- data/lib/optimizely/odp/lru_cache.rb +114 -114
- data/lib/optimizely/odp/odp_config.rb +102 -102
- data/lib/optimizely/odp/odp_event.rb +75 -75
- data/lib/optimizely/odp/odp_event_api_manager.rb +70 -70
- data/lib/optimizely/odp/odp_event_manager.rb +286 -286
- data/lib/optimizely/odp/odp_manager.rb +159 -159
- data/lib/optimizely/odp/odp_segment_api_manager.rb +122 -122
- data/lib/optimizely/odp/odp_segment_manager.rb +97 -97
- data/lib/optimizely/optimizely_config.rb +273 -273
- data/lib/optimizely/optimizely_factory.rb +184 -184
- data/lib/optimizely/optimizely_user_context.rb +238 -238
- data/lib/optimizely/params.rb +31 -31
- data/lib/optimizely/project_config.rb +99 -99
- data/lib/optimizely/semantic_version.rb +166 -166
- data/lib/optimizely/user_condition_evaluator.rb +391 -391
- data/lib/optimizely/user_profile_service.rb +35 -35
- data/lib/optimizely/version.rb +21 -21
- data/lib/optimizely.rb +1262 -1262
- metadata +7 -5
@@ -1,184 +1,184 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#
|
4
|
-
# Copyright 2019, 2022-2023, 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: datafile, logger: logger, error_handler: error_handler, sdk_key: sdk_key, config_manager: config_manager, notification_center: 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(config_manager: 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
|
-
# @param settings: Optional instance of OptimizelySdkSettings for sdk configuration.
|
130
|
-
#
|
131
|
-
# if @max_event_batch_size and @max_event_flush_interval are nil then default batchsize and flush_interval
|
132
|
-
# will be used to setup batchEventProcessor.
|
133
|
-
def self.custom_instance( # rubocop:disable Metrics/ParameterLists
|
134
|
-
sdk_key,
|
135
|
-
datafile = nil,
|
136
|
-
event_dispatcher = nil,
|
137
|
-
logger = nil,
|
138
|
-
error_handler = nil,
|
139
|
-
skip_json_validation = false, # rubocop:disable Style/OptionalBooleanParameter
|
140
|
-
user_profile_service = nil,
|
141
|
-
config_manager = nil,
|
142
|
-
notification_center = nil,
|
143
|
-
settings = nil
|
144
|
-
)
|
145
|
-
|
146
|
-
error_handler ||= NoOpErrorHandler.new
|
147
|
-
logger ||= NoOpLogger.new
|
148
|
-
notification_center = notification_center.is_a?(Optimizely::NotificationCenter) ? notification_center : NotificationCenter.new(logger, error_handler)
|
149
|
-
|
150
|
-
event_processor = BatchEventProcessor.new(
|
151
|
-
event_dispatcher: event_dispatcher || EventDispatcher.new,
|
152
|
-
batch_size: @max_event_batch_size,
|
153
|
-
flush_interval: @max_event_flush_interval,
|
154
|
-
logger: logger,
|
155
|
-
notification_center: notification_center
|
156
|
-
)
|
157
|
-
|
158
|
-
config_manager ||= Optimizely::HTTPProjectConfigManager.new(
|
159
|
-
sdk_key: sdk_key,
|
160
|
-
polling_interval: @polling_interval,
|
161
|
-
blocking_timeout: @blocking_timeout,
|
162
|
-
datafile: datafile,
|
163
|
-
logger: logger,
|
164
|
-
error_handler: error_handler,
|
165
|
-
skip_json_validation: skip_json_validation,
|
166
|
-
notification_center: notification_center
|
167
|
-
)
|
168
|
-
|
169
|
-
Optimizely::Project.new(
|
170
|
-
datafile: datafile,
|
171
|
-
event_dispatcher: event_dispatcher,
|
172
|
-
logger: logger,
|
173
|
-
error_handler: error_handler,
|
174
|
-
skip_json_validation: skip_json_validation,
|
175
|
-
user_profile_service: user_profile_service,
|
176
|
-
sdk_key: sdk_key,
|
177
|
-
config_manager: config_manager,
|
178
|
-
notification_center: notification_center,
|
179
|
-
event_processor: event_processor,
|
180
|
-
settings: settings
|
181
|
-
)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright 2019, 2022-2023, 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: datafile, logger: logger, error_handler: error_handler, sdk_key: sdk_key, config_manager: config_manager, notification_center: 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(config_manager: 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
|
+
# @param settings: Optional instance of OptimizelySdkSettings for sdk configuration.
|
130
|
+
#
|
131
|
+
# if @max_event_batch_size and @max_event_flush_interval are nil then default batchsize and flush_interval
|
132
|
+
# will be used to setup batchEventProcessor.
|
133
|
+
def self.custom_instance( # rubocop:disable Metrics/ParameterLists
|
134
|
+
sdk_key,
|
135
|
+
datafile = nil,
|
136
|
+
event_dispatcher = nil,
|
137
|
+
logger = nil,
|
138
|
+
error_handler = nil,
|
139
|
+
skip_json_validation = false, # rubocop:disable Style/OptionalBooleanParameter
|
140
|
+
user_profile_service = nil,
|
141
|
+
config_manager = nil,
|
142
|
+
notification_center = nil,
|
143
|
+
settings = nil
|
144
|
+
)
|
145
|
+
|
146
|
+
error_handler ||= NoOpErrorHandler.new
|
147
|
+
logger ||= NoOpLogger.new
|
148
|
+
notification_center = notification_center.is_a?(Optimizely::NotificationCenter) ? notification_center : NotificationCenter.new(logger, error_handler)
|
149
|
+
|
150
|
+
event_processor = BatchEventProcessor.new(
|
151
|
+
event_dispatcher: event_dispatcher || EventDispatcher.new,
|
152
|
+
batch_size: @max_event_batch_size,
|
153
|
+
flush_interval: @max_event_flush_interval,
|
154
|
+
logger: logger,
|
155
|
+
notification_center: notification_center
|
156
|
+
)
|
157
|
+
|
158
|
+
config_manager ||= Optimizely::HTTPProjectConfigManager.new(
|
159
|
+
sdk_key: sdk_key,
|
160
|
+
polling_interval: @polling_interval,
|
161
|
+
blocking_timeout: @blocking_timeout,
|
162
|
+
datafile: datafile,
|
163
|
+
logger: logger,
|
164
|
+
error_handler: error_handler,
|
165
|
+
skip_json_validation: skip_json_validation,
|
166
|
+
notification_center: notification_center
|
167
|
+
)
|
168
|
+
|
169
|
+
Optimizely::Project.new(
|
170
|
+
datafile: datafile,
|
171
|
+
event_dispatcher: event_dispatcher,
|
172
|
+
logger: logger,
|
173
|
+
error_handler: error_handler,
|
174
|
+
skip_json_validation: skip_json_validation,
|
175
|
+
user_profile_service: user_profile_service,
|
176
|
+
sdk_key: sdk_key,
|
177
|
+
config_manager: config_manager,
|
178
|
+
notification_center: notification_center,
|
179
|
+
event_processor: event_processor,
|
180
|
+
settings: settings
|
181
|
+
)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|