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.
- checksums.yaml +4 -4
- data/LICENSE +202 -202
- data/lib/optimizely/audience.rb +127 -97
- data/lib/optimizely/bucketer.rb +156 -156
- data/lib/optimizely/condition_tree_evaluator.rb +123 -123
- data/lib/optimizely/config/datafile_project_config.rb +539 -552
- 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 +330 -329
- data/lib/optimizely/config_manager/project_config_manager.rb +24 -24
- data/lib/optimizely/config_manager/static_project_config_manager.rb +53 -52
- 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 -234
- data/lib/optimizely/event/entity/conversion_event.rb +44 -43
- 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 -47
- 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 -35
- data/lib/optimizely/event/entity/visitor_attribute.rb +38 -37
- data/lib/optimizely/event/event_factory.rb +156 -155
- data/lib/optimizely/event/event_processor.rb +25 -25
- data/lib/optimizely/event/forwarding_event_processor.rb +44 -43
- data/lib/optimizely/event/user_event_factory.rb +88 -88
- data/lib/optimizely/event_builder.rb +221 -228
- data/lib/optimizely/event_dispatcher.rb +71 -71
- data/lib/optimizely/exceptions.rb +135 -139
- data/lib/optimizely/helpers/constants.rb +415 -397
- 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 +65 -64
- data/lib/optimizely/helpers/validator.rb +183 -183
- data/lib/optimizely/helpers/variable_type.rb +67 -67
- data/lib/optimizely/logger.rb +46 -45
- data/lib/optimizely/notification_center.rb +174 -176
- data/lib/optimizely/optimizely_config.rb +271 -272
- data/lib/optimizely/optimizely_factory.rb +181 -181
- data/lib/optimizely/optimizely_user_context.rb +204 -179
- data/lib/optimizely/params.rb +31 -31
- data/lib/optimizely/project_config.rb +99 -91
- data/lib/optimizely/semantic_version.rb +166 -166
- data/lib/optimizely/{custom_attribute_condition_evaluator.rb → user_condition_evaluator.rb} +391 -369
- data/lib/optimizely/user_profile_service.rb +35 -35
- data/lib/optimizely/version.rb +21 -21
- data/lib/optimizely.rb +1130 -1145
- metadata +13 -13
@@ -1,34 +1,34 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright 2020, Optimizely and contributors
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
#
|
17
|
-
#
|
18
|
-
|
19
|
-
module Optimizely
|
20
|
-
class ProxyConfig
|
21
|
-
attr_reader :host, :port, :username, :password
|
22
|
-
|
23
|
-
def initialize(host, port = nil, username = nil, password = nil)
|
24
|
-
# host - DNS name or IP address of proxy
|
25
|
-
# port - port to use to acess the proxy
|
26
|
-
# username - username if authorization is required
|
27
|
-
# password - password if authorization is required
|
28
|
-
@host = host
|
29
|
-
@port = port
|
30
|
-
@username = username
|
31
|
-
@password = password
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2020, Optimizely and contributors
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
#
|
18
|
+
|
19
|
+
module Optimizely
|
20
|
+
class ProxyConfig
|
21
|
+
attr_reader :host, :port, :username, :password
|
22
|
+
|
23
|
+
def initialize(host, port = nil, username = nil, password = nil)
|
24
|
+
# host - DNS name or IP address of proxy
|
25
|
+
# port - port to use to acess the proxy
|
26
|
+
# username - username if authorization is required
|
27
|
+
# password - password if authorization is required
|
28
|
+
@host = host
|
29
|
+
@port = port
|
30
|
+
@username = username
|
31
|
+
@password = password
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,95 +1,95 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#
|
4
|
-
# Copyright 2019-2020, 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
|
-
module Optimizely
|
19
|
-
class AsyncScheduler
|
20
|
-
attr_reader :running
|
21
|
-
|
22
|
-
def initialize(callback, interval, auto_update, logger = nil, error_handler = nil)
|
23
|
-
# Sets up AsyncScheduler to execute a callback periodically.
|
24
|
-
#
|
25
|
-
# callback - Main function to be executed periodically.
|
26
|
-
# interval - How many seconds to wait between executions.
|
27
|
-
# auto_update - boolean indicates to run infinitely or only once.
|
28
|
-
# logger - Optional Provides a logger instance.
|
29
|
-
# error_handler - Optional Provides a handle_error method to handle exceptions.
|
30
|
-
|
31
|
-
@callback = callback
|
32
|
-
@interval = interval
|
33
|
-
@auto_update = auto_update
|
34
|
-
@running = false
|
35
|
-
@thread = nil
|
36
|
-
@logger = logger || NoOpLogger.new
|
37
|
-
@error_handler = error_handler || NoOpErrorHandler.new
|
38
|
-
end
|
39
|
-
|
40
|
-
def start!
|
41
|
-
# Starts the async scheduler.
|
42
|
-
|
43
|
-
if @running
|
44
|
-
@logger.log(
|
45
|
-
Logger::WARN,
|
46
|
-
'Scheduler is already running. Ignoring .start() call.'
|
47
|
-
)
|
48
|
-
return
|
49
|
-
end
|
50
|
-
|
51
|
-
begin
|
52
|
-
@running = true
|
53
|
-
@thread = Thread.new { execution_wrapper(@callback) }
|
54
|
-
rescue StandardError => e
|
55
|
-
@logger.log(
|
56
|
-
Logger::ERROR,
|
57
|
-
"Couldn't create a new thread for async scheduler. #{e.message}"
|
58
|
-
)
|
59
|
-
@error_handler.handle_error(e)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def stop!
|
64
|
-
# Stops the async scheduler.
|
65
|
-
|
66
|
-
# If the scheduler is not running do nothing.
|
67
|
-
return unless @running
|
68
|
-
|
69
|
-
@running = false
|
70
|
-
@thread.exit
|
71
|
-
end
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
def execution_wrapper(callback)
|
76
|
-
# Executes the given callback periodically
|
77
|
-
|
78
|
-
loop do
|
79
|
-
begin
|
80
|
-
callback.call
|
81
|
-
rescue StandardError => e
|
82
|
-
@logger.log(
|
83
|
-
Logger::ERROR,
|
84
|
-
"Something went wrong when executing passed callback. #{e.message}"
|
85
|
-
)
|
86
|
-
@error_handler.handle_error(e)
|
87
|
-
stop!
|
88
|
-
end
|
89
|
-
break unless @auto_update
|
90
|
-
|
91
|
-
sleep @interval
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright 2019-2020, 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
|
+
module Optimizely
|
19
|
+
class AsyncScheduler
|
20
|
+
attr_reader :running
|
21
|
+
|
22
|
+
def initialize(callback, interval, auto_update, logger = nil, error_handler = nil)
|
23
|
+
# Sets up AsyncScheduler to execute a callback periodically.
|
24
|
+
#
|
25
|
+
# callback - Main function to be executed periodically.
|
26
|
+
# interval - How many seconds to wait between executions.
|
27
|
+
# auto_update - boolean indicates to run infinitely or only once.
|
28
|
+
# logger - Optional Provides a logger instance.
|
29
|
+
# error_handler - Optional Provides a handle_error method to handle exceptions.
|
30
|
+
|
31
|
+
@callback = callback
|
32
|
+
@interval = interval
|
33
|
+
@auto_update = auto_update
|
34
|
+
@running = false
|
35
|
+
@thread = nil
|
36
|
+
@logger = logger || NoOpLogger.new
|
37
|
+
@error_handler = error_handler || NoOpErrorHandler.new
|
38
|
+
end
|
39
|
+
|
40
|
+
def start!
|
41
|
+
# Starts the async scheduler.
|
42
|
+
|
43
|
+
if @running
|
44
|
+
@logger.log(
|
45
|
+
Logger::WARN,
|
46
|
+
'Scheduler is already running. Ignoring .start() call.'
|
47
|
+
)
|
48
|
+
return
|
49
|
+
end
|
50
|
+
|
51
|
+
begin
|
52
|
+
@running = true
|
53
|
+
@thread = Thread.new { execution_wrapper(@callback) }
|
54
|
+
rescue StandardError => e
|
55
|
+
@logger.log(
|
56
|
+
Logger::ERROR,
|
57
|
+
"Couldn't create a new thread for async scheduler. #{e.message}"
|
58
|
+
)
|
59
|
+
@error_handler.handle_error(e)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def stop!
|
64
|
+
# Stops the async scheduler.
|
65
|
+
|
66
|
+
# If the scheduler is not running do nothing.
|
67
|
+
return unless @running
|
68
|
+
|
69
|
+
@running = false
|
70
|
+
@thread.exit
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def execution_wrapper(callback)
|
76
|
+
# Executes the given callback periodically
|
77
|
+
|
78
|
+
loop do
|
79
|
+
begin
|
80
|
+
callback.call
|
81
|
+
rescue StandardError => e
|
82
|
+
@logger.log(
|
83
|
+
Logger::ERROR,
|
84
|
+
"Something went wrong when executing passed callback. #{e.message}"
|
85
|
+
)
|
86
|
+
@error_handler.handle_error(e)
|
87
|
+
stop!
|
88
|
+
end
|
89
|
+
break unless @auto_update
|
90
|
+
|
91
|
+
sleep @interval
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|