optimizely-sdk 3.9.0 → 4.0.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 -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 -508
 - 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 -321
 - data/lib/optimizely/config_manager/project_config_manager.rb +24 -24
 - data/lib/optimizely/config_manager/static_project_config_manager.rb +53 -47
 - 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 -500
 - 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 -107
 - 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 -1117
 - metadata +13 -13
 
| 
         @@ -1,35 +1,36 @@ 
     | 
|
| 
       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 
     | 
    
         
            -
              class Visitor
         
     | 
| 
       20 
     | 
    
         
            -
                attr_reader :snapshots, :visitor_id, :attributes
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                  @ 
     | 
| 
       24 
     | 
    
         
            -
                  @ 
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
                     
     | 
| 
       31 
     | 
    
         
            -
                     
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            #
         
     | 
| 
      
 4 
     | 
    
         
            +
            #    Copyright 2019, 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 Visitor
         
     | 
| 
      
 20 
     | 
    
         
            +
                attr_reader :snapshots, :visitor_id, :attributes
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                def initialize(snapshots:, visitor_id:, attributes:)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  @snapshots = snapshots
         
     | 
| 
      
 24 
     | 
    
         
            +
                  @visitor_id = visitor_id
         
     | 
| 
      
 25 
     | 
    
         
            +
                  @attributes = attributes
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                def as_json
         
     | 
| 
      
 29 
     | 
    
         
            +
                  {
         
     | 
| 
      
 30 
     | 
    
         
            +
                    snapshots: @snapshots,
         
     | 
| 
      
 31 
     | 
    
         
            +
                    visitor_id: @visitor_id,
         
     | 
| 
      
 32 
     | 
    
         
            +
                    attributes: @attributes
         
     | 
| 
      
 33 
     | 
    
         
            +
                  }
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,37 +1,38 @@ 
     | 
|
| 
       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 
     | 
    
         
            -
              class VisitorAttribute
         
     | 
| 
       20 
     | 
    
         
            -
                attr_reader :entity_id, :key, :type, :value
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                  @ 
     | 
| 
       24 
     | 
    
         
            -
                  @ 
     | 
| 
       25 
     | 
    
         
            -
                  @ 
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                     
     | 
| 
       32 
     | 
    
         
            -
                     
     | 
| 
       33 
     | 
    
         
            -
                     
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            #
         
     | 
| 
      
 4 
     | 
    
         
            +
            #    Copyright 2019, 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 VisitorAttribute
         
     | 
| 
      
 20 
     | 
    
         
            +
                attr_reader :entity_id, :key, :type, :value
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                def initialize(entity_id:, key:, type:, value:)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  @entity_id = entity_id
         
     | 
| 
      
 24 
     | 
    
         
            +
                  @key = key
         
     | 
| 
      
 25 
     | 
    
         
            +
                  @type = type
         
     | 
| 
      
 26 
     | 
    
         
            +
                  @value = value
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                def as_json
         
     | 
| 
      
 30 
     | 
    
         
            +
                  {
         
     | 
| 
      
 31 
     | 
    
         
            +
                    entity_id: @entity_id,
         
     | 
| 
      
 32 
     | 
    
         
            +
                    key: @key,
         
     | 
| 
      
 33 
     | 
    
         
            +
                    type: @type,
         
     | 
| 
      
 34 
     | 
    
         
            +
                    value: @value
         
     | 
| 
      
 35 
     | 
    
         
            +
                  }
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
              end
         
     | 
| 
      
 38 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,155 +1,156 @@ 
     | 
|
| 
       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 
     | 
    
         
            -
            require_relative 'entity/event_batch'
         
     | 
| 
       19 
     | 
    
         
            -
            require_relative 'entity/conversion_event'
         
     | 
| 
       20 
     | 
    
         
            -
            require_relative 'entity/decision'
         
     | 
| 
       21 
     | 
    
         
            -
            require_relative 'entity/impression_event'
         
     | 
| 
       22 
     | 
    
         
            -
            require_relative 'entity/snapshot'
         
     | 
| 
       23 
     | 
    
         
            -
            require_relative 'entity/snapshot_event'
         
     | 
