optimizely-sdk 5.0.0.pre.beta → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) 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 +48 -32
  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 -338
  10. data/lib/optimizely/config_manager/project_config_manager.rb +25 -25
  11. data/lib/optimizely/config_manager/static_project_config_manager.rb +55 -54
  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 -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 -149
  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 -238
  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 -271
  55. data/lib/optimizely/optimizely_factory.rb +184 -186
  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/version.rb +21 -21
  63. data/lib/optimizely.rb +1262 -1262
  64. metadata +12 -10
@@ -1,36 +1,36 @@
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
+ # 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,38 +1,38 @@
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
+ # 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,156 +1,156 @@
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
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright 2019-2020, 2022-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
+ 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&.each_key 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,44 +1,44 @@
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
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