vwo-fme-ruby-sdk 1.0.0 → 1.2.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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/lib/resources/debug_messages.json +13 -0
  3. data/lib/resources/error_messages.json +30 -0
  4. data/lib/resources/info_messages.json +33 -0
  5. data/lib/resources/warn_messages.json +1 -0
  6. data/lib/vwo/api/get_flag.rb +236 -0
  7. data/lib/vwo/api/set_attribute.rb +57 -0
  8. data/lib/vwo/api/track_event.rb +77 -0
  9. data/lib/vwo/constants/constants.rb +54 -0
  10. data/lib/vwo/decorators/storage_decorator.rb +86 -0
  11. data/lib/vwo/{utils/logger_helper.rb → enums/api_enum.rb} +5 -10
  12. data/lib/vwo/enums/campaign_type_enum.rb +19 -0
  13. data/lib/vwo/enums/decision_types_enum.rb +18 -0
  14. data/lib/vwo/enums/event_enum.rb +19 -0
  15. data/lib/vwo/enums/headers_enum.rb +20 -0
  16. data/lib/vwo/enums/hooks_enum.rb +17 -0
  17. data/lib/vwo/enums/http_method_enum.rb +18 -0
  18. data/lib/vwo/enums/log_level_enum.rb +21 -0
  19. data/lib/vwo/enums/status_enum.rb +19 -0
  20. data/lib/vwo/enums/storage_enum.rb +22 -0
  21. data/lib/vwo/enums/url_enum.rb +21 -0
  22. data/lib/vwo/models/campaign/campaign_model.rb +192 -0
  23. data/lib/vwo/models/campaign/feature_model.rb +111 -0
  24. data/lib/vwo/models/campaign/impact_campaign_model.rb +38 -0
  25. data/lib/vwo/models/campaign/metric_model.rb +44 -0
  26. data/lib/vwo/models/campaign/rule_model.rb +56 -0
  27. data/lib/vwo/models/campaign/variable_model.rb +51 -0
  28. data/lib/vwo/models/campaign/variation_model.rb +137 -0
  29. data/lib/vwo/models/gateway_service_model.rb +39 -0
  30. data/lib/vwo/models/schemas/settings_schema_validation.rb +102 -0
  31. data/lib/vwo/models/settings/settings_model.rb +85 -0
  32. data/lib/vwo/models/storage/storage_data_model.rb +44 -0
  33. data/lib/vwo/models/user/context_model.rb +100 -0
  34. data/lib/vwo/models/user/context_vwo_model.rb +38 -0
  35. data/lib/vwo/{utils/feature_flag_response.rb → models/user/get_flag_response.rb} +14 -14
  36. data/lib/vwo/models/vwo_options_model.rb +107 -0
  37. data/lib/vwo/packages/decision_maker/decision_maker.rb +60 -0
  38. data/lib/vwo/packages/logger/core/log_manager.rb +90 -0
  39. data/lib/vwo/packages/logger/core/transport_manager.rb +87 -0
  40. data/lib/vwo/packages/logger/log_message_builder.rb +70 -0
  41. data/lib/vwo/packages/logger/logger.rb +38 -0
  42. data/lib/vwo/packages/logger/transports/console_transport.rb +49 -0
  43. data/lib/vwo/packages/network_layer/client/network_client.rb +107 -0
  44. data/lib/vwo/packages/network_layer/handlers/request_handler.rb +37 -0
  45. data/lib/vwo/packages/network_layer/manager/network_manager.rb +78 -0
  46. data/lib/vwo/packages/network_layer/models/global_request_model.rb +105 -0
  47. data/lib/vwo/packages/network_layer/models/request_model.rb +145 -0
  48. data/lib/vwo/packages/network_layer/models/response_model.rb +45 -0
  49. data/lib/vwo/packages/segmentation_evaluator/core/segmentation_manager.rb +76 -0
  50. data/lib/vwo/packages/segmentation_evaluator/enums/segment_operand_regex_enum.rb +29 -0
  51. data/lib/vwo/packages/segmentation_evaluator/enums/segment_operand_value_enum.rb +26 -0
  52. data/lib/vwo/packages/segmentation_evaluator/enums/segment_operator_value_enum.rb +30 -0
  53. data/lib/vwo/packages/segmentation_evaluator/evaluators/segment_evaluator.rb +210 -0
  54. data/lib/vwo/packages/segmentation_evaluator/evaluators/segment_operand_evaluator.rb +198 -0
  55. data/lib/vwo/packages/segmentation_evaluator/utils/segment_util.rb +44 -0
  56. data/lib/vwo/{constants.rb → packages/storage/connector.rb} +12 -10
  57. data/lib/vwo/packages/storage/storage.rb +45 -0
  58. data/lib/vwo/services/campaign_decision_service.rb +153 -0
  59. data/lib/vwo/services/hooks_service.rb +51 -0
  60. data/lib/vwo/services/logger_service.rb +83 -0
  61. data/lib/vwo/services/settings_service.rb +120 -0
  62. data/lib/vwo/services/storage_service.rb +65 -0
  63. data/lib/vwo/utils/campaign_util.rb +249 -0
  64. data/lib/vwo/utils/data_type_util.rb +105 -0
  65. data/lib/vwo/utils/decision_util.rb +253 -0
  66. data/lib/vwo/utils/function_util.rb +123 -0
  67. data/lib/vwo/utils/gateway_service_util.rb +101 -0
  68. data/lib/vwo/utils/impression_util.rb +49 -0
  69. data/lib/vwo/utils/log_message_util.rb +42 -0
  70. data/lib/vwo/utils/meg_util.rb +350 -0
  71. data/lib/vwo/utils/network_util.rb +235 -0
  72. data/lib/vwo/utils/rule_evaluation_util.rb +57 -0
  73. data/lib/vwo/utils/settings_util.rb +38 -0
  74. data/lib/vwo/utils/url_util.rb +46 -0
  75. data/lib/vwo/utils/uuid_util.rb +55 -0
  76. data/lib/vwo/vwo_builder.rb +156 -11
  77. data/lib/vwo/vwo_client.rb +163 -113
  78. data/lib/vwo.rb +49 -31
  79. metadata +191 -9
  80. data/lib/vwo/utils/request.rb +0 -89