| 
       24 
     | 
    
         
            -
            require_relative 'entity/visitor'
         
     | 
| 
       25 
     | 
    
         
            -
            require 'optimizely/helpers/validator'
         
     | 
| 
       26 
     | 
    
         
            -
            module Optimizely
         
     | 
| 
       27 
     | 
    
         
            -
              class EventFactory
         
     | 
| 
       28 
     | 
    
         
            -
                # EventFactory builds LogEvent objects from a given user_event.
         
     | 
| 
       29 
     | 
    
         
            -
                class << self
         
     | 
| 
       30 
     | 
    
         
            -
                  CUSTOM_ATTRIBUTE_FEATURE_TYPE = 'custom'
         
     | 
| 
       31 
     | 
    
         
            -
                  ENDPOINT = 'https://logx.optimizely.com/v1/events'
         
     | 
| 
       32 
     | 
    
         
            -
                  POST_HEADERS = {'Content-Type' => 'application/json'}.freeze
         
     | 
| 
       33 
     | 
    
         
            -
                  ACTIVATE_EVENT_KEY = 'campaign_activated'
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                  def create_log_event(user_events, logger)
         
     | 
| 
       36 
     | 
    
         
            -
                    @logger = logger
         
     | 
| 
       37 
     | 
    
         
            -
                    builder = Optimizely::EventBatch::Builder.new
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                    user_events = [user_events] unless user_events.is_a? Array
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                    visitors = []
         
     | 
| 
       42 
     | 
    
         
            -
                    user_context = nil
         
     | 
| 
       43 
     | 
    
         
            -
                    user_events.each do |user_event|
         
     | 
| 
       44 
     | 
    
         
            -
                       
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
                         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
                         
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
                         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
                       
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
                    builder. 
     | 
| 
       61 
     | 
    
         
            -
                    builder. 
     | 
| 
       62 
     | 
    
         
            -
                    builder. 
     | 
| 
       63 
     | 
    
         
            -
                    builder. 
     | 
| 
       64 
     | 
    
         
            -
                    builder. 
     | 
| 
       65 
     | 
    
         
            -
                    builder. 
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
                     
     | 
| 
       69 
     | 
    
         
            -
                     
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
                     
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
                       
     | 
| 
       77 
     | 
    
         
            -
                       
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
                       
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
                         
     | 
| 
       85 
     | 
    
         
            -
                         
     | 
| 
       86 
     | 
    
         
            -
                         
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
                     
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
                       
     | 
| 
       96 
     | 
    
         
            -
                       
     | 
| 
       97 
     | 
    
         
            -
                       
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
                       
     | 
| 
       107 
     | 
    
         
            -
                       
     | 
| 
       108 
     | 
    
         
            -
                       
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
             
     | 
| 
       113 
     | 
    
         
            -
                       
     | 
| 
       114 
     | 
    
         
            -
                       
     | 
| 
       115 
     | 
    
         
            -
                       
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
                       
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
       125 
     | 
    
         
            -
                       
     | 
| 
       126 
     | 
    
         
            -
                       
     | 
| 
       127 
     | 
    
         
            -
             
     | 
| 
       128 
     | 
    
         
            -
                     
     | 
| 
       129 
     | 
    
         
            -
             
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
                     
     | 
| 
       134 
     | 
    
         
            -
                     
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
                       
     | 
| 
       137 
     | 
    
         
            -
                       
     | 
| 
       138 
     | 
    
         
            -
                       
     | 
| 
       139 
     | 
    
         
            -
                       
     | 
| 
       140 
     | 
    
         
            -
                       
     | 
| 
       141 
     | 
    
         
            -
                       
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
             
     | 
| 
       144 
     | 
    
         
            -
             
     | 
| 
       145 
     | 
    
         
            -
             
     | 
| 
       146 
     | 
    
         
            -
             
     | 
| 
       147 
     | 
    
         
            -
             
     | 
| 
       148 
     | 
    
         
            -
                       
     | 
| 
       149 
     | 
    
         
            -
                       
     | 
| 
       150 
     | 
    
         
            -
             
     | 
| 
       151 
     | 
    
         
            -
                     
     | 
| 
       152 
     | 
    
         
            -
             
     | 
