vwo-fme-ruby-sdk 1.2.0 → 1.3.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/lib/resources/debug_messages.json +8 -1
- data/lib/resources/error_messages.json +5 -1
- data/lib/resources/info_messages.json +9 -1
- data/lib/vwo/api/get_flag.rb +30 -27
- data/lib/vwo/api/set_attribute.rb +10 -3
- data/lib/vwo/api/track_event.rb +11 -3
- data/lib/vwo/constants/constants.rb +6 -2
- data/lib/vwo/decorators/storage_decorator.rb +1 -1
- data/lib/vwo/enums/api_enum.rb +1 -1
- data/lib/vwo/enums/campaign_type_enum.rb +1 -1
- data/lib/vwo/enums/decision_types_enum.rb +1 -1
- data/lib/vwo/enums/event_enum.rb +1 -1
- data/lib/vwo/enums/headers_enum.rb +1 -1
- data/lib/vwo/enums/hooks_enum.rb +1 -1
- data/lib/vwo/enums/http_method_enum.rb +1 -1
- data/lib/vwo/enums/log_level_enum.rb +1 -1
- data/lib/vwo/enums/status_enum.rb +1 -1
- data/lib/vwo/enums/storage_enum.rb +1 -1
- data/lib/vwo/enums/url_enum.rb +2 -1
- data/lib/vwo/models/campaign/campaign_model.rb +1 -1
- data/lib/vwo/models/campaign/feature_model.rb +1 -1
- data/lib/vwo/models/campaign/impact_campaign_model.rb +1 -1
- data/lib/vwo/models/campaign/metric_model.rb +1 -1
- data/lib/vwo/models/campaign/rule_model.rb +1 -1
- data/lib/vwo/models/campaign/variable_model.rb +1 -1
- data/lib/vwo/models/campaign/variation_model.rb +1 -1
- data/lib/vwo/models/gateway_service_model.rb +1 -1
- data/lib/vwo/models/schemas/settings_schema_validation.rb +1 -1
- data/lib/vwo/models/settings/settings_model.rb +8 -2
- data/lib/vwo/models/storage/storage_data_model.rb +1 -1
- data/lib/vwo/models/user/context_model.rb +1 -1
- data/lib/vwo/models/user/context_vwo_model.rb +1 -1
- data/lib/vwo/models/user/get_flag_response.rb +1 -1
- data/lib/vwo/models/vwo_options_model.rb +1 -1
- data/lib/vwo/packages/decision_maker/decision_maker.rb +1 -1
- data/lib/vwo/packages/logger/core/log_manager.rb +1 -1
- data/lib/vwo/packages/logger/core/transport_manager.rb +1 -1
- data/lib/vwo/packages/logger/log_message_builder.rb +1 -1
- data/lib/vwo/packages/logger/logger.rb +1 -1
- data/lib/vwo/packages/logger/transports/console_transport.rb +1 -1
- data/lib/vwo/packages/network_layer/client/network_client.rb +39 -25
- data/lib/vwo/packages/network_layer/handlers/request_handler.rb +1 -1
- data/lib/vwo/packages/network_layer/manager/network_manager.rb +6 -4
- data/lib/vwo/packages/network_layer/models/global_request_model.rb +1 -1
- data/lib/vwo/packages/network_layer/models/request_model.rb +1 -1
- data/lib/vwo/packages/network_layer/models/response_model.rb +9 -1
- data/lib/vwo/packages/segmentation_evaluator/core/segmentation_manager.rb +1 -1
- data/lib/vwo/packages/segmentation_evaluator/enums/segment_operand_regex_enum.rb +1 -1
- data/lib/vwo/packages/segmentation_evaluator/enums/segment_operand_value_enum.rb +1 -1
- data/lib/vwo/packages/segmentation_evaluator/enums/segment_operator_value_enum.rb +1 -1
- data/lib/vwo/packages/segmentation_evaluator/evaluators/segment_evaluator.rb +1 -1
- data/lib/vwo/packages/segmentation_evaluator/evaluators/segment_operand_evaluator.rb +1 -1
- data/lib/vwo/packages/segmentation_evaluator/utils/segment_util.rb +1 -1
- data/lib/vwo/packages/storage/connector.rb +1 -1
- data/lib/vwo/packages/storage/storage.rb +3 -1
- data/lib/vwo/services/batch_event_queue.rb +179 -0
- data/lib/vwo/services/campaign_decision_service.rb +1 -1
- data/lib/vwo/services/hooks_service.rb +1 -1
- data/lib/vwo/services/logger_service.rb +1 -1
- data/lib/vwo/services/settings_service.rb +4 -2
- data/lib/vwo/services/storage_service.rb +1 -1
- data/lib/vwo/utils/batch_event_dispatcher.rb +117 -0
- data/lib/vwo/utils/campaign_util.rb +1 -1
- data/lib/vwo/utils/data_type_util.rb +1 -1
- data/lib/vwo/utils/decision_util.rb +1 -1
- data/lib/vwo/utils/function_util.rb +5 -1
- data/lib/vwo/utils/gateway_service_util.rb +1 -1
- data/lib/vwo/utils/impression_util.rb +10 -3
- data/lib/vwo/utils/log_message_util.rb +1 -1
- data/lib/vwo/utils/meg_util.rb +1 -1
- data/lib/vwo/utils/network_util.rb +16 -7
- data/lib/vwo/utils/rule_evaluation_util.rb +1 -1
- data/lib/vwo/utils/settings_util.rb +1 -1
- data/lib/vwo/utils/url_util.rb +1 -1
- data/lib/vwo/utils/uuid_util.rb +1 -1
- data/lib/vwo/vwo_builder.rb +97 -24
- data/lib/vwo/vwo_client.rb +23 -4
- data/lib/vwo.rb +2 -1
- metadata +4 -2
data/lib/vwo/vwo_builder.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright 2025 Wingify Software Pvt. Ltd.
|
1
|
+
# Copyright 2024-2025 Wingify Software Pvt. Ltd.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -21,9 +21,13 @@ require_relative './packages/storage/storage'
|
|
21
21
|
require_relative './packages/network_layer/manager/network_manager'
|
22
22
|
require_relative './packages/segmentation_evaluator/core/segmentation_manager'
|
23
23
|
require_relative './services/logger_service'
|
24
|
+
require_relative './services/batch_event_queue'
|
25
|
+
require_relative './utils/function_util'
|
26
|
+
require_relative './utils/batch_event_dispatcher'
|
27
|
+
require_relative './constants/constants'
|
24
28
|
|
25
29
|
class VWOBuilder
|
26
|
-
attr_reader :settings, :storage, :log_manager, :is_settings_fetch_in_progress, :vwo_instance
|
30
|
+
attr_reader :settings, :storage, :log_manager, :is_settings_fetch_in_progress, :vwo_instance, :is_valid_poll_interval_passed_from_init
|
27
31
|
|
28
32
|
# Initialize the VWOBuilder with the given options
|
29
33
|
# @param options [Hash] The options for the VWOBuilder
|
@@ -33,9 +37,50 @@ class VWOBuilder
|
|
33
37
|
@storage = nil
|
34
38
|
@log_manager = nil
|
35
39
|
@is_settings_fetch_in_progress = false
|
40
|
+
@is_valid_poll_interval_passed_from_init = false
|
36
41
|
@vwo_instance = nil
|
37
42
|
end
|
38
43
|
|
44
|
+
# Initializes the batch event processing system
|
45
|
+
# Validates batch event settings and configures the BatchEventsQueue
|
46
|
+
# Sets up event dispatcher and flushes any existing events
|
47
|
+
# @raise [StandardError] If batch event configuration is invalid
|
48
|
+
def init_batch
|
49
|
+
# if gateway service is configured, then do not initialize batch event queue
|
50
|
+
if SettingsService.instance.is_gateway_service_provided
|
51
|
+
LoggerService.log(LogLevelEnum::INFO, "GATEWAY_AND_BATCH_EVENTS_CONFIG_MISMATCH")
|
52
|
+
return self
|
53
|
+
end
|
54
|
+
begin
|
55
|
+
if @options.key?(:batch_event_data)
|
56
|
+
if @options[:batch_event_data].is_a?(Hash)
|
57
|
+
# Validate batch event parameters
|
58
|
+
events_per_request = @options[:batch_event_data][:events_per_request]
|
59
|
+
request_time_interval = @options[:batch_event_data][:request_time_interval]
|
60
|
+
|
61
|
+
if (!events_per_request.is_a?(Numeric) || events_per_request <= 0) &&
|
62
|
+
(!request_time_interval.is_a?(Numeric) || request_time_interval <= 0)
|
63
|
+
LoggerService.log(LogLevelEnum::ERROR, "INVALID_BATCH_EVENTS_CONFIG")
|
64
|
+
end
|
65
|
+
|
66
|
+
BatchEventsQueue.configure(
|
67
|
+
@options[:batch_event_data].merge(
|
68
|
+
{
|
69
|
+
account_id: @options[:account_id],
|
70
|
+
dispatcher: method(:dispatcher)
|
71
|
+
}
|
72
|
+
)
|
73
|
+
)
|
74
|
+
@batch_event_data = @options[:batch_event_data]
|
75
|
+
else
|
76
|
+
LoggerService.log(LogLevelEnum::ERROR, "Invalid batch events config, should be a hash.", nil)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
rescue StandardError => e
|
80
|
+
LoggerService.log(LogLevelEnum::ERROR, "Failed to initialize batch event queue: #{e.message}", nil)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
39
84
|
# Set the network manager
|
40
85
|
# @return [VWOBuilder] The VWOBuilder instance
|
41
86
|
def set_network_manager
|
@@ -89,7 +134,12 @@ class VWOBuilder
|
|
89
134
|
# Set the storage
|
90
135
|
# @return [VWOBuilder] The VWOBuilder instance
|
91
136
|
def set_storage
|
92
|
-
|
137
|
+
if @options[:storage]
|
138
|
+
@storage = Storage.instance.attach_connector(@options[:storage])
|
139
|
+
Storage.instance.is_storage_enabled = true
|
140
|
+
else
|
141
|
+
@storage = nil
|
142
|
+
end
|
93
143
|
LoggerService.log(LogLevelEnum::DEBUG, "SERVICE_INITIALIZED", {service: "Storage"})
|
94
144
|
self
|
95
145
|
end
|
@@ -116,26 +166,19 @@ class VWOBuilder
|
|
116
166
|
# Initialize the polling
|
117
167
|
# @return [VWOBuilder] The VWOBuilder instance
|
118
168
|
def init_polling
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
end
|
128
|
-
|
129
|
-
# Check if the polling interval is greater than or equal to 1000
|
130
|
-
unless @options[:poll_interval] >= 1000
|
169
|
+
poll_interval = @options[:poll_interval]
|
170
|
+
|
171
|
+
if poll_interval && poll_interval.is_a?(Numeric) && poll_interval >= 1000
|
172
|
+
# this is to check if the poll_interval passed in options is valid
|
173
|
+
@is_valid_poll_interval_passed_from_init = true
|
174
|
+
check_and_poll
|
175
|
+
elsif poll_interval
|
176
|
+
# only log error if poll_interval is present in options
|
131
177
|
LoggerService.log(LogLevelEnum::ERROR, "INIT_OPTIONS_INVALID", {
|
132
178
|
key: 'poll_interval',
|
133
|
-
correctType: 'number'
|
179
|
+
correctType: 'number >= 1000'
|
134
180
|
})
|
135
|
-
return self
|
136
181
|
end
|
137
|
-
|
138
|
-
check_and_poll
|
139
182
|
self
|
140
183
|
end
|
141
184
|
|
@@ -144,25 +187,42 @@ class VWOBuilder
|
|
144
187
|
# @return [VWOClient] The VWO instance
|
145
188
|
def build(settings)
|
146
189
|
@vwo_instance = VWOClient.new(settings, @options)
|
190
|
+
# if poll_interval is not present in options, set it to the pollInterval from settings
|
191
|
+
update_poll_interval_and_check_and_poll(settings)
|
147
192
|
@vwo_instance
|
148
193
|
end
|
149
194
|
|
195
|
+
def update_poll_interval_and_check_and_poll(settings, should_check_and_poll = true)
|
196
|
+
# only update the poll_interval if it poll_interval is not valid or not present in options
|
197
|
+
if !@is_valid_poll_interval_passed_from_init
|
198
|
+
@options[:poll_interval] = settings["pollInterval"] || Constants::POLLING_INTERVAL
|
199
|
+
LoggerService.log(LogLevelEnum::DEBUG, "USING_POLL_INTERVAL_FROM_SETTINGS", {
|
200
|
+
source: settings["pollInterval"] ? 'settings' : 'default',
|
201
|
+
pollInterval: @options[:poll_interval]
|
202
|
+
})
|
203
|
+
end
|
204
|
+
# should_check_and_poll will be true only when we are updating the poll_interval first time from self.build method
|
205
|
+
# if we are updating the poll_interval already running polling, we don't need to check and poll again
|
206
|
+
if should_check_and_poll && !@is_valid_poll_interval_passed_from_init
|
207
|
+
check_and_poll
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
150
211
|
# This method is used to check and poll the settings from the server
|
151
212
|
# @return [VWOBuilder] The VWOBuilder instance
|
152
213
|
def check_and_poll
|
153
|
-
polling_interval = @options[:poll_interval]
|
154
|
-
|
155
214
|
@thread_pool = NetworkManager.instance.get_client.get_thread_pool
|
156
215
|
@thread_pool.post do
|
157
216
|
loop do
|
158
|
-
sleep(
|
217
|
+
sleep(@options[:poll_interval]/ 1000.0)
|
159
218
|
begin
|
160
219
|
latest_settings = fetch_settings(true)
|
161
|
-
if latest_settings.to_json != @settings.to_json
|
220
|
+
if latest_settings && latest_settings.to_json != @settings.to_json
|
162
221
|
@settings = latest_settings
|
163
222
|
LoggerService.log(LogLevelEnum::INFO, "POLLING_SET_SETTINGS")
|
164
223
|
@vwo_instance.update_settings(latest_settings.clone, false) if @vwo_instance
|
165
|
-
|
224
|
+
update_poll_interval_and_check_and_poll(latest_settings, false)
|
225
|
+
elsif latest_settings
|
166
226
|
LoggerService.log(LogLevelEnum::INFO, "POLLING_NO_CHANGE_IN_SETTINGS")
|
167
227
|
end
|
168
228
|
rescue StandardError => e
|
@@ -171,4 +231,17 @@ class VWOBuilder
|
|
171
231
|
end
|
172
232
|
end
|
173
233
|
end
|
234
|
+
|
235
|
+
def dispatcher(events, callback)
|
236
|
+
BatchEventDispatcher.dispatch(
|
237
|
+
{
|
238
|
+
ev: events
|
239
|
+
},
|
240
|
+
callback,
|
241
|
+
{
|
242
|
+
a: @options[:account_id],
|
243
|
+
env: @options[:sdk_key]
|
244
|
+
}
|
245
|
+
)
|
246
|
+
end
|
174
247
|
end
|
data/lib/vwo/vwo_client.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright 2025 Wingify Software Pvt. Ltd.
|
1
|
+
# Copyright 2024-2025 Wingify Software Pvt. Ltd.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -23,6 +23,7 @@ require_relative 'services/logger_service'
|
|
23
23
|
require_relative 'enums/log_level_enum'
|
24
24
|
require_relative 'utils/network_util'
|
25
25
|
require_relative 'models/schemas/settings_schema_validation'
|
26
|
+
require_relative 'services/batch_event_queue'
|
26
27
|
|
27
28
|
class VWOClient
|
28
29
|
attr_accessor :settings, :original_settings
|
@@ -59,7 +60,7 @@ class VWOClient
|
|
59
60
|
LoggerService.log(LogLevelEnum::ERROR, "API_INVALID_PARAM", {apiName: api_name, key: 'feature_key', type: feature_key.class.name , correctType: 'String'})
|
60
61
|
raise TypeError, 'feature_key should be a non-empty string'
|
61
62
|
end
|
62
|
-
unless
|
63
|
+
unless SettingsService.instance.is_settings_valid
|
63
64
|
LoggerService.log(LogLevelEnum::ERROR, "API_SETTING_INVALID")
|
64
65
|
raise TypeError, 'Invalid Settings'
|
65
66
|
end
|
@@ -100,7 +101,7 @@ class VWOClient
|
|
100
101
|
LoggerService.log(LogLevelEnum::ERROR, "API_INVALID_PARAM", {apiName: api_name, key: 'event_properties', type: event_properties.class.name, correctType: 'Hash'})
|
101
102
|
raise TypeError, 'event_properties should be a hash'
|
102
103
|
end
|
103
|
-
unless
|
104
|
+
unless SettingsService.instance.is_settings_valid
|
104
105
|
LoggerService.log(LogLevelEnum::ERROR, "API_SETTING_INVALID")
|
105
106
|
raise TypeError, 'Invalid Settings'
|
106
107
|
end
|
@@ -139,7 +140,7 @@ class VWOClient
|
|
139
140
|
LoggerService.log(LogLevelEnum::ERROR, "API_INVALID_PARAM", {apiName: api_name, key: 'context.id', type: context[:id].class.name, correctType: 'String'})
|
140
141
|
raise TypeError, 'Invalid context, id should be a non-empty string'
|
141
142
|
end
|
142
|
-
unless
|
143
|
+
unless SettingsService.instance.is_settings_valid
|
143
144
|
LoggerService.log(LogLevelEnum::ERROR, "API_SETTING_INVALID")
|
144
145
|
raise TypeError, 'Invalid Settings'
|
145
146
|
end
|
@@ -189,4 +190,22 @@ class VWOClient
|
|
189
190
|
)
|
190
191
|
end
|
191
192
|
end
|
193
|
+
|
194
|
+
# Flushes the batch events queue
|
195
|
+
# @return [void]
|
196
|
+
def flush_events
|
197
|
+
api_name = 'flush_events'
|
198
|
+
begin
|
199
|
+
LoggerService.log(LogLevelEnum::DEBUG, "API_CALLED", {apiName: api_name})
|
200
|
+
if BatchEventsQueue.instance.nil?
|
201
|
+
LoggerService.log(LogLevelEnum::ERROR, "Batching is not enabled. Pass batch_event_data in the SDK configuration while invoking init API.", nil)
|
202
|
+
raise StandardError, "Batch events queue is not initialized"
|
203
|
+
end
|
204
|
+
# flush the batch events queue
|
205
|
+
@response = BatchEventsQueue.instance.flush(true)
|
206
|
+
@response
|
207
|
+
rescue StandardError => e
|
208
|
+
LoggerService.log(LogLevelEnum::ERROR, "API_THROW_ERROR", {apiName: api_name, err: e.message})
|
209
|
+
end
|
210
|
+
end
|
192
211
|
end
|
data/lib/vwo.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright 2025 Wingify Software Pvt. Ltd.
|
1
|
+
# Copyright 2024-2025 Wingify Software Pvt. Ltd.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -36,6 +36,7 @@ class VWO
|
|
36
36
|
.set_network_manager
|
37
37
|
.set_segmentation
|
38
38
|
.init_polling
|
39
|
+
.init_batch
|
39
40
|
|
40
41
|
if options[:settings]
|
41
42
|
return @@vwo_builder.build(options[:settings])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vwo-fme-ruby-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- VWO
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uuidtools
|
@@ -200,11 +200,13 @@ files:
|
|
200
200
|
- lib/vwo/packages/segmentation_evaluator/utils/segment_util.rb
|
201
201
|
- lib/vwo/packages/storage/connector.rb
|
202
202
|
- lib/vwo/packages/storage/storage.rb
|
203
|
+
- lib/vwo/services/batch_event_queue.rb
|
203
204
|
- lib/vwo/services/campaign_decision_service.rb
|
204
205
|
- lib/vwo/services/hooks_service.rb
|
205
206
|
- lib/vwo/services/logger_service.rb
|
206
207
|
- lib/vwo/services/settings_service.rb
|
207
208
|
- lib/vwo/services/storage_service.rb
|
209
|
+
- lib/vwo/utils/batch_event_dispatcher.rb
|
208
210
|
- lib/vwo/utils/campaign_util.rb
|
209
211
|
- lib/vwo/utils/data_type_util.rb
|
210
212
|
- lib/vwo/utils/decision_util.rb
|