optimizely-sdk 5.0.0 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +202 -202
  3. data/lib/optimizely/audience.rb +127 -127
  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 +558 -558
  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 +340 -340
  10. data/lib/optimizely/config_manager/project_config_manager.rb +25 -25
  11. data/lib/optimizely/config_manager/static_project_config_manager.rb +55 -55
  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 +589 -563
  16. data/lib/optimizely/error_handler.rb +39 -39
  17. data/lib/optimizely/event/batch_event_processor.rb +235 -235
  18. data/lib/optimizely/event/entity/conversion_event.rb +44 -44
  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 -48
  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 -36
  27. data/lib/optimizely/event/entity/visitor_attribute.rb +38 -38
  28. data/lib/optimizely/event/event_factory.rb +156 -156
  29. data/lib/optimizely/event/event_processor.rb +25 -25
  30. data/lib/optimizely/event/forwarding_event_processor.rb +44 -44
  31. data/lib/optimizely/event/user_event_factory.rb +88 -88
  32. data/lib/optimizely/event_builder.rb +221 -221
  33. data/lib/optimizely/event_dispatcher.rb +69 -69
  34. data/lib/optimizely/exceptions.rb +193 -193
  35. data/lib/optimizely/helpers/constants.rb +459 -459
  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 +68 -68
  40. data/lib/optimizely/helpers/sdk_settings.rb +61 -61
  41. data/lib/optimizely/helpers/validator.rb +236 -236
  42. data/lib/optimizely/helpers/variable_type.rb +67 -67
  43. data/lib/optimizely/logger.rb +46 -46
  44. data/lib/optimizely/notification_center.rb +174 -174
  45. data/lib/optimizely/notification_center_registry.rb +71 -71
  46. data/lib/optimizely/odp/lru_cache.rb +114 -114
  47. data/lib/optimizely/odp/odp_config.rb +102 -102
  48. data/lib/optimizely/odp/odp_event.rb +75 -75
  49. data/lib/optimizely/odp/odp_event_api_manager.rb +70 -70
  50. data/lib/optimizely/odp/odp_event_manager.rb +286 -286
  51. data/lib/optimizely/odp/odp_manager.rb +159 -159
  52. data/lib/optimizely/odp/odp_segment_api_manager.rb +122 -122
  53. data/lib/optimizely/odp/odp_segment_manager.rb +97 -97
  54. data/lib/optimizely/optimizely_config.rb +273 -273
  55. data/lib/optimizely/optimizely_factory.rb +183 -184
  56. data/lib/optimizely/optimizely_user_context.rb +238 -238
  57. data/lib/optimizely/params.rb +31 -31
  58. data/lib/optimizely/project_config.rb +99 -99
  59. data/lib/optimizely/semantic_version.rb +166 -166
  60. data/lib/optimizely/user_condition_evaluator.rb +391 -391
  61. data/lib/optimizely/user_profile_service.rb +35 -35
  62. data/lib/optimizely/user_profile_tracker.rb +64 -0
  63. data/lib/optimizely/version.rb +21 -21
  64. data/lib/optimizely.rb +1326 -1262
  65. metadata +8 -5
@@ -1,35 +1,35 @@
1
- # frozen_string_literal: true
2
-
3
- #
4
- # Copyright 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
-
19
- module Optimizely
20
- class BaseUserProfileService
21
- # Class encapsulating user profile service functionality.
22
- # Override with your own implementation for storing and retrieving user profiles.
23
-
24
- # Retrieve the Hash user profile associated with a given user ID.
25
- #
26
- # @param user_id - String user ID
27
- # @return [Hash] user profile.
28
- def lookup(user_id); end
29
-
30
- # Saves a given user profile.
31
- #
32
- # @param user_profile - Hash user profile.
33
- def save(user_profile); end
34
- end
35
- end
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright 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
+
19
+ module Optimizely
20
+ class BaseUserProfileService
21
+ # Class encapsulating user profile service functionality.
22
+ # Override with your own implementation for storing and retrieving user profiles.
23
+
24
+ # Retrieve the Hash user profile associated with a given user ID.
25
+ #
26
+ # @param user_id - String user ID
27
+ # @return [Hash] user profile.
28
+ def lookup(user_id); end
29
+
30
+ # Saves a given user profile.
31
+ #
32
+ # @param user_profile - Hash user profile.
33
+ def save(user_profile); end
34
+ end
35
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'logger'
4
+
5
+ module Optimizely
6
+ class UserProfileTracker
7
+ attr_reader :user_profile
8
+
9
+ def initialize(user_id, user_profile_service = nil, logger = nil)
10
+ @user_id = user_id
11
+ @user_profile_service = user_profile_service
12
+ @logger = logger || NoOpLogger.new
13
+ @profile_updated = false
14
+ @user_profile = {
15
+ user_id: user_id,
16
+ experiment_bucket_map: {}
17
+ }
18
+ end
19
+
20
+ def load_user_profile(reasons = [], error_handler = nil)
21
+ return if reasons.nil?
22
+
23
+ begin
24
+ @user_profile = @user_profile_service.lookup(@user_id) if @user_profile_service
25
+ if @user_profile.nil?
26
+ @user_profile = {
27
+ user_id: @user_id,
28
+ experiment_bucket_map: {}
29
+ }
30
+ end
31
+ rescue => e
32
+ message = "Error while looking up user profile for user ID '#{@user_id}': #{e}."
33
+ reasons << message
34
+ @logger.log(Logger::ERROR, message)
35
+ error_handler&.handle_error(e)
36
+ end
37
+ end
38
+
39
+ def update_user_profile(experiment_id, variation_id)
40
+ user_id = @user_profile[:user_id]
41
+ begin
42
+ @user_profile[:experiment_bucket_map][experiment_id] = {
43
+ variation_id: variation_id
44
+ }
45
+ @profile_updated = true
46
+ @logger.log(Logger::INFO, "Updated variation ID #{variation_id} of experiment ID #{experiment_id} for user '#{user_id}'.")
47
+ rescue => e
48
+ @logger.log(Logger::ERROR, "Error while updating user profile for user ID '#{user_id}': #{e}.")
49
+ end
50
+ end
51
+
52
+ def save_user_profile(error_handler = nil)
53
+ return unless @profile_updated && @user_profile_service
54
+
55
+ begin
56
+ @user_profile_service.save(@user_profile)
57
+ @logger.log(Logger::INFO, "Saved user profile for user '#{@user_profile[:user_id]}'.")
58
+ rescue => e
59
+ @logger.log(Logger::ERROR, "Failed to save user profile for user '#{@user_profile[:user_id]}': #{e}.")
60
+ error_handler&.handle_error(e)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -1,21 +1,21 @@
1
- # frozen_string_literal: true
2
-
3
- #
4
- # Copyright 2016-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
- module Optimizely
19
- CLIENT_ENGINE = 'ruby-sdk'
20
- VERSION = '5.0.0'
21
- end
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright 2016-2024, 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
+ CLIENT_ENGINE = 'ruby-sdk'
20
+ VERSION = '5.1.0'
21
+ end