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,97 +1,97 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#
|
4
|
-
# Copyright 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/logger'
|
20
|
-
require_relative 'odp_segment_api_manager'
|
21
|
-
|
22
|
-
module Optimizely
|
23
|
-
class OdpSegmentManager
|
24
|
-
# Schedules connections to ODP for audience segmentation and caches the results
|
25
|
-
attr_accessor :odp_config
|
26
|
-
attr_reader :segments_cache, :api_manager, :logger
|
27
|
-
|
28
|
-
def initialize(segments_cache, api_manager = nil, logger = nil, proxy_config = nil, timeout: nil)
|
29
|
-
@odp_config = nil
|
30
|
-
@logger = logger || NoOpLogger.new
|
31
|
-
@api_manager = api_manager || OdpSegmentApiManager.new(logger: @logger, proxy_config: proxy_config, timeout: timeout)
|
32
|
-
@segments_cache = segments_cache
|
33
|
-
end
|
34
|
-
|
35
|
-
# Returns qualified segments for the user from the cache or the ODP server if not in the cache.
|
36
|
-
#
|
37
|
-
# @param user_key - The key for identifying the id type.
|
38
|
-
# @param user_value - The id itself.
|
39
|
-
# @param options - An array of OptimizelySegmentOptions used to ignore and/or reset the cache.
|
40
|
-
#
|
41
|
-
# @return - Array of qualified segments.
|
42
|
-
def fetch_qualified_segments(user_key, user_value, options)
|
43
|
-
odp_api_key = @odp_config&.api_key
|
44
|
-
odp_api_host = @odp_config&.api_host
|
45
|
-
segments_to_check = @odp_config&.segments_to_check
|
46
|
-
|
47
|
-
if odp_api_key.nil? || odp_api_host.nil?
|
48
|
-
@logger.log(Logger::ERROR, format(Optimizely::Helpers::Constants::ODP_LOGS[:FETCH_SEGMENTS_FAILED], 'ODP is not enabled'))
|
49
|
-
return nil
|
50
|
-
end
|
51
|
-
|
52
|
-
unless segments_to_check&.size&.positive?
|
53
|
-
@logger.log(Logger::DEBUG, 'No segments are used in the project. Returning empty list')
|
54
|
-
return []
|
55
|
-
end
|
56
|
-
|
57
|
-
cache_key = make_cache_key(user_key, user_value)
|
58
|
-
|
59
|
-
ignore_cache = options.include?(OptimizelySegmentOption::IGNORE_CACHE)
|
60
|
-
reset_cache = options.include?(OptimizelySegmentOption::RESET_CACHE)
|
61
|
-
|
62
|
-
reset if reset_cache
|
63
|
-
|
64
|
-
unless ignore_cache || reset_cache
|
65
|
-
segments = @segments_cache.lookup(cache_key)
|
66
|
-
unless segments.nil?
|
67
|
-
@logger.log(Logger::DEBUG, 'ODP cache hit. Returning segments from cache.')
|
68
|
-
return segments
|
69
|
-
end
|
70
|
-
@logger.log(Logger::DEBUG, 'ODP cache miss.')
|
71
|
-
end
|
72
|
-
|
73
|
-
@logger.log(Logger::DEBUG, 'Making a call to ODP server.')
|
74
|
-
|
75
|
-
segments = @api_manager.fetch_segments(odp_api_key, odp_api_host, user_key, user_value, segments_to_check)
|
76
|
-
@segments_cache.save(cache_key, segments) unless segments.nil? || ignore_cache
|
77
|
-
segments
|
78
|
-
end
|
79
|
-
|
80
|
-
def reset
|
81
|
-
@segments_cache.reset
|
82
|
-
nil
|
83
|
-
end
|
84
|
-
|
85
|
-
private
|
86
|
-
|
87
|
-
def make_cache_key(user_key, user_value)
|
88
|
-
"#{user_key}-$-#{user_value}"
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class OptimizelySegmentOption
|
93
|
-
# Options for the OdpSegmentManager
|
94
|
-
IGNORE_CACHE = :IGNORE_CACHE
|
95
|
-
RESET_CACHE = :RESET_CACHE
|
96
|
-
end
|
97
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright 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/logger'
|
20
|
+
require_relative 'odp_segment_api_manager'
|
21
|
+
|
22
|
+
module Optimizely
|
23
|
+
class OdpSegmentManager
|
24
|
+
# Schedules connections to ODP for audience segmentation and caches the results
|
25
|
+
attr_accessor :odp_config
|
26
|
+
attr_reader :segments_cache, :api_manager, :logger
|
27
|
+
|
28
|
+
def initialize(segments_cache, api_manager = nil, logger = nil, proxy_config = nil, timeout: nil)
|
29
|
+
@odp_config = nil
|
30
|
+
@logger = logger || NoOpLogger.new
|
31
|
+
@api_manager = api_manager || OdpSegmentApiManager.new(logger: @logger, proxy_config: proxy_config, timeout: timeout)
|
32
|
+
@segments_cache = segments_cache
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns qualified segments for the user from the cache or the ODP server if not in the cache.
|
36
|
+
#
|
37
|
+
# @param user_key - The key for identifying the id type.
|
38
|
+
# @param user_value - The id itself.
|
39
|
+
# @param options - An array of OptimizelySegmentOptions used to ignore and/or reset the cache.
|
40
|
+
#
|
41
|
+
# @return - Array of qualified segments.
|
42
|
+
def fetch_qualified_segments(user_key, user_value, options)
|
43
|
+
odp_api_key = @odp_config&.api_key
|
44
|
+
odp_api_host = @odp_config&.api_host
|
45
|
+
segments_to_check = @odp_config&.segments_to_check
|
46
|
+
|
47
|
+
if odp_api_key.nil? || odp_api_host.nil?
|
48
|
+
@logger.log(Logger::ERROR, format(Optimizely::Helpers::Constants::ODP_LOGS[:FETCH_SEGMENTS_FAILED], 'ODP is not enabled'))
|
49
|
+
return nil
|
50
|
+
end
|
51
|
+
|
52
|
+
unless segments_to_check&.size&.positive?
|
53
|
+
@logger.log(Logger::DEBUG, 'No segments are used in the project. Returning empty list')
|
54
|
+
return []
|
55
|
+
end
|
56
|
+
|
57
|
+
cache_key = make_cache_key(user_key, user_value)
|
58
|
+
|
59
|
+
ignore_cache = options.include?(OptimizelySegmentOption::IGNORE_CACHE)
|
60
|
+
reset_cache = options.include?(OptimizelySegmentOption::RESET_CACHE)
|
61
|
+
|
62
|
+
reset if reset_cache
|
63
|
+
|
64
|
+
unless ignore_cache || reset_cache
|
65
|
+
segments = @segments_cache.lookup(cache_key)
|
66
|
+
unless segments.nil?
|
67
|
+
@logger.log(Logger::DEBUG, 'ODP cache hit. Returning segments from cache.')
|
68
|
+
return segments
|
69
|
+
end
|
70
|
+
@logger.log(Logger::DEBUG, 'ODP cache miss.')
|
71
|
+
end
|
72
|
+
|
73
|
+
@logger.log(Logger::DEBUG, 'Making a call to ODP server.')
|
74
|
+
|
75
|
+
segments = @api_manager.fetch_segments(odp_api_key, odp_api_host, user_key, user_value, segments_to_check)
|
76
|
+
@segments_cache.save(cache_key, segments) unless segments.nil? || ignore_cache
|
77
|
+
segments
|
78
|
+
end
|
79
|
+
|
80
|
+
def reset
|
81
|
+
@segments_cache.reset
|
82
|
+
nil
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def make_cache_key(user_key, user_value)
|
88
|
+
"#{user_key}-$-#{user_value}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
class OptimizelySegmentOption
|
93
|
+
# Options for the OdpSegmentManager
|
94
|
+
IGNORE_CACHE = :IGNORE_CACHE
|
95
|
+
RESET_CACHE = :RESET_CACHE
|
96
|
+
end
|
97
|
+
end
|