| 
       153 
     | 
    
         
            -
             
     | 
| 
       154 
     | 
    
         
            -
             
     | 
| 
       155 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            #
         
     | 
| 
      
 4 
     | 
    
         
            +
            #    Copyright 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 'entity/event_batch'
         
     | 
| 
      
 19 
     | 
    
         
            +
            require_relative 'entity/conversion_event'
         
     | 
| 
      
 20 
     | 
    
         
            +
            require_relative 'entity/decision'
         
     | 
| 
      
 21 
     | 
    
         
            +
            require_relative 'entity/impression_event'
         
     | 
| 
      
 22 
     | 
    
         
            +
            require_relative 'entity/snapshot'
         
     | 
| 
      
 23 
     | 
    
         
            +
            require_relative 'entity/snapshot_event'
         
     | 
| 
      
 24 
     | 
    
         
            +
            require_relative 'entity/visitor'
         
     | 
| 
      
 25 
     | 
    
         
            +
            require 'optimizely/helpers/validator'
         
     | 
| 
      
 26 
     | 
    
         
            +
            module Optimizely
         
     | 
| 
      
 27 
     | 
    
         
            +
              class EventFactory
         
     | 
| 
      
 28 
     | 
    
         
            +
                # EventFactory builds LogEvent objects from a given user_event.
         
     | 
| 
      
 29 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 30 
     | 
    
         
            +
                  CUSTOM_ATTRIBUTE_FEATURE_TYPE = 'custom'
         
     | 
| 
      
 31 
     | 
    
         
            +
                  ENDPOINT = 'https://logx.optimizely.com/v1/events'
         
     | 
| 
      
 32 
     | 
    
         
            +
                  POST_HEADERS = {'Content-Type' => 'application/json'}.freeze
         
     | 
| 
      
 33 
     | 
    
         
            +
                  ACTIVATE_EVENT_KEY = 'campaign_activated'
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                  def create_log_event(user_events, logger)
         
     | 
| 
      
 36 
     | 
    
         
            +
                    @logger = logger
         
     | 
| 
      
 37 
     | 
    
         
            +
                    builder = Optimizely::EventBatch::Builder.new
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                    user_events = [user_events] unless user_events.is_a? Array
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                    visitors = []
         
     | 
| 
      
 42 
     | 
    
         
            +
                    user_context = nil
         
     | 
| 
      
 43 
     | 
    
         
            +
                    user_events.each do |user_event|
         
     | 
| 
      
 44 
     | 
    
         
            +
                      case user_event
         
     | 
| 
      
 45 
     | 
    
         
            +
                      when Optimizely::ImpressionEvent
         
     | 
| 
      
 46 
     | 
    
         
            +
                        visitor = create_impression_event_visitor(user_event)
         
     | 
| 
      
 47 
     | 
    
         
            +
                        visitors.push(visitor)
         
     | 
| 
      
 48 
     | 
    
         
            +
                      when Optimizely::ConversionEvent
         
     | 
| 
      
 49 
     | 
    
         
            +
                        visitor = create_conversion_event_visitor(user_event)
         
     | 
| 
      
 50 
     | 
    
         
            +
                        visitors.push(visitor)
         
     | 
| 
      
 51 
     | 
    
         
            +
                      else
         
     | 
| 
      
 52 
     | 
    
         
            +
                        @logger.log(Logger::WARN, 'invalid UserEvent added in a list.')
         
     | 
| 
      
 53 
     | 
    
         
            +
                        next
         
     | 
| 
      
 54 
     | 
    
         
            +
                      end
         
     | 
| 
      
 55 
     | 
    
         
            +
                      user_context = user_event.event_context
         
     | 
| 
      
 56 
     | 
    
         
            +
                    end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                    return nil if visitors.empty?
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                    builder.with_account_id(user_context[:account_id])
         
     | 
| 
      
 61 
     | 
    
         
            +
                    builder.with_project_id(user_context[:project_id])
         
     | 
| 
      
 62 
     | 
    
         
            +
                    builder.with_client_version(user_context[:client_version])
         
     | 
| 
      
 63 
     | 
    
         
            +
                    builder.with_revision(user_context[:revision])
         
     | 