data/lib/vwo.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Wingify Software Pvt. Ltd.
1
+ # Copyright 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.
@@ -12,45 +12,63 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- require_relative 'vwo/utils/logger_helper'
16
- require_relative 'vwo/vwo_client'
15
+ require 'json'
16
+ require 'uri'
17
17
  require_relative 'vwo/vwo_builder'
18
- require_relative 'vwo/constants'
19
- require_relative 'vwo/utils/request'
18
+ require_relative 'vwo/vwo_client'
20
19
 
21
- # The main VWO module
22
- module VWO
23
- # Class-level variable to hold the VWO client instance
20
+ class VWO
21
+ @@vwo_builder = nil
24
22
  @@instance = nil
25
23
 
26
- # Initialize the VWO SDK with the given options
27
- def self.init(options = {})
28
- raise 'options is required to initialize VWO' unless options.is_a?(Hash)
29
- raise 'sdk_key is required to initialize VWO' if options[:sdk_key].nil? || options[:sdk_key].empty?
30
- raise 'account_id is required to initialize VWO' if options[:account_id].nil? || options[:account_id].empty?
31
- raise 'gateway_service_url is required to initialize VWO' if options[:gateway_service_url].nil? || options[:gateway_service_url].empty?
32
-
33
- vwo_init_options = {
34
- sdk_key: options[:sdk_key],
35
- account_id: options[:account_id],
36
- gateway_service_url: options[:gateway_service_url]
37
- }
38
-
39
- set_instance(vwo_init_options)
40
- rescue StandardError => e
41
- LoggerHelper.logger.error("Error initializing VWO: #{e.message}")
42
- @@instance = VWOClient.new(nil)
24
+ def initialize(options)
25
+ self.class.set_instance(options)
43
26
  end
