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,71 +1,71 @@
1
- # frozen_string_literal: true
2
-
3
- #
4
- # Copyright 2016-2017, 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
- require_relative 'exceptions'
19
- require_relative 'helpers/http_utils'
20
-
21
- module Optimizely
22
- class NoOpEventDispatcher
23
- # Class providing dispatch_event method which does nothing.
24
-
25
- def dispatch_event(event); end
26
- end
27
-
28
- class EventDispatcher
29
- # @api constants
30
- REQUEST_TIMEOUT = 10
31
-
32
- def initialize(logger: nil, error_handler: nil, proxy_config: nil)
33
- @logger = logger || NoOpLogger.new
34
- @error_handler = error_handler || NoOpErrorHandler.new
35
- @proxy_config = proxy_config
36
- end
37
-
38
- # Dispatch the event being represented by the Event object.
39
- #
40
- # @param event - Event object
41
- def dispatch_event(event)
42
- response = Helpers::HttpUtils.make_request(
43
- event.url, event.http_verb, event.params.to_json, event.headers, REQUEST_TIMEOUT, @proxy_config
44
- )
45
-
46
- error_msg = "Event failed to dispatch with response code: #{response.code}"
47
-
48
- case response.code.to_i
49
- when 400...500
50
- @logger.log(Logger::ERROR, error_msg)
51
- @error_handler.handle_error(HTTPCallError.new("HTTP Client Error: #{response.code}"))
52
-
53
- when 500...600
54
- @logger.log(Logger::ERROR, error_msg)
55
- @error_handler.handle_error(HTTPCallError.new("HTTP Server Error: #{response.code}"))
56
- else
57
- @logger.log(Logger::DEBUG, 'event successfully sent with response code ' + response.code.to_s)
58
- end
59
- rescue Timeout::Error => e
60
- @logger.log(Logger::ERROR, "Request Timed out. Error: #{e}")
61
- @error_handler.handle_error(e)
62
-
63
- # Returning Timeout error to retain existing behavior.
64
- e
65
- rescue StandardError => e
66
- @logger.log(Logger::ERROR, "Event failed to dispatch. Error: #{e}")
67
- @error_handler.handle_error(e)
68
- nil
69
- end
70
- end
71
- end
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright 2016-2017, 2019-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
+ require_relative 'exceptions'
19
+ require_relative 'helpers/http_utils'
20
+
21
+ module Optimizely
22
+ class NoOpEventDispatcher
23
+ # Class providing dispatch_event method which does nothing.
24
+
25
+ def dispatch_event(event); end
26
+ end
27
+
28
+ class EventDispatcher
29
+ # @api constants
30
+ REQUEST_TIMEOUT = 10
31
+
32
+ def initialize(logger: nil, error_handler: nil, proxy_config: nil)
33
+ @logger = logger || NoOpLogger.new
34
+ @error_handler = error_handler || NoOpErrorHandler.new
35
+ @proxy_config = proxy_config
36
+ end
37
+
38
+ # Dispatch the event being represented by the Event object.
39
+ #
40
+ # @param event - Event object
41
+ def dispatch_event(event)
42
+ response = Helpers::HttpUtils.make_request(
43
+ event.url, event.http_verb, event.params.to_json, event.headers, REQUEST_TIMEOUT, @proxy_config
44
+ )
45
+
46
+ error_msg = "Event failed to dispatch with response code: #{response.code}"
47
+
48
+ case response.code.to_i
49
+ when 400...500
50
+ @logger.log(Logger::ERROR, error_msg)
51
+ @error_handler.handle_error(HTTPCallError.new("HTTP Client Error: #{response.code}"))
52
+
53
+ when 500...600
54
+ @logger.log(Logger::ERROR, error_msg)
55
+ @error_handler.handle_error(HTTPCallError.new("HTTP Server Error: #{response.code}"))
56
+ else
57
+ @logger.log(Logger::DEBUG, "event successfully sent with response code #{response.code}")
58
+ end
59
+ rescue Timeout::Error => e
60
+ @logger.log(Logger::ERROR, "Request Timed out. Error: #{e}")
61
+ @error_handler.handle_error(e)
62
+
63
+ # Returning Timeout error to retain existing behavior.
64
+ e
65
+ rescue StandardError => e
66
+ @logger.log(Logger::ERROR, "Event failed to dispatch. Error: #{e}")
67
+ @error_handler.handle_error(e)
68
+ nil
69
+ end
70
+ end
71
+ end
@@ -1,139 +1,135 @@
1
- # frozen_string_literal: true
2
-
3
- #
4
- # Copyright 2016-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 Error < StandardError; end
20
-
21
- class HTTPCallError < Error
22
- # Raised when a 4xx or 5xx response code is recieved.
23
- def initialize(msg = 'HTTP call resulted in a response with an error code.')
24
- super
25
- end
26
- end
27
-
28
- class InvalidAudienceError < Error
29
- # Raised when an invalid audience is provided
30
-
31
- def initialize(msg = 'Provided audience is not in datafile.')
32
- super
33
- end
34
- end
35
-
36
- class InvalidAttributeError < Error
37
- # Raised when an invalid attribute is provided
38
-
39
- def initialize(msg = 'Provided attribute is not in datafile.')
40
- super
41
- end
42
- end
43
-
44
- class InvalidAttributeFormatError < Error
45
- # Raised when attributes are provided in an invalid format (e.g. not a Hash)
46
-
47
- def initialize(msg = 'Attributes provided are in an invalid format.')
48
- super
49
- end
50
- end
51
-
52
- class InvalidEventTagFormatError < Error
53
- # Raised when attributes are provided in an invalid format (e.g. not a Hash)
54
-
55
- def initialize(msg = 'Event tags provided are in an invalid format.')
56
- super
57
- end
58
- end
59
-
60
- class InvalidExperimentError < Error
61
- # Raised when an invalid experiment key is provided
62
-
63
- def initialize(msg = 'Provided experiment is not in datafile.')
64
- super
65
- end
66
- end
67
-
68
- class InvalidEventError < Error
69
- # Raised when an invalid event key is provided
70
-
71
- def initialize(msg = 'Provided event is not in datafile.')
72
- super
73
- end
74
- end
75
-
76
- class InvalidVariationError < Error
77
- # Raised when an invalid variation key or ID is provided
78
-
79
- def initialize(msg = 'Provided variation is not in datafile.')
80
- super
81
- end
82
- end
83
-
84
- class InvalidDatafileVersionError < Error
85
- # Raised when a datafile with an unsupported version is provided
86
-
87
- def initialize(version)
88
- super("This version of the Ruby SDK does not support the given datafile version: #{version}.")
89
- end
90
- end
91
-
92
- class InvalidInputError < Error
93
- # Abstract error raised when an invalid input is provided during Project instantiation
94
-
95
- def initialize(type)
96
- super("Provided #{type} is in an invalid format.")
97
- end
98
- end
99
-
100
- class InvalidNotificationType < Error
101
- # Raised when an invalid notification type is provided
102
-
103
- def initialize(msg = 'Provided notification type is invalid.')
104
- super
105
- end
106
- end
107
-
108
- class InvalidInputsError < Error
109
- # Raised when an invalid inputs are provided during Project instantiation
110
-
111
- def initialize(msg)
112
- super msg
113
- end
114
- end
115
-
116
- class InvalidProjectConfigError < Error
117
- # Raised when a public method fails due to an invalid datafile
118
-
119
- def initialize(aborted_method)
120
- super("Optimizely instance is not valid. Failing '#{aborted_method}'.")
121
- end
122
- end
123
-
124
- class InvalidAttributeType < Error
125
- # Raised when an attribute is not provided in expected type.
126
-
127
- def initialize(msg = 'Provided attribute value is not in the expected data type.')
128
- super
129
- end
130
- end
131
-
132
- class InvalidSemanticVersion < Error
133
- # Raised when an invalid value is provided as semantic version.
134
-
135
- def initialize(msg = 'Provided semantic version is invalid.')
136
- super
137
- end
138
- end
139
- end
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright 2016-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
+ module Optimizely
19
+ class Error < StandardError; end
20
+
21
+ class HTTPCallError < Error
22
+ # Raised when a 4xx or 5xx response code is recieved.
23
+ def initialize(msg = 'HTTP call resulted in a response with an error code.')
24
+ super
25
+ end
26
+ end
27
+
28
+ class InvalidAudienceError < Error
29
+ # Raised when an invalid audience is provided
30
+
31
+ def initialize(msg = 'Provided audience is not in datafile.')
32
+ super
33
+ end
34
+ end
35
+
36
+ class InvalidAttributeError < Error
37
+ # Raised when an invalid attribute is provided
38
+
39
+ def initialize(msg = 'Provided attribute is not in datafile.')
40
+ super
41
+ end
42
+ end
43
+
44
+ class InvalidAttributeFormatError < Error
45
+ # Raised when attributes are provided in an invalid format (e.g. not a Hash)
46
+
47
+ def initialize(msg = 'Attributes provided are in an invalid format.')
48
+ super
49
+ end
50
+ end
51
+
52
+ class InvalidEventTagFormatError < Error
53
+ # Raised when attributes are provided in an invalid format (e.g. not a Hash)
54
+
55
+ def initialize(msg = 'Event tags provided are in an invalid format.')
56
+ super
57
+ end
58
+ end
59
+
60
+ class InvalidExperimentError < Error
61
+ # Raised when an invalid experiment key is provided
62
+
63
+ def initialize(msg = 'Provided experiment is not in datafile.')
64
+ super
65
+ end
66
+ end
67
+
68
+ class InvalidEventError < Error
69
+ # Raised when an invalid event key is provided
70
+
71
+ def initialize(msg = 'Provided event is not in datafile.')
72
+ super
73
+ end
74
+ end
75
+
76
+ class InvalidVariationError < Error
77
+ # Raised when an invalid variation key or ID is provided
78
+
79
+ def initialize(msg = 'Provided variation is not in datafile.')
80
+ super
81
+ end
82
+ end
83
+
84
+ class InvalidDatafileVersionError < Error
85
+ # Raised when a datafile with an unsupported version is provided
86
+
87
+ def initialize(version)
88
+ super("This version of the Ruby SDK does not support the given datafile version: #{version}.")
89
+ end
90
+ end
91
+
92
+ class InvalidInputError < Error
93
+ # Abstract error raised when an invalid input is provided during Project instantiation
94
+
95
+ def initialize(type)
96
+ super("Provided #{type} is in an invalid format.")
97
+ end
98
+ end
99
+
100
+ class InvalidNotificationType < Error
101
+ # Raised when an invalid notification type is provided
102
+
103
+ def initialize(msg = 'Provided notification type is invalid.')
104
+ super
105
+ end
106
+ end
107
+
108
+ class InvalidInputsError < Error
109
+ # Raised when an invalid inputs are provided during Project instantiation
110
+ end
111
+
112
+ class InvalidProjectConfigError < Error
113
+ # Raised when a public method fails due to an invalid datafile
114
+
115
+ def initialize(aborted_method)
116
+ super("Optimizely instance is not valid. Failing '#{aborted_method}'.")
117
+ end
118
+ end
119
+
120
+ class InvalidAttributeType < Error
121
+ # Raised when an attribute is not provided in expected type.
122
+
123
+ def initialize(msg = 'Provided attribute value is not in the expected data type.')
124
+ super
125
+ end
126
+ end
127
+
128
+ class InvalidSemanticVersion < Error
129
+ # Raised when an invalid value is provided as semantic version.
130
+
131
+ def initialize(msg = 'Provided semantic version is invalid.')
132
+ super
133
+ end
134
+ end
135
+ end