| 
      
 64 
     | 
    
         
            +
                    builder.with_client_name(user_context[:client_name])
         
     | 
| 
      
 65 
     | 
    
         
            +
                    builder.with_anonymize_ip(user_context[:anonymize_ip])
         
     | 
| 
      
 66 
     | 
    
         
            +
                    builder.with_enrich_decisions(true)
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                    builder.with_visitors(visitors)
         
     | 
| 
      
 69 
     | 
    
         
            +
                    event_batch = builder.build
         
     | 
| 
      
 70 
     | 
    
         
            +
                    Event.new(:post, ENDPOINT, event_batch.as_json, POST_HEADERS)
         
     | 
| 
      
 71 
     | 
    
         
            +
                  end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                  def build_attribute_list(user_attributes, project_config)
         
     | 
| 
      
 74 
     | 
    
         
            +
                    visitor_attributes = []
         
     | 
| 
      
 75 
     | 
    
         
            +
                    user_attributes&.keys&.each do |attribute_key|
         
     | 
| 
      
 76 
     | 
    
         
            +
                      # Omit attribute values that are not supported by the log endpoint.
         
     | 
| 
      
 77 
     | 
    
         
            +
                      attribute_value = user_attributes[attribute_key]
         
     | 
| 
      
 78 
     | 
    
         
            +
                      next unless Helpers::Validator.attribute_valid?(attribute_key, attribute_value)
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                      attribute_id = project_config.get_attribute_id attribute_key
         
     | 
| 
      
 81 
     | 
    
         
            +
                      next if attribute_id.nil?
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                      visitor_attributes.push(
         
     | 
| 
      
 84 
     | 
    
         
            +
                        entity_id: attribute_id,
         
     | 
| 
      
 85 
     | 
    
         
            +
                        key: attribute_key,
         
     | 
| 
      
 86 
     | 
    
         
            +
                        type: CUSTOM_ATTRIBUTE_FEATURE_TYPE,
         
     | 
| 
      
 87 
     | 
    
         
            +
                        value: attribute_value
         
     | 
| 
      
 88 
     | 
    
         
            +
                      )
         
     | 
| 
      
 89 
     | 
    
         
            +
                    end
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
                    return visitor_attributes unless Helpers::Validator.boolean? project_config.bot_filtering
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                    # Append Bot Filtering Attribute
         
     | 
| 
      
 94 
     | 
    
         
            +
                    visitor_attributes.push(
         
     | 
| 
      
 95 
     | 
    
         
            +
                      entity_id: Optimizely::Helpers::Constants::CONTROL_ATTRIBUTES['BOT_FILTERING'],
         
     | 
| 
      
 96 
     | 
    
         
            +
                      key: Optimizely::Helpers::Constants::CONTROL_ATTRIBUTES['BOT_FILTERING'],
         
     | 
| 
      
 97 
     | 
    
         
            +
                      type: CUSTOM_ATTRIBUTE_FEATURE_TYPE,
         
     | 
| 
      
 98 
     | 
    
         
            +
                      value: project_config.bot_filtering
         
     | 
| 
      
 99 
     | 
    
         
            +
                    )
         
     | 
| 
      
 100 
     | 
    
         
            +
                  end
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
                  private
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                  def create_impression_event_visitor(impression_event)
         
     | 
| 
      
 105 
     | 
    
         
            +
                    decision = Decision.new(
         
     | 
| 
      
 106 
     | 
    
         
            +
                      campaign_id: impression_event.experiment_layer_id,
         
     | 
| 
      
 107 
     | 
    
         
            +
                      experiment_id: impression_event.experiment_id,
         
     | 
| 
      
 108 
     | 
    
         
            +
                      variation_id: impression_event.variation_id,
         
     | 
| 
      
 109 
     | 
    
         
            +
                      metadata: impression_event.metadata
         
     | 
| 
      
 110 
     | 
    
         
            +
                    )
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
                    snapshot_event = Optimizely::SnapshotEvent.new(
         
     | 
| 
      
 113 
     | 
    
         
            +
                      entity_id: impression_event.experiment_layer_id,
         
     | 
| 
      
 114 
     | 
    
         
            +
                      timestamp: impression_event.timestamp,
         
     | 
| 
      
 115 
     | 
    
         
            +
                      uuid: impression_event.uuid,
         
     | 
| 
      
 116 
     | 
    
         
            +
                      key: ACTIVATE_EVENT_KEY
         
     | 
| 
      
 117 
     | 
    
         
            +
                    )
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
                    snapshot = Optimizely::Snapshot.new(
         
     | 
| 
      
 120 
     | 
    
         
            +
                      events: [snapshot_event.as_json],
         
     | 
| 
      
 121 
     | 
    
         
            +
                      decisions: [decision.as_json]
         
     | 
| 
      
 122 
     | 
    
         
            +
                    )
         
     | 