44
27
 
45
- # Set the VWO instance using VWOBuilder and VWOClient
46
28
  def self.set_instance(options)
47
- vwo_builder = VWOBuilder.new(options)
48
- vwo_builder.init_client
49
- @@instance = VWOClient.new(options)
29
+ options_vwo_builder = options[:vwo_builder]
30
+ @@vwo_builder = options_vwo_builder || VWOBuilder.new(options)
31
+
32
+ @@instance = @@vwo_builder
33
+ .set_logger
34
+ .set_settings_service
35
+ .set_storage
36
+ .set_network_manager
37
+ .set_segmentation
38
+ .init_polling
39
+
40
+ if options[:settings]
41
+ return @@vwo_builder.build(options[:settings])
42
+ end
43
+
44
+ settings = @@vwo_builder.get_settings
45
+ @@instance = @@vwo_builder.build(settings)
46
+ @@instance
50
47
  end
51
48
 
52
- # Get the singleton instance of VWO
53
49
  def self.instance
54
50
  @@instance
55
51
  end
56
- end
52
+
53
+ def self.init(options)
54
+
55
+ begin
56
+ unless options.is_a?(Hash)
57
+ puts "[ERROR]: VWO-SDK: Please provide the options as a hash"
58
+ end
59
+
60
+ unless options[:sdk_key]&.is_a?(String) && !options[:sdk_key].empty?
61
+ puts "[ERROR]: VWO-SDK: Please provide the sdkKey in the options and should be a of type string"
62
+ end
63
+
64
+ unless options[:account_id] && (options[:account_id].is_a?(Integer) || (options[:account_id].is_a?(String) && !options[:account_id].empty?))
65
+ puts "[ERROR]: VWO-SDK: Please provide VWO account ID in the options and should be a of type string|number"
66
+ end
67
+
68
+ new(options)
69
+ @@instance
70
+ rescue StandardError => e
71
+ puts "[ERROR]: VWO-SDK: Got error while initializing VWO: #{e.message}"
72
+ end
73
+ end
74
+ end
metadata CHANGED
@@ -1,29 +1,141 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vwo-fme-ruby-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - VWO
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-09 00:00:00.000000000 Z
11
+ date: 2025-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: uuidtools
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-schema
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: murmurhash3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.6
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.6
13
55
  - !ruby/object:Gem::Dependency
14
56
  name: net-http
15
57
  requirement: !ruby/object:Gem::Requirement
16
58
  requirements:
17
59
  - - "~>"
18
60
  - !ruby/object:Gem::Version
19
- version: '0.1'
61
+ version: 0.2.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.2.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: concurrent-ruby
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.2.0
20
76
  type: :runtime
21
77
  prerelease: false
22
78
  version_requirements: !ruby/object:Gem::Requirement
23
79
  requirements:
24
80
  - - "~>"
25
81
  - !ruby/object:Gem::Version
26
- version: '0.1'
82
+ version: 1.2.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '5.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '5.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mocha
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.7'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.7'
111
+ - !ruby/object:Gem::Dependency
112
+ name: json
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.5'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.5'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '13.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '13.0'
27
139
  description: A Ruby SDK for Feature Management And Experimentation
28
140
  email:
29
141
  - dev@wingify.com
@@ -31,11 +143,81 @@ executables: []
31
143
  extensions: []
32
144
  extra_rdoc_files: []
33
145
  files:
146
+ - lib/resources/debug_messages.json
147
+ - lib/resources/error_messages.json
148
+ - lib/resources/info_messages.json
149
+ - lib/resources/warn_messages.json
34
150
  - lib/vwo.rb
