vwo-fme-ruby-sdk 1.3.0 → 1.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21c0e79e4c0cca26188c44b647de95c940bf919e4f88f584ef41836068f1cff2
4
- data.tar.gz: 4ef7bda68a051cb7365d9607ba8d48e0dc82924a11cabaedbbb947db73b15999
3
+ metadata.gz: a93237647aaaac411d5ecd0d6eed52c33778282ab781ffc236ea2b46ed88a3e5
4
+ data.tar.gz: 52eecf7bf9d7f96c194715e510e0190346aa1f1f63f941fbbf311e9786364097
5
5
  SHA512:
6
- metadata.gz: 0450c78a51f8a3fa8352c9b6fe66b6ec48b448187e7fcad33e501f6810d53d919b6d0ec9492a314d9885cb9a28568c0ffe1248e3742f99da8415f735622c2d60
7
- data.tar.gz: d4aa3eca37dfbff8f035af7392d92851bbf239234f1bd933e7c7143ca0ebec5778d9e5e6159a11f9601c986ea6533331bc55013351a3a81ecc5f2b957587e674
6
+ metadata.gz: e6eb2497b2968e79662cd6161ee4b4fa849510bb1fa6edefd3b4becaec0b10be48c01bb7aec48f84f4b139048bec79cdf4dd97366a2a124519491c940a6c82fe
7
+ data.tar.gz: 8db5b2ee18a59597d9ef3072e847defaf7aaab30d93426cf1c15229a451591903c91e8c2f0627a6b48b1c5d85a59beff749e017d222f2a494cae7869915dac5d
@@ -17,7 +17,7 @@
17
17
  # Define the Constants module
18
18
  module Constants
19
19
  SDK_NAME = 'vwo-fme-ruby-sdk'.freeze
20
- SDK_VERSION = '1.3.0'.freeze
20
+ SDK_VERSION = '1.3.1'.freeze
21
21
 
22
22
  MAX_TRAFFIC_PERCENT = 100
23
23
  MAX_TRAFFIC_VALUE = 10_000
@@ -0,0 +1,27 @@
1
+ # Copyright 2024-2025 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module LogLevelToNumber
16
+ LEVELS = {
17
+ 'TRACE' => 0,
18
+ 'DEBUG' => 1,
19
+ 'INFO' => 2,
20
+ 'WARN' => 3,
21
+ 'ERROR' => 4
22
+ }.freeze
23
+
24
+ def self.to_number(level)
25
+ LEVELS[level.to_s.upcase] || 0
26
+ end
27
+ end
@@ -15,7 +15,7 @@
15
15
  class VWOOptionsModel
16
16
  attr_accessor :account_id, :sdk_key, :is_development_mode, :storage, :gateway_service,
17
17
  :poll_interval, :logger, :segmentation, :integrations, :network,
18
- :should_wait_for_tracking_calls, :settings, :vwo_builder
18
+ :should_wait_for_tracking_calls, :settings, :vwo_builder, :is_usage_stats_disabled, :_vwo_meta
19
19
 
20
20
  def initialize(options = {})
21
21
  @account_id = options[:account_id]
@@ -31,6 +31,8 @@ class VWOOptionsModel
31
31
  @should_wait_for_tracking_calls = options[:should_wait_for_tracking_calls]
32
32
  @settings = options[:settings]
33
33
  @vwo_builder = options[:vwo_builder]
34
+ @is_usage_stats_disabled = options[:is_usage_stats_disabled]
35
+ @_vwo_meta = options[:_vwo_meta]
34
36
  end
35
37
 
36
38
  # Creates a model instance from a hash (dictionary)
@@ -104,4 +106,13 @@ class VWOOptionsModel
104
106
  def get_vwo_builder
105
107
  @vwo_builder
106
108
  end
109
+
110
+ def get_is_usage_stats_disabled
111
+ @is_usage_stats_disabled
112
+ end
113
+
114
+ def get_vwo_meta
115
+ @_vwo_meta
116
+ end
117
+
107
118
  end
@@ -13,6 +13,7 @@
13
13
  # limitations under the License.
14
14
 
15
15
  require_relative '../log_message_builder'
16
+ require_relative '../../../enums/log_level_to_number'
16
17
 
17
18
  class LogTransportManager
18
19
  def initialize(config)
@@ -25,8 +26,8 @@ class LogTransportManager
25
26
  end