| 
      
 123 
     | 
    
         
            +
             
     | 
| 
      
 124 
     | 
    
         
            +
                    visitor = Optimizely::Visitor.new(
         
     | 
| 
      
 125 
     | 
    
         
            +
                      snapshots: [snapshot.as_json],
         
     | 
| 
      
 126 
     | 
    
         
            +
                      visitor_id: impression_event.user_id,
         
     | 
| 
      
 127 
     | 
    
         
            +
                      attributes: impression_event.visitor_attributes
         
     | 
| 
      
 128 
     | 
    
         
            +
                    )
         
     | 
| 
      
 129 
     | 
    
         
            +
                    visitor.as_json
         
     | 
| 
      
 130 
     | 
    
         
            +
                  end
         
     | 
| 
      
 131 
     | 
    
         
            +
             
     | 
| 
      
 132 
     | 
    
         
            +
                  def create_conversion_event_visitor(conversion_event)
         
     | 
| 
      
 133 
     | 
    
         
            +
                    revenue_value = Helpers::EventTagUtils.get_revenue_value(conversion_event.tags, @logger)
         
     | 
| 
      
 134 
     | 
    
         
            +
                    numeric_value = Helpers::EventTagUtils.get_numeric_value(conversion_event.tags, @logger)
         
     | 
| 
      
 135 
     | 
    
         
            +
                    snapshot_event = Optimizely::SnapshotEvent.new(
         
     | 
| 
      
 136 
     | 
    
         
            +
                      entity_id: conversion_event.event['id'],
         
     | 
| 
      
 137 
     | 
    
         
            +
                      timestamp: conversion_event.timestamp,
         
     | 
| 
      
 138 
     | 
    
         
            +
                      uuid: conversion_event.uuid,
         
     | 
| 
      
 139 
     | 
    
         
            +
                      key: conversion_event.event['key'],
         
     | 
| 
      
 140 
     | 
    
         
            +
                      revenue: revenue_value,
         
     | 
| 
      
 141 
     | 
    
         
            +
                      value: numeric_value,
         
     | 
| 
      
 142 
     | 
    
         
            +
                      tags: conversion_event.tags
         
     | 
| 
      
 143 
     | 
    
         
            +
                    )
         
     | 
| 
      
 144 
     | 
    
         
            +
             
     | 
| 
      
 145 
     | 
    
         
            +
                    snapshot = Optimizely::Snapshot.new(events: [snapshot_event.as_json])
         
     | 
| 
      
 146 
     | 
    
         
            +
             
     | 
| 
      
 147 
     | 
    
         
            +
                    visitor = Optimizely::Visitor.new(
         
     | 
| 
      
 148 
     | 
    
         
            +
                      snapshots: [snapshot.as_json],
         
     | 
| 
      
 149 
     | 
    
         
            +
                      visitor_id: conversion_event.user_id,
         
     | 
| 
      
 150 
     | 
    
         
            +
                      attributes: conversion_event.visitor_attributes
         
     | 
| 
      
 151 
     | 
    
         
            +
                    )
         
     | 
| 
      
 152 
     | 
    
         
            +
                    visitor.as_json
         
     | 
| 
      
 153 
     | 
    
         
            +
                  end
         
     | 
| 
      
 154 
     | 
    
         
            +
                end
         
     | 
| 
      
 155 
     | 
    
         
            +
              end
         
     | 
| 
      
 156 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,25 +1,25 @@ 
     | 
|
| 
       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 
     | 
    
         
            -
              class EventProcessor
         
     | 