35
- - lib/vwo/constants.rb
36
- - lib/vwo/utils/feature_flag_response.rb
37
- - lib/vwo/utils/logger_helper.rb
38
- - lib/vwo/utils/request.rb
151
+ - lib/vwo/api/get_flag.rb
152
+ - lib/vwo/api/set_attribute.rb
153
+ - lib/vwo/api/track_event.rb
154
+ - lib/vwo/constants/constants.rb
155
+ - lib/vwo/decorators/storage_decorator.rb
156
+ - lib/vwo/enums/api_enum.rb
157
+ - lib/vwo/enums/campaign_type_enum.rb
158
+ - lib/vwo/enums/decision_types_enum.rb
159
+ - lib/vwo/enums/event_enum.rb
160
+ - lib/vwo/enums/headers_enum.rb
161
+ - lib/vwo/enums/hooks_enum.rb
162
+ - lib/vwo/enums/http_method_enum.rb
163
+ - lib/vwo/enums/log_level_enum.rb
164
+ - lib/vwo/enums/status_enum.rb
165
+ - lib/vwo/enums/storage_enum.rb
166
+ - lib/vwo/enums/url_enum.rb
167
+ - lib/vwo/models/campaign/campaign_model.rb
168
+ - lib/vwo/models/campaign/feature_model.rb
169
+ - lib/vwo/models/campaign/impact_campaign_model.rb
170
+ - lib/vwo/models/campaign/metric_model.rb
171
+ - lib/vwo/models/campaign/rule_model.rb
172
+ - lib/vwo/models/campaign/variable_model.rb
173
+ - lib/vwo/models/campaign/variation_model.rb
174
+ - lib/vwo/models/gateway_service_model.rb
175
+ - lib/vwo/models/schemas/settings_schema_validation.rb
176
+ - lib/vwo/models/settings/settings_model.rb
177
+ - lib/vwo/models/storage/storage_data_model.rb
178
+ - lib/vwo/models/user/context_model.rb
179
+ - lib/vwo/models/user/context_vwo_model.rb
180
+ - lib/vwo/models/user/get_flag_response.rb
181
+ - lib/vwo/models/vwo_options_model.rb
182
+ - lib/vwo/packages/decision_maker/decision_maker.rb
183
+ - lib/vwo/packages/logger/core/log_manager.rb
184
+ - lib/vwo/packages/logger/core/transport_manager.rb
185
+ - lib/vwo/packages/logger/log_message_builder.rb
186
+ - lib/vwo/packages/logger/logger.rb
187
+ - lib/vwo/packages/logger/transports/console_transport.rb
188
+ - lib/vwo/packages/network_layer/client/network_client.rb
189
+ - lib/vwo/packages/network_layer/handlers/request_handler.rb
190
+ - lib/vwo/packages/network_layer/manager/network_manager.rb
191
+ - lib/vwo/packages/network_layer/models/global_request_model.rb
192
+ - lib/vwo/packages/network_layer/models/request_model.rb
193
+ - lib/vwo/packages/network_layer/models/response_model.rb
194
+ - lib/vwo/packages/segmentation_evaluator/core/segmentation_manager.rb
195
+ - lib/vwo/packages/segmentation_evaluator/enums/segment_operand_regex_enum.rb
196
+ - lib/vwo/packages/segmentation_evaluator/enums/segment_operand_value_enum.rb
197
+ - lib/vwo/packages/segmentation_evaluator/enums/segment_operator_value_enum.rb
198
+ - lib/vwo/packages/segmentation_evaluator/evaluators/segment_evaluator.rb
199
+ - lib/vwo/packages/segmentation_evaluator/evaluators/segment_operand_evaluator.rb
200
+ - lib/vwo/packages/segmentation_evaluator/utils/segment_util.rb
201
+ - lib/vwo/packages/storage/connector.rb
202
+ - lib/vwo/packages/storage/storage.rb
203
+ - lib/vwo/services/campaign_decision_service.rb
204
+ - lib/vwo/services/hooks_service.rb
205
+ - lib/vwo/services/logger_service.rb
206
+ - lib/vwo/services/settings_service.rb
207
+ - lib/vwo/services/storage_service.rb
208
+ - lib/vwo/utils/campaign_util.rb
209
+ - lib/vwo/utils/data_type_util.rb
210
+ - lib/vwo/utils/decision_util.rb
211
+ - lib/vwo/utils/function_util.rb
212
+ - lib/vwo/utils/gateway_service_util.rb
213
+ - lib/vwo/utils/impression_util.rb
214
+ - lib/vwo/utils/log_message_util.rb
215
+ - lib/vwo/utils/meg_util.rb
216
+ - lib/vwo/utils/network_util.rb
217
+ - lib/vwo/utils/rule_evaluation_util.rb
218
+ - lib/vwo/utils/settings_util.rb
219
+ - lib/vwo/utils/url_util.rb
220
+ - lib/vwo/utils/uuid_util.rb
39
221
  - lib/vwo/vwo_builder.rb
