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,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
- def initialize(snapshots:, visitor_id:, attributes:)
22
- @snapshots = snapshots
23
- @visitor_id = visitor_id
24
- @attributes = attributes
25
- end
26
-
27
- def as_json
28
- {
29
- snapshots: @snapshots,
30
- visitor_id: @visitor_id,
31
- attributes: @attributes
32
- }
33
- end
34
- end
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
- def initialize(entity_id:, key:, type:, value:)
22
- @entity_id = entity_id
23
- @key = key
24
- @type = type
25
- @value = value
26
- end
27
-
28
- def as_json
29
- {
30
- entity_id: @entity_id,
31
- key: @key,
32
- type: @type,
33
- value: @value
34
- }
35
- end
36
- end
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
- if user_event.is_a? Optimizely::ImpressionEvent
45
- visitor = create_impression_event_visitor(user_event)
46
- visitors.push(visitor)
47
- elsif user_event.is_a? Optimizely::ConversionEvent
48
- visitor = create_conversion_event_visitor(user_event)
49
- visitors.push(visitor)
50
- else
51
- @logger.log(Logger::WARN, 'invalid UserEvent added in a list.')
52
- next
53
- end
54
- user_context = user_event.event_context
55
- end
56
-
57
- return nil if visitors.empty?
58
-
59
- builder.with_account_id(user_context[:account_id])
60
- builder.with_project_id(user_context[:project_id])
61
- builder.with_client_version(user_context[:client_version])
62
- builder.with_revision(user_context[:revision])
63
- builder.with_client_name(user_context[:client_name])
64
- builder.with_anonymize_ip(user_context[:anonymize_ip])
65
- builder.with_enrich_decisions(true)
66
-
67
- builder.with_visitors(visitors)
68
- event_batch = builder.build
69
- Event.new(:post, ENDPOINT, event_batch.as_json, POST_HEADERS)
70
- end
71
-
72
- def build_attribute_list(user_attributes, project_config)
73
- visitor_attributes = []
74
- user_attributes&.keys&.each do |attribute_key|
75
- # Omit attribute values that are not supported by the log endpoint.
76
- attribute_value = user_attributes[attribute_key]
77
- next unless Helpers::Validator.attribute_valid?(attribute_key, attribute_value)
78
-
79
- attribute_id = project_config.get_attribute_id attribute_key
80
- next if attribute_id.nil?
81
-
82
- visitor_attributes.push(
83
- entity_id: attribute_id,
84
- key: attribute_key,
85
- type: CUSTOM_ATTRIBUTE_FEATURE_TYPE,
86
- value: attribute_value
87
- )
88
- end
89
-
90
- return visitor_attributes unless Helpers::Validator.boolean? project_config.bot_filtering
91
-
92
- # Append Bot Filtering Attribute
93
- visitor_attributes.push(
94
- entity_id: Optimizely::Helpers::Constants::CONTROL_ATTRIBUTES['BOT_FILTERING'],
95
- key: Optimizely::Helpers::Constants::CONTROL_ATTRIBUTES['BOT_FILTERING'],
96
- type: CUSTOM_ATTRIBUTE_FEATURE_TYPE,
97
- value: project_config.bot_filtering
98
- )
99
- end
100
-
101
- private
102
-
103
- def create_impression_event_visitor(impression_event)
104
- decision = Decision.new(
105
- campaign_id: impression_event.experiment_layer_id,
106
- experiment_id: impression_event.experiment_id,
107
- variation_id: impression_event.variation_id,
108
- metadata: impression_event.metadata
109
- )
110
-
111
- snapshot_event = Optimizely::SnapshotEvent.new(
112
- entity_id: impression_event.experiment_layer_id,
113
- timestamp: impression_event.timestamp,
114
- uuid: impression_event.uuid,
115
- key: ACTIVATE_EVENT_KEY
116
- )
117
-
118
- snapshot = Optimizely::Snapshot.new(
119
- events: [snapshot_event.as_json],
120
- decisions: [decision.as_json]
121
- )
122
-
123
- visitor = Optimizely::Visitor.new(
124
- snapshots: [snapshot.as_json],
125
- visitor_id: impression_event.user_id,
126
- attributes: impression_event.visitor_attributes
127
- )
128
- visitor.as_json
129
- end
130
-
131
- def create_conversion_event_visitor(conversion_event)
132
- revenue_value = Helpers::EventTagUtils.get_revenue_value(conversion_event.tags, @logger)
133
- numeric_value = Helpers::EventTagUtils.get_numeric_value(conversion_event.tags, @logger)
134
- snapshot_event = Optimizely::SnapshotEvent.new(
135
- entity_id: conversion_event.event['id'],
136
- timestamp: conversion_event.timestamp,
137
- uuid: conversion_event.uuid,
138
- key: conversion_event.event['key'],
139
- revenue: revenue_value,
140
- value: numeric_value,
141
- tags: conversion_event.tags
142
- )
143
-
144
- snapshot = Optimizely::Snapshot.new(events: [snapshot_event.as_json])
145
-
146
- visitor = Optimizely::Visitor.new(
147
- snapshots: [snapshot.as_json],
148
- visitor_id: conversion_event.user_id,
149
- attributes: conversion_event.visitor_attributes
150
- )
151
- visitor.as_json
152
- end
153
- end
154
- end
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
- @event_dispatcher = event_dispatcher
25
- @logger = logger || NoOpLogger.new
26
- @notification_center = notification_center
27
- end
28
-
29
- def process(user_event)
30
- log_event = Optimizely::EventFactory.create_log_event(user_event, @logger)
31
-
32
- begin
33
- @event_dispatcher.dispatch_event(log_event)
34
- @notification_center&.send_notifications(
35
- NotificationCenter::NOTIFICATION_TYPES[:LOG_EVENT],
36
- log_event
37
- )
38
- rescue StandardError => e
39
- @logger.log(Logger::ERROR, "Error dispatching event: #{log_event} #{e.message}.")
40
- end
41
- end
42
- end
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