26
27
 
27
28
  def should_log?(transport_level, config_level)
28
- target_level = log_level_to_number(transport_level)
29
- desired_level = log_level_to_number(config_level || @config[:level])
29
+ target_level = LogLevelToNumber.to_number(transport_level)
30
+ desired_level = LogLevelToNumber.to_number(config_level || @config[:level])
30
31
  target_level >= desired_level
31
32
  end
32
33
 
@@ -70,18 +71,6 @@ class LogTransportManager
70
71
  end
71
72
  end
72
73
  end
73
-
74
- private
75
-
76
- def log_level_to_number(level)
77
- {
78
- 'TRACE' => 0,
79
- 'DEBUG' => 1,
80
- 'INFO' => 2,
81
- 'WARN' => 3,
82
- 'ERROR' => 4
83
- }[level.upcase] || 0
84
- end
85
74
  end
86
75
 
87
76
 
@@ -23,6 +23,7 @@ require_relative '../packages/network_layer/models/request_model'
23
23
  require_relative '../packages/network_layer/models/response_model'
24
24
  require_relative '../utils/url_util'
25
25
  require_relative '../utils/uuid_util'
26
+ require_relative '../utils/usage_stats_util'
26
27
 
27
28
  class NetworkUtil
28
29
  class << self
@@ -132,6 +133,12 @@ class NetworkUtil
132
133
  # Only add visitor_ua and visitor_ip if they are non-null
133
134
  properties[:d][:visitor_ua] = visitor_user_agent if visitor_user_agent && !visitor_user_agent.empty?
134
135
  properties[:d][:visitor_ip] = ip_address if ip_address && !ip_address.empty?
136
+
137
+ # check if usage stats size is greater than 0
138
+ usage_stats = UsageStatsUtil.get_usage_stats
139
+ if usage_stats.size > 0
140
+ properties[:d][:event][:props][:vwoMeta] = usage_stats
141
+ end
135
142
 
136
143
  LoggerService.log(LogLevelEnum::DEBUG, "IMPRESSION_FOR_TRACK_USER", {
137
144
  accountId: settings.account_id,
@@ -203,10 +210,17 @@ class NetworkUtil
203
210
  if network_instance.get_client.get_should_use_threading
204
211
  network_instance.get_client.get_thread_pool.post {
205
212
  response = network_instance.post(request)
213
+ if response.get_status_code == 200
214
+ UsageStatsUtil.clear_usage_stats
215
+ end
206
216
  response
207
217
  }
208
218
  else
209
219
  response = network_instance.post(request)
220
+ if response.get_status_code == 200
221
+ UsageStatsUtil.clear_usage_stats
222
+ end
223
+ response
210
224
  end
211
225
  rescue ResponseModel => err
212
226
  LoggerService.log(LogLevelEnum::ERROR, "NETWORK_CALL_FAILED", {
@@ -241,4 +255,4 @@ class NetworkUtil
241
255
  end
242
256
  end
243
257
  end
244
- end
258
+ end
@@ -0,0 +1,117 @@
1
+ # Copyright 2024-2025 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ require_relative '../constants/constants'
17
+ require_relative '../enums/log_level_to_number'
18
+
19
+ # Manages usage statistics for the SDK.
20
+ # Tracks various features and configurations being used by the client.
21
+ # Implements Singleton pattern to ensure a single instance.
22
+ class UsageStatsUtil
23
+ @instance = nil
24
+ @usage_stats_data = {}
25
+
26
+ class << self
27
+ # Provides access to the singleton instance of UsageStatsUtil.
28
+ #
29
+ # @return [UsageStatsUtil] The single instance of UsageStatsUtil
30
+ def instance
31
+ @instance ||= new
32
+ end
33
+
34
+ # Sets usage statistics based on provided options.
35
+ # Maps various SDK features and configurations to boolean flags.
36
+ #
37
+ # @param options [Hash] Configuration options for the SDK
38
+ def set_usage_stats(options)
39
+ instance.set_usage_stats(options)
40
+ end
41
+
42
+ # Retrieves the current usage statistics.
43
+ #
44
+ # @return [Hash] Record containing boolean flags for various SDK features in use
45
+ def get_usage_stats
46
+ instance.get_usage_stats
47
+ end
48
+
49
+ def clear_usage_stats
50
+ instance.clear_usage_stats
51
+ end
52
+ end
53
+
54
+ private_class_method :new
55
+
56
+ def initialize
57
+ @usage_stats_data = {}
58
+ end
59
+
60
+ def set_usage_stats(options)
61
+ storage = options[:storage]
62
+ logger = options[:logger]
63
+ event_batching = options[:batch_event_data]
64
+ integrations = options[:integrations]
65
+ poll_interval = options[:poll_interval]
66
+ vwo_meta = options[:_vwo_meta]
67
+ gateway_service = options[:gateway_service]
68
+ threading = options[:threading]
69
+
70
+ data = {}
71
+
72
+ data[:ig] = 1 if integrations
73
+ data[:eb] = 1 if event_batching
74
+ data[:gs] = 1 if gateway_service
75
+
76
+ # if logger has transport or transports, then it is custom logger
77
+ if logger && (logger.key?(:transport) || logger.key?(:transports))
78
+ data[:cl] = 1
79
+ end
80
+
81
+ data[:ss] = 1 if storage
82
+
83
+ if logger && logger.key?(:level)
84
+ data[:ll] = LogLevelToNumber.to_number(logger[:level]) || -1
85
+ end
86
+
87
+ data[:pi] = 1 if poll_interval
88
+
89
+ if vwo_meta && vwo_meta.key?(:ea)
90
+ data[:_ea] = 1
91
+ end
92
+
93
+ # check if threading is not passed or is if passed then enabled should be true
94
+ if !threading || (threading && threading[:enabled] == true)
95
+ data[:th] = 1
96
+ # check if max_pool_size is passed
97
+ if threading && threading[:max_pool_size]
98
+ data[:th_mps] = threading[:max_pool_size]
99
+ end
100
+ end
101
+
102
+ if defined?(RUBY_VERSION)
103
+ data[:lv] = RUBY_VERSION
104
+ end
105
+
106
+ @usage_stats_data = data
107
+ end
108
+
109
+ def get_usage_stats
110
+ @usage_stats_data
111
+ end
112
+
113
+ def clear_usage_stats
114
+ @usage_stats_data = {}
115
+ end
116
+ end
117
+
@@ -25,6 +25,7 @@ require_relative './services/batch_event_queue'
25
25
  require_relative './utils/function_util'
26
26
  require_relative './utils/batch_event_dispatcher'
27
27
  require_relative './constants/constants'
28
+ require_relative './utils/usage_stats_util'
28
29
 
29
30
  class VWOBuilder
30
31
  attr_reader :settings, :storage, :log_manager, :is_settings_fetch_in_progress, :vwo_instance, :is_valid_poll_interval_passed_from_init
@@ -244,4 +245,13 @@ class VWOBuilder
244
245
  }
245
246
  )
246
247
  end
248
+
249
+ # Initialize the usage stats
250
+ # @return [VWOBuilder] The VWOBuilder instance
251
+ def init_usage_stats
252
+ return self if @options[:is_usage_stats_disabled]
253
+
254
+ UsageStatsUtil.set_usage_stats(@options)
255
+ self
256
+ end
247
257
  end
data/lib/vwo.rb CHANGED
@@ -36,6 +36,7 @@ class VWO
36
36
  .set_network_manager
37
37
  .set_segmentation
38
38
  .init_polling
39
+ .init_usage_stats
39
40
  .init_batch
40
41
 
41
42
  if options[:settings]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vwo-fme-ruby-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - VWO
@@ -161,6 +161,7 @@ files:
161
161
  - lib/vwo/enums/hooks_enum.rb
162
162
  - lib/vwo/enums/http_method_enum.rb
163
163
  - lib/vwo/enums/log_level_enum.rb
164
+ - lib/vwo/enums/log_level_to_number.rb
164
165
  - lib/vwo/enums/status_enum.rb
165
166
  - lib/vwo/enums/storage_enum.rb
166
167
  - lib/vwo/enums/url_enum.rb
@@ -219,6 +220,7 @@ files:
219
220
  - lib/vwo/utils/rule_evaluation_util.rb
220
221
  - lib/vwo/utils/settings_util.rb
221
222
  - lib/vwo/utils/url_util.rb
223
+ - lib/vwo/utils/usage_stats_util.rb
222
224
  - lib/vwo/utils/uuid_util.rb
223
225
  - lib/vwo/vwo_builder.rb
224
226
  - lib/vwo/vwo_client.rb