40
222
  - lib/vwo/vwo_client.rb
41
223
  homepage:
@@ -54,7 +236,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
236
  requirements:
55
237
  - - ">="
56
238
  - !ruby/object:Gem::Version
57
- version: '2.5'
239
+ version: 2.6.0
58
240
  required_rubygems_version: !ruby/object:Gem::Requirement
59
241
  requirements:
60
242
  - - ">="
@@ -1,89 +0,0 @@
1
- # Copyright 2024 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
- require 'net/http'
16
- require 'uri'
17
- require 'json'
18
-
19
- module VWO
20
- module Utils
21
- # The Request class is responsible for sending HTTP GET and POST requests.
22
- # It uses a base URL that can be set once and then reused for all subsequent requests.
23
- class Request
24
- @@base_url = '' # Class variable to store the base URL for requests.
25
-
26
- # Sets the base URL to be used for making HTTP requests.
27
- #
28
- # @param [String] url The base URL to be used for all requests.
29
- def self.set_base_url(url)
30
- @@base_url = url
31
- end
32
-
33
- # Sends an HTTP GET request to a specific endpoint using the set base URL.
34
- #
35
- # @param [String] endpoint The API endpoint to send the GET request to.
36
- # @return [String, nil] Returns the response body if the request is successful, or nil if it fails.
37
- def self.send_get_request(endpoint)
38
- # Combine the base URL and endpoint into a full URI.
39
- full_url = URI.join(@@base_url, endpoint)
40
-
41
- # Send the GET request and capture the response.
42
- response = Net::HTTP.get_response(full_url)
43
-
44
- # Check if the response was successful (status code 2xx).
45
- if response.is_a?(Net::HTTPSuccess)
46
- response.body # Return the response body if successful.
47
- else
48
- # Log an error message if the request fails and return nil.
49
- puts "GET request failed with response code: #{response.code}"
50
- nil
51
- end
52
- end
53
-
54
- # Sends an HTTP POST request with JSON data to a specific endpoint using the set base URL.
55
- #
56
- # @param [String] endpoint The API endpoint to send the POST request to.
57
- # @param [Hash] data The data to be sent as the POST request body, in JSON format.
58
- # @return [String, nil] Returns the response body if the request is successful, or nil if it fails.
59
- def self.send_post_request(endpoint, data)
60
- # Combine the base URL and endpoint into a full URI.
61
- full_url = URI.join(@@base_url, endpoint)
62
-
63
- # Initialize a new HTTP object for the specified host and port.
64
- http = Net::HTTP.new(full_url.host, full_url.port)
65
-
66
- # Enable SSL (HTTPS) if the URL scheme is 'https'.
67
- http.use_ssl = true if full_url.scheme == 'https'
68
-
69
- # Create a new POST request object, setting the content type to JSON.
70
- request = Net::HTTP::Post.new(full_url, { 'Content-Type' => 'application/json' })
71
-
72
- # Convert the data to JSON and set it as the request body.
73
- request.body = data.to_json
74
-
75
- # Send the POST request and capture the response.
76
- response = http.request(request)
77
-
78
- # Check if the response was successful (status code 2xx).
79
- if response.is_a?(Net::HTTPSuccess)
80
- response.body # Return the response body if successful.
81
- else
82
- # Log an error message if the request fails and return nil.
83
- puts "POST request failed with response code: #{response.code}"
84
- nil
85
- end
86
- end
87
- end
88
- end
89
- end