optimizely-sdk 5.0.0 → 5.1.0
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 +589 -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 +183 -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/user_profile_tracker.rb +64 -0
- data/lib/optimizely/version.rb +21 -21
- data/lib/optimizely.rb +1326 -1262
- metadata +8 -5
@@ -1,30 +1,30 @@
|
|
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
|
-
module Optimizely
|
19
|
-
module Helpers
|
20
|
-
module DateTimeUtils
|
21
|
-
module_function
|
22
|
-
|
23
|
-
def create_timestamp
|
24
|
-
# Returns Integer current UTC timestamp
|
25
|
-
utc = Time.now.getutc
|
26
|
-
(utc.to_f * 1000).to_i
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
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
|
+
module Optimizely
|
19
|
+
module Helpers
|
20
|
+
module DateTimeUtils
|
21
|
+
module_function
|
22
|
+
|
23
|
+
def create_timestamp
|
24
|
+
# Returns Integer current UTC timestamp
|
25
|
+
utc = Time.now.getutc
|
26
|
+
(utc.to_f * 1000).to_i
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,132 +1,132 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#
|
4
|
-
# Copyright 2017-2018, 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
|
-
require 'optimizely/logger'
|
19
|
-
require 'optimizely/helpers/validator'
|
20
|
-
|
21
|
-
module Optimizely
|
22
|
-
module Helpers
|
23
|
-
module EventTagUtils
|
24
|
-
module_function
|
25
|
-
|
26
|
-
REVENUE_EVENT_METRIC_NAME = 'revenue'
|
27
|
-
NUMERIC_EVENT_METRIC_NAME = 'value'
|
28
|
-
|
29
|
-
def get_revenue_value(event_tags, logger)
|
30
|
-
# Grab the revenue value from the event tags. "revenue" is a reserved keyword.
|
31
|
-
# The value will be parsed to an integer if possible.
|
32
|
-
# Example:
|
33
|
-
# 4.0 or "4.0" will be parsed to int(4).
|
34
|
-
# 4.1 will not be parsed and the method will return nil.
|
35
|
-
# event_tags - Hash representing metadata associated with the event.
|
36
|
-
# logger - Optional component which provides a log method to log messages.
|
37
|
-
#
|
38
|
-
# Returns revenue value as an integer number
|
39
|
-
# Returns nil if revenue can't be retrieved from the event tags.
|
40
|
-
|
41
|
-
if event_tags.nil?
|
42
|
-
logger.log(Logger::DEBUG, 'Event tags is undefined.')
|
43
|
-
return nil
|
44
|
-
end
|
45
|
-
|
46
|
-
unless Helpers::Validator.event_tags_valid?(event_tags)
|
47
|
-
logger.log(Logger::DEBUG, 'Event tags is not a hash.')
|
48
|
-
return nil
|
49
|
-
end
|
50
|
-
|
51
|
-
unless event_tags.key?(REVENUE_EVENT_METRIC_NAME)
|
52
|
-
logger.log(Logger::DEBUG, 'The revenue key is not defined in the event tags.')
|
53
|
-
return nil
|
54
|
-
end
|
55
|
-
|
56
|
-
if event_tags[REVENUE_EVENT_METRIC_NAME].nil?
|
57
|
-
logger.log(Logger::DEBUG, 'The revenue key is nil.')
|
58
|
-
return nil
|
59
|
-
end
|
60
|
-
|
61
|
-
raw_value = event_tags[REVENUE_EVENT_METRIC_NAME]
|
62
|
-
|
63
|
-
unless Helpers::Validator.string_numeric?(raw_value)
|
64
|
-
logger.log(Logger::WARN, 'Revenue value is not an integer or float, or is not a numeric string.')
|
65
|
-
return nil
|
66
|
-
end
|
67
|
-
|
68
|
-
raw_value = raw_value.to_f if raw_value.is_a? String
|
69
|
-
|
70
|
-
unless raw_value == raw_value.to_i
|
71
|
-
logger.log(Logger::WARN, "Failed to parse revenue value #{raw_value} from event tags.")
|
72
|
-
return nil
|
73
|
-
end
|
74
|
-
|
75
|
-
logger.log(Logger::INFO, "Parsed revenue value #{raw_value.to_i} from event tags.")
|
76
|
-
raw_value.to_i
|
77
|
-
end
|
78
|
-
|
79
|
-
def get_numeric_value(event_tags, logger)
|
80
|
-
# Grab the numeric event value from the event tags. "value" is a reserved keyword.
|
81
|
-
# The value of 'value' can be a float or a numeric string
|
82
|
-
#
|
83
|
-
# event_tags - +Hash+ representing metadata associated with the event.
|
84
|
-
# logger - Optional component which provides a log method to log messages.
|
85
|
-
# Returns +Number+ | +nil+ if value can't be retrieved from the event tags.
|
86
|
-
|
87
|
-
if event_tags.nil?
|
88
|
-
logger.log(Logger::DEBUG, 'Event tags is undefined.')
|
89
|
-
return nil
|
90
|
-
end
|
91
|
-
|
92
|
-
unless Helpers::Validator.event_tags_valid?(event_tags)
|
93
|
-
logger.log(Logger::DEBUG, 'Event tags is not a dictionary.')
|
94
|
-
return nil
|
95
|
-
end
|
96
|
-
|
97
|
-
unless event_tags.key?(NUMERIC_EVENT_METRIC_NAME)
|
98
|
-
logger.log(Logger::DEBUG, 'The numeric metric key is not defined in the event tags.')
|
99
|
-
return nil
|
100
|
-
end
|
101
|
-
|
102
|
-
if event_tags[NUMERIC_EVENT_METRIC_NAME].nil?
|
103
|
-
logger.log(Logger::DEBUG, 'The numeric metric key is null.')
|
104
|
-
return nil
|
105
|
-
end
|
106
|
-
|
107
|
-
raw_value = event_tags[NUMERIC_EVENT_METRIC_NAME]
|
108
|
-
|
109
|
-
if raw_value.is_a?(TrueClass) || raw_value.is_a?(FalseClass)
|
110
|
-
logger.log(Logger::DEBUG, 'Provided numeric value is a boolean, which is an invalid format.')
|
111
|
-
return nil
|
112
|
-
end
|
113
|
-
|
114
|
-
if raw_value.is_a?(Array) || raw_value.is_a?(Hash) || raw_value.to_f.nan? || raw_value.to_f.infinite?
|
115
|
-
logger.log(Logger::DEBUG, 'Provided numeric value is in an invalid format.')
|
116
|
-
return nil
|
117
|
-
end
|
118
|
-
|
119
|
-
unless Helpers::Validator.string_numeric?(raw_value)
|
120
|
-
logger.log(Logger::DEBUG, 'Provided numeric value is not a numeric string.')
|
121
|
-
return nil
|
122
|
-
end
|
123
|
-
|
124
|
-
raw_value = raw_value.to_f
|
125
|
-
|
126
|
-
logger.log(Logger::INFO, "The numeric metric value #{raw_value} will be sent to results.")
|
127
|
-
|
128
|
-
raw_value
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright 2017-2018, 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
|
+
require 'optimizely/logger'
|
19
|
+
require 'optimizely/helpers/validator'
|
20
|
+
|
21
|
+
module Optimizely
|
22
|
+
module Helpers
|
23
|
+
module EventTagUtils
|
24
|
+
module_function
|
25
|
+
|
26
|
+
REVENUE_EVENT_METRIC_NAME = 'revenue'
|
27
|
+
NUMERIC_EVENT_METRIC_NAME = 'value'
|
28
|
+
|
29
|
+
def get_revenue_value(event_tags, logger)
|
30
|
+
# Grab the revenue value from the event tags. "revenue" is a reserved keyword.
|
31
|
+
# The value will be parsed to an integer if possible.
|
32
|
+
# Example:
|
33
|
+
# 4.0 or "4.0" will be parsed to int(4).
|
34
|
+
# 4.1 will not be parsed and the method will return nil.
|
35
|
+
# event_tags - Hash representing metadata associated with the event.
|
36
|
+
# logger - Optional component which provides a log method to log messages.
|
37
|
+
#
|
38
|
+
# Returns revenue value as an integer number
|
39
|
+
# Returns nil if revenue can't be retrieved from the event tags.
|
40
|
+
|
41
|
+
if event_tags.nil?
|
42
|
+
logger.log(Logger::DEBUG, 'Event tags is undefined.')
|
43
|
+
return nil
|
44
|
+
end
|
45
|
+
|
46
|
+
unless Helpers::Validator.event_tags_valid?(event_tags)
|
47
|
+
logger.log(Logger::DEBUG, 'Event tags is not a hash.')
|
48
|
+
return nil
|
49
|
+
end
|
50
|
+
|
51
|
+
unless event_tags.key?(REVENUE_EVENT_METRIC_NAME)
|
52
|
+
logger.log(Logger::DEBUG, 'The revenue key is not defined in the event tags.')
|
53
|
+
return nil
|
54
|
+
end
|
55
|
+
|
56
|
+
if event_tags[REVENUE_EVENT_METRIC_NAME].nil?
|
57
|
+
logger.log(Logger::DEBUG, 'The revenue key is nil.')
|
58
|
+
return nil
|
59
|
+
end
|
60
|
+
|
61
|
+
raw_value = event_tags[REVENUE_EVENT_METRIC_NAME]
|
62
|
+
|
63
|
+
unless Helpers::Validator.string_numeric?(raw_value)
|
64
|
+
logger.log(Logger::WARN, 'Revenue value is not an integer or float, or is not a numeric string.')
|
65
|
+
return nil
|
66
|
+
end
|
67
|
+
|
68
|
+
raw_value = raw_value.to_f if raw_value.is_a? String
|
69
|
+
|
70
|
+
unless raw_value == raw_value.to_i
|
71
|
+
logger.log(Logger::WARN, "Failed to parse revenue value #{raw_value} from event tags.")
|
72
|
+
return nil
|
73
|
+
end
|
74
|
+
|
75
|
+
logger.log(Logger::INFO, "Parsed revenue value #{raw_value.to_i} from event tags.")
|
76
|
+
raw_value.to_i
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_numeric_value(event_tags, logger)
|
80
|
+
# Grab the numeric event value from the event tags. "value" is a reserved keyword.
|
81
|
+
# The value of 'value' can be a float or a numeric string
|
82
|
+
#
|
83
|
+
# event_tags - +Hash+ representing metadata associated with the event.
|
84
|
+
# logger - Optional component which provides a log method to log messages.
|
85
|
+
# Returns +Number+ | +nil+ if value can't be retrieved from the event tags.
|
86
|
+
|
87
|
+
if event_tags.nil?
|
88
|
+
logger.log(Logger::DEBUG, 'Event tags is undefined.')
|
89
|
+
return nil
|
90
|
+
end
|
91
|
+
|
92
|
+
unless Helpers::Validator.event_tags_valid?(event_tags)
|
93
|
+
logger.log(Logger::DEBUG, 'Event tags is not a dictionary.')
|
94
|
+
return nil
|
95
|
+
end
|
96
|
+
|
97
|
+
unless event_tags.key?(NUMERIC_EVENT_METRIC_NAME)
|
98
|
+
logger.log(Logger::DEBUG, 'The numeric metric key is not defined in the event tags.')
|
99
|
+
return nil
|
100
|
+
end
|
101
|
+
|
102
|
+
if event_tags[NUMERIC_EVENT_METRIC_NAME].nil?
|
103
|
+
logger.log(Logger::DEBUG, 'The numeric metric key is null.')
|
104
|
+
return nil
|
105
|
+
end
|
106
|
+
|
107
|
+
raw_value = event_tags[NUMERIC_EVENT_METRIC_NAME]
|
108
|
+
|
109
|
+
if raw_value.is_a?(TrueClass) || raw_value.is_a?(FalseClass)
|
110
|
+
logger.log(Logger::DEBUG, 'Provided numeric value is a boolean, which is an invalid format.')
|
111
|
+
return nil
|
112
|
+
end
|
113
|
+
|
114
|
+
if raw_value.is_a?(Array) || raw_value.is_a?(Hash) || raw_value.to_f.nan? || raw_value.to_f.infinite?
|
115
|
+
logger.log(Logger::DEBUG, 'Provided numeric value is in an invalid format.')
|
116
|
+
return nil
|
117
|
+
end
|
118
|
+
|
119
|
+
unless Helpers::Validator.string_numeric?(raw_value)
|
120
|
+
logger.log(Logger::DEBUG, 'Provided numeric value is not a numeric string.')
|
121
|
+
return nil
|
122
|
+
end
|
123
|
+
|
124
|
+
raw_value = raw_value.to_f
|
125
|
+
|
126
|
+
logger.log(Logger::INFO, "The numeric metric value #{raw_value} will be sent to results.")
|
127
|
+
|
128
|
+
raw_value
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -1,31 +1,31 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#
|
4
|
-
# Copyright 2016-2017, 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
|
-
module Helpers
|
20
|
-
module Group
|
21
|
-
OVERLAPPING_POLICY = 'overlapping'
|
22
|
-
RANDOM_POLICY = 'random'
|
23
|
-
|
24
|
-
module_function
|
25
|
-
|
26
|
-
def random_policy?(group)
|
27
|
-
group['policy'] == RANDOM_POLICY
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright 2016-2017, 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
|
+
module Helpers
|
20
|
+
module Group
|
21
|
+
OVERLAPPING_POLICY = 'overlapping'
|
22
|
+
RANDOM_POLICY = 'random'
|
23
|
+
|
24
|
+
module_function
|
25
|
+
|
26
|
+
def random_policy?(group)
|
27
|
+
group['policy'] == RANDOM_POLICY
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,68 +1,68 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#
|
4
|
-
# Copyright 2020, 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 'net/http'
|
20
|
-
require_relative '../exceptions'
|
21
|
-
|
22
|
-
module Optimizely
|
23
|
-
module Helpers
|
24
|
-
module HttpUtils
|
25
|
-
module_function
|
26
|
-
|
27
|
-
def make_request(url, http_method, request_body = nil, headers = {}, read_timeout = nil, proxy_config = nil) # rubocop:disable Metrics/ParameterLists
|
28
|
-
# makes http/https GET/POST request and returns response
|
29
|
-
#
|
30
|
-
uri = URI.parse(url)
|
31
|
-
|
32
|
-
raise HTTPUriError unless uri.respond_to?(:request_uri)
|
33
|
-
|
34
|
-
case http_method
|
35
|
-
when :get
|
36
|
-
request = Net::HTTP::Get.new(uri.request_uri)
|
37
|
-
when :post
|
38
|
-
request = Net::HTTP::Post.new(uri.request_uri)
|
39
|
-
request.body = request_body if request_body
|
40
|
-
else
|
41
|
-
return nil
|
42
|
-
end
|
43
|
-
|
44
|
-
# set headers
|
45
|
-
headers&.each do |key, val|
|
46
|
-
request[key] = val
|
47
|
-
end
|
48
|
-
|
49
|
-
# do not try to make request with proxy unless we have at least a host
|
50
|
-
http_class = if proxy_config&.host
|
51
|
-
Net::HTTP::Proxy(
|
52
|
-
proxy_config.host,
|
53
|
-
proxy_config.port,
|
54
|
-
proxy_config.username,
|
55
|
-
proxy_config.password
|
56
|
-
)
|
57
|
-
else
|
58
|
-
Net::HTTP
|
59
|
-
end
|
60
|
-
|
61
|
-
http = http_class.new(uri.host, uri.port)
|
62
|
-
http.read_timeout = read_timeout if read_timeout
|
63
|
-
http.use_ssl = uri.scheme == 'https'
|
64
|
-
http.request(request)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright 2020, 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 'net/http'
|
20
|
+
require_relative '../exceptions'
|
21
|
+
|
22
|
+
module Optimizely
|
23
|
+
module Helpers
|
24
|
+
module HttpUtils
|
25
|
+
module_function
|
26
|
+
|
27
|
+
def make_request(url, http_method, request_body = nil, headers = {}, read_timeout = nil, proxy_config = nil) # rubocop:disable Metrics/ParameterLists
|
28
|
+
# makes http/https GET/POST request and returns response
|
29
|
+
#
|
30
|
+
uri = URI.parse(url)
|
31
|
+
|
32
|
+
raise HTTPUriError unless uri.respond_to?(:request_uri)
|
33
|
+
|
34
|
+
case http_method
|
35
|
+
when :get
|
36
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
37
|
+
when :post
|
38
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
39
|
+
request.body = request_body if request_body
|
40
|
+
else
|
41
|
+
return nil
|
42
|
+
end
|
43
|
+
|
44
|
+
# set headers
|
45
|
+
headers&.each do |key, val|
|
46
|
+
request[key] = val
|
47
|
+
end
|
48
|
+
|
49
|
+
# do not try to make request with proxy unless we have at least a host
|
50
|
+
http_class = if proxy_config&.host
|
51
|
+
Net::HTTP::Proxy(
|
52
|
+
proxy_config.host,
|
53
|
+
proxy_config.port,
|
54
|
+
proxy_config.username,
|
55
|
+
proxy_config.password
|
56
|
+
)
|
57
|
+
else
|
58
|
+
Net::HTTP
|
59
|
+
end
|
60
|
+
|
61
|
+
http = http_class.new(uri.host, uri.port)
|
62
|
+
http.read_timeout = read_timeout if read_timeout
|
63
|
+
http.use_ssl = uri.scheme == 'https'
|
64
|
+
http.request(request)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -1,61 +1,61 @@
|
|
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_relative 'constants'
|
20
|
-
|
21
|
-
module Optimizely
|
22
|
-
module Helpers
|
23
|
-
class OptimizelySdkSettings
|
24
|
-
attr_accessor :odp_disabled, :segments_cache_size, :segments_cache_timeout_in_secs, :odp_segments_cache, :odp_segment_manager,
|
25
|
-
:odp_event_manager, :fetch_segments_timeout, :odp_event_timeout, :odp_flush_interval
|
26
|
-
|
27
|
-
# Contains configuration used for Optimizely Project initialization.
|
28
|
-
#
|
29
|
-
# @param disable_odp - Set this flag to true (default = false) to disable ODP features.
|
30
|
-
# @param segments_cache_size - The maximum size of audience segments cache (optional. default = 10,000). Set to zero to disable caching.
|
31
|
-
# @param segments_cache_timeout_in_secs - The timeout in seconds of audience segments cache (optional. default = 600). Set to zero to disable timeout.
|
32
|
-
# @param odp_segments_cache - A custom odp segments cache. Required methods include: `save(key, value)`, `lookup(key) -> value`, and `reset()`
|
33
|
-
# @param odp_segment_manager - A custom odp segment manager. Required method is: `fetch_qualified_segments(user_key, user_value, options)`.
|
34
|
-
# @param odp_event_manager - A custom odp event manager. Required method is: `send_event(type:, action:, identifiers:, data:)`
|
35
|
-
# @param odp_segment_request_timeout - Time to wait in seconds for fetch_qualified_segments (optional. default = 10).
|
36
|
-
# @param odp_event_request_timeout - Time to wait in seconds for send_odp_events (optional. default = 10).
|
37
|
-
# @param odp_event_flush_interval - Time to wait in seconds for odp events to accumulate before sending (optional. default = 1).
|
38
|
-
def initialize(
|
39
|
-
disable_odp: false,
|
40
|
-
segments_cache_size: Constants::ODP_SEGMENTS_CACHE_CONFIG[:DEFAULT_CAPACITY],
|
41
|
-
segments_cache_timeout_in_secs: Constants::ODP_SEGMENTS_CACHE_CONFIG[:DEFAULT_TIMEOUT_SECONDS],
|
42
|
-
odp_segments_cache: nil,
|
43
|
-
odp_segment_manager: nil,
|
44
|
-
odp_event_manager: nil,
|
45
|
-
odp_segment_request_timeout: nil,
|
46
|
-
odp_event_request_timeout: nil,
|
47
|
-
odp_event_flush_interval: nil
|
48
|
-
)
|
49
|
-
@odp_disabled = disable_odp
|
50
|
-
@segments_cache_size = segments_cache_size
|
51
|
-
@segments_cache_timeout_in_secs = segments_cache_timeout_in_secs
|
52
|
-
@odp_segments_cache = odp_segments_cache
|
53
|
-
@odp_segment_manager = odp_segment_manager
|
54
|
-
@odp_event_manager = odp_event_manager
|
55
|
-
@fetch_segments_timeout = odp_segment_request_timeout
|
56
|
-
@odp_event_timeout = odp_event_request_timeout
|
57
|
-
@odp_flush_interval = odp_event_flush_interval
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
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_relative 'constants'
|
20
|
+
|
21
|
+
module Optimizely
|
22
|
+
module Helpers
|
23
|
+
class OptimizelySdkSettings
|
24
|
+
attr_accessor :odp_disabled, :segments_cache_size, :segments_cache_timeout_in_secs, :odp_segments_cache, :odp_segment_manager,
|
25
|
+
:odp_event_manager, :fetch_segments_timeout, :odp_event_timeout, :odp_flush_interval
|
26
|
+
|
27
|
+
# Contains configuration used for Optimizely Project initialization.
|
28
|
+
#
|
29
|
+
# @param disable_odp - Set this flag to true (default = false) to disable ODP features.
|
30
|
+
# @param segments_cache_size - The maximum size of audience segments cache (optional. default = 10,000). Set to zero to disable caching.
|
31
|
+
# @param segments_cache_timeout_in_secs - The timeout in seconds of audience segments cache (optional. default = 600). Set to zero to disable timeout.
|
32
|
+
# @param odp_segments_cache - A custom odp segments cache. Required methods include: `save(key, value)`, `lookup(key) -> value`, and `reset()`
|
33
|
+
# @param odp_segment_manager - A custom odp segment manager. Required method is: `fetch_qualified_segments(user_key, user_value, options)`.
|
34
|
+
# @param odp_event_manager - A custom odp event manager. Required method is: `send_event(type:, action:, identifiers:, data:)`
|
35
|
+
# @param odp_segment_request_timeout - Time to wait in seconds for fetch_qualified_segments (optional. default = 10).
|
36
|
+
# @param odp_event_request_timeout - Time to wait in seconds for send_odp_events (optional. default = 10).
|
37
|
+
# @param odp_event_flush_interval - Time to wait in seconds for odp events to accumulate before sending (optional. default = 1).
|
38
|
+
def initialize(
|
39
|
+
disable_odp: false,
|
40
|
+
segments_cache_size: Constants::ODP_SEGMENTS_CACHE_CONFIG[:DEFAULT_CAPACITY],
|
41
|
+
segments_cache_timeout_in_secs: Constants::ODP_SEGMENTS_CACHE_CONFIG[:DEFAULT_TIMEOUT_SECONDS],
|
42
|
+
odp_segments_cache: nil,
|
43
|
+
odp_segment_manager: nil,
|
44
|
+
odp_event_manager: nil,
|
45
|
+
odp_segment_request_timeout: nil,
|
46
|
+
odp_event_request_timeout: nil,
|
47
|
+
odp_event_flush_interval: nil
|
48
|
+
)
|
49
|
+
@odp_disabled = disable_odp
|
50
|
+
@segments_cache_size = segments_cache_size
|
51
|
+
@segments_cache_timeout_in_secs = segments_cache_timeout_in_secs
|
52
|
+
@odp_segments_cache = odp_segments_cache
|
53
|
+
@odp_segment_manager = odp_segment_manager
|
54
|
+
@odp_event_manager = odp_event_manager
|
55
|
+
@fetch_segments_timeout = odp_segment_request_timeout
|
56
|
+
@odp_event_timeout = odp_event_request_timeout
|
57
|
+
@odp_flush_interval = odp_event_flush_interval
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|