| 
       20 
     | 
    
         
            -
                # EventProcessor interface is used to provide an intermediary processing stage within
         
     | 
| 
       21 
     | 
    
         
            -
                # event production. It's assumed that the EventProcessor dispatches events via a provided
         
     | 
| 
       22 
     | 
    
         
            -
                # EventDispatcher.
         
     | 
| 
       23 
     | 
    
         
            -
                def process(user_event); end
         
     | 
| 
       24 
     | 
    
         
            -
              end
         
     | 
| 
       25 
     | 
    
         
            -
            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 
     | 
    
         
            +
              class EventProcessor
         
     | 
| 
      
 20 
     | 
    
         
            +
                # EventProcessor interface is used to provide an intermediary processing stage within
         
     | 
| 
      
 21 
     | 
    
         
            +
                # event production. It's assumed that the EventProcessor dispatches events via a provided
         
     | 
| 
      
 22 
     | 
    
         
            +
                # EventDispatcher.
         
     | 
| 
      
 23 
     | 
    
         
            +
                def process(user_event); end
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,43 +1,44 @@ 
     | 
|
| 
       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 
     | 
    
         
            -
            require_relative 'event_processor'
         
     | 
| 
       19 
     | 
    
         
            -
            module Optimizely
         
     | 
| 
       20 
     | 
    
         
            -
              class ForwardingEventProcessor < EventProcessor
         
     | 
| 
       21 
     | 
    
         
            -
                # ForwardingEventProcessor is a basic transformation stage for converting
         
     | 
| 
       22 
     | 
    
         
            -
                # the event batch into a LogEvent to be dispatched.
         
     | 
| 
       23 
     | 
    
         
            -
                def initialize(event_dispatcher, logger = nil, notification_center = nil)
         
     | 
| 
       24 
     | 
    
         
            -
                   
     | 
| 
       25 
     | 
    
         
            -
                  @ 
     | 
| 
       26 
     | 
    
         
            -
                  @ 
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
                    @ 
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
                       
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            #
         
     | 
| 
      
 4 
     | 
    
         
            +
            #    Copyright 2019, 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 'event_processor'
         
     | 
| 
      
 19 
     | 
    
         
            +
            module Optimizely
         
     | 
| 
      
 20 
     | 
    
         
            +
              class ForwardingEventProcessor < EventProcessor
         
     | 
| 
      
 21 
     | 
    
         
            +
                # ForwardingEventProcessor is a basic transformation stage for converting
         
     | 
| 
      
 22 
     | 
    
         
            +
                # the event batch into a LogEvent to be dispatched.
         
     | 
| 
      
 23 
     | 
    
         
            +
                def initialize(event_dispatcher, logger = nil, notification_center = nil)
         
     | 
| 
      
 24 
     | 
    
         
            +
                  super()
         
     | 
| 
      
 25 
     | 
    
         
            +
                  @event_dispatcher = event_dispatcher
         
     | 
| 
      
 26 
     | 
    
         
            +
                  @logger = logger || NoOpLogger.new
         
     | 
| 
      
 27 
     | 
    
         
            +
                  @notification_center = notification_center
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                def process(user_event)
         
     | 
| 
      
 31 
     | 
    
         
            +
                  log_event = Optimizely::EventFactory.create_log_event(user_event, @logger)
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 34 
     | 
    
         
            +
                    @event_dispatcher.dispatch_event(log_event)
         
     | 
| 
      
 35 
     | 
    
         
            +
                    @notification_center&.send_notifications(
         
     | 
| 
      
 36 
     | 
    
         
            +
                      NotificationCenter::NOTIFICATION_TYPES[:LOG_EVENT],
         
     | 
| 
      
 37 
     | 
    
         
            +
                      log_event
         
     | 
| 
      
 38 
     | 
    
         
            +
                    )
         
     | 
| 
      
 39 
     | 
    
         
            +
                  rescue StandardError => e
         
     | 
| 
      
 40 
     | 
    
         
            +
                    @logger.log(Logger::ERROR, "Error dispatching event: #{log_event} #{e.message}.")
         
     | 
| 
      
 41 
     | 
    
         
            +
                  end
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
            end
         
     |