vwo-sdk 1.30.0 → 1.37.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/vwo/enums.rb CHANGED
@@ -12,8 +12,6 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- # rubocop:disable Metrics/LineLength
16
-
17
15
  require 'logger'
18
16
 
19
17
  class VWO
@@ -64,157 +62,23 @@ class VWO
64
62
  VWO_PATH = 'vwo'
65
63
  UTIL_PATH = 'vwo/utils'
66
64
 
67
- VWO = VWO_PATH + '/vwo'
68
- Bucketer = VWO_PATH + '/core/bucketer'
69
- VariationDecider = VWO_PATH + '/core/variation_decider'
70
- EventDispatcher = VWO_PATH + '/services/event_dispatcher'
71
- SegmentEvaluator = VWO_PATH + '/services/segment_evaluator'
72
- Logger = VWO_PATH + '/logger'
73
- SettingsFileProcessor = VWO_PATH + '/services/settings_file_processor'
74
- BatchEventsQueue = VWO_PATH + '/services/batch_events_queue'
75
- BatchEventsDispatcher = VWO_PATH + '/services/batch_events_dispatcher'
76
-
77
- CampaignUtil = UTIL_PATH + '/campaign'
78
- FunctionUtil = UTIL_PATH + '/function'
79
- FeatureUtil = UTIL_PATH + '/feature'
80
- ImpressionUtil = UTIL_PATH + '/impression'
81
- UuidUtil = UTIL_PATH + '/uuid'
82
- ValidateUtil = UTIL_PATH + '/validations'
83
- CustomDimensionsUtil = UTIL_PATH + '/custom_dimensions_util'
84
- end
85
-
86
- # Logging Enums
87
- module LogMessageEnum
88
- # Debug Messages
89
- module DebugMessages
90
- LOG_LEVEL_SET = '(%<file>s): Log level set to %<level>s'
91
- SET_DEVELOPMENT_MODE = '(%<file>s): DEVELOPMENT mode is ON'
92
- VALID_CONFIGURATION = '(%<file>s): SDK configuration and account settings are valid.'
93
- CUSTOM_LOGGER_USED = '(%<file>s): Custom logger used'
94
- SDK_INITIALIZED = '(%<file>s): SDK properly initialized'
95
- SETTINGS_FILE_PROCESSED = '(%<file>s): Settings file processed'
96
- NO_STORED_VARIATION = '(%<file>s): No stored variation for UserId:%<user_id>s for Campaign:%<campaign_key>s found in UserStorageService'
97
- NO_USER_STORAGE_SERVICE_LOOKUP = '(%<file>s): No UserStorageService to look for stored data'
98
- NO_USER_STORAGE_SERVICE_SAVE = '(%<file>s): No UserStorageService to save data'
99
- GETTING_STORED_VARIATION = '(%<file>s): Got stored variation for UserId:%<user_id>s of Campaign:%<campaign_key>s as Variation: %<variation_name>s found in UserStorageService'
100
- CHECK_USER_ELIGIBILITY_FOR_CAMPAIGN = '(%<file>s): campaign:%<campaign_key>s having traffic allocation:%<traffic_allocation>s assigned value:%<traffic_allocation>s to userId:%<user_id>s'
101
- USER_HASH_BUCKET_VALUE = '(%<file>s): userId:%<user_id>s having hash:%<hash_value>s got bucketValue:%<bucket_value>s'
102
- VARIATION_HASH_BUCKET_VALUE = '(%<file>s): userId:%<user_id>s for campaign:%<campaign_key>s having percent traffic:%<percent_traffic>s got hash-value:%<hash_value>s and bucket value:%<bucket_value>s'
103
- IMPRESSION_FAILED = '(%<file>s): userId:%<user_id>s for campaign:%<campaign_key>s got variationName:%<variation_name>s inside method:%<method>s'
104
- USER_NOT_PART_OF_CAMPAIGN = '(%<file>s): userId:%<user_id>s for campaign:%<campaign_key>s did not become part of campaign method:%<method>s'
105
- UUID_FOR_USER = '(%<file>s): Uuid generated for userId:%<user_id>s and accountId:%<account_id>s is %<desired_uuid>s'
106
- IMPRESSION_FOR_TRACK_USER = '(%<file>s): Impression built for track-user - %<properties>s'
107
- IMPRESSION_FOR_TRACK_GOAL = '(%<file>s): Impression built for track-goal - %<properties>s'
108
- GOT_VARIATION_FOR_USER = '(%<file>s): userId:%<user_id>s for campaign:%<campaign_key>s got variationName:%<variation_name>s'
109
- SEGMENTATION_STATUS = '(%<file>s): In API: %<api_name>s, for UserId:%<user_id>s of campaign:%<campaign_key>s with variables:%<custom_variables>s %<status>s %<segmentation_type>s %<variation_name>s'
110
- PARAMS_FOR_PUSH_CALL = '(%<file>s): Params for push call - %<properties>s'
111
- CAMPAIGN_NOT_ACTIVATED = '(%<file>s): Campaign:%<campaign_key>s for User ID:%<user_id>s is not yet activated for API:%<api_name>s. Use activate API to activate A/B test or isFeatureEnabled API to activate Feature Test.'
112
- BATCH_EVENT_LIMIT_EXCEEDED = '(%<file>s): Impression event - %<end_point>s failed due to exceeding payload size. Parameter eventsPerRequest in batchEvents config in launch API has value:%<eventsPerRequest>s for accountId:%<accountId>s. Please read the official documentation for knowing the size limits.'
113
- BULK_NOT_PROCESSED = "(%<file>s): Batch events couldn't be received by VWO. Calling Flush Callback with error and data."
114
- BEFORE_FLUSHING = '(%<file>s): Flushing events queue %<manually>s having %<length>s events %<timer>s queue summary: %<queue_metadata>s'
115
- EVENT_BATCHING_INSUFFICIENT = '(%<file>s): %<key>s not provided, assigning default value'
116
- GOT_ELIGIBLE_CAMPAIGNS = "(%<file>s): Campaigns:%<eligible_campaigns_key>s are eligible, %<ineligible_campaigns_log_text>s are ineligible from the Group:%<group_name>s for the User ID:%<user_id>s"
117
- IMPRESSION_FOR_EVENT_ARCH_TRACK_USER = "(%<file>s): impression built for vwo_variationShown event for account ID:%<a>s, user ID:%<u>s, and campaign ID:%<c>s"
118
- IMPRESSION_FOR_EVENT_ARCH_TRACK_GOAL = "(%<file>s): impression built for %<goal_identifier>s event for account ID:%<a>s, user ID:%<u>s, and campaign ID:%<c>s"
119
- IMPRESSION_FOR_EVENT_ARCH_PUSH = "(%<file>s): impression built for visitor property:%<property>s for account ID:%<a>s and user ID:%<u>s"
120
- end
121
-
122
- # Info Messages
123
- module InfoMessages
124
- VARIATION_RANGE_ALLOCATION = '(%<file>s): Campaign:%<campaign_key>s having variations:%<variation_name>s with weight:%<variation_weight>s got range as: ( %<start>s - %<end>s ))'
125
- VARIATION_ALLOCATED = '(%<file>s): UserId:%<user_id>s of Campaign:%<campaign_key>s type: %<campaign_type>s got variation: %<variation_name>s'
126
- LOOKING_UP_USER_STORAGE_SERVICE = '(%<file>s): Looked into UserStorageService for userId:%<user_id>s %<status>s'
127
- SAVING_DATA_USER_STORAGE_SERVICE = '(%<file>s): Saving into UserStorageService for userId:%<user_id>s successful'
128
- GOT_STORED_VARIATION = '(%<file>s): Got stored variation:%<variation_name>s of campaign:%<campaign_key>s for userId:%<user_id>s from UserStorageService'
129
- NO_VARIATION_ALLOCATED = '(%<file>s): UserId:%<user_id>s of Campaign:%<campaign_key>s did not get any variation'
130
- USER_ELIGIBILITY_FOR_CAMPAIGN = '(%<file>s): Is userId:%<user_id>s part of campaign? %<is_user_part>s'
131
- AUDIENCE_CONDITION_NOT_MET = '(%<file>s): userId:%<user_id>s does not become part of campaign because of not meeting audience conditions'
132
- GOT_VARIATION_FOR_USER = '(%<file>s): userId:%<user_id>s for campaign:%<campaign_key>s got variationName:%<variation_name>s'
133
- USER_GOT_NO_VARIATION = '(%<file>s): userId:%<user_id>s for campaign:%<campaign_key>s did not allot any variation'
134
- IMPRESSION_SUCCESS_FOR_EVENT_ARCH = '(%<file>s): Impression for %<event>s - %<url>s was successfully received by VWO for account ID:%<a>s'
135
- IMPRESSION_SUCCESS = '(%<file>s): Impression event - %<end_point>s was successfully received by VWO having main keys: accountId:%<account_id>s campaignId:%<campaign_id>s and variationId:%<variation_id>s'
136
- MAIN_KEYS_FOR_IMPRESSION = '(%<file>s): Having main keys: accountId:%<account_id>s campaignId:%<campaign_id>s and variationId:%<variation_id>s}'
137
- MAIN_KEYS_FOR_PUSH_API = '(%<file>s): Having main keys: accountId:%<account_id>s u:%<u>s and tags:%<tags>s}'
138
- INVALID_VARIATION_KEY = '(%<file>s): Variation was not assigned to userId:%<user_id>s for campaign:%<campaign_key>s'
139
-
140
- USER_IN_FEATURE_ROLLOUT = '(%<file>s): User ID:%<user_id>s is in feature rollout:%<campaign_key>s'
141
- USER_NOT_IN_FEATURE_ROLLOUT = '(%<file>s): User ID:%<user_id>s is NOT in feature rollout:%<campaign_key>s'
142
- FEATURE_ENABLED_FOR_USER = '(%<file>s): In API: %<api_name>s Feature having feature-key:%<feature_key>s for user ID:%<user_id>s is enabled'
143
- FEATURE_NOT_ENABLED_FOR_USER = '(%<file>s): In API: %<api_name>s Feature having feature-key:%<feature_key>s for user ID:%<user_id>s is not enabled'
144
-
145
- VARIABLE_FOUND = '(%<file>s): In API: %<api_name>s Value for variable:%<variable_key>s of campaign:%<campaign_key>s and campaign type: %<campaign_type>s is:%<variable_value>s for user:%<user_id>s'
146
-
147
- USER_PASSED_SEGMENTATION = '(%<file>s): UserId:%<user_id>s of campaign:%<campaign_key>s with custom_variables:%<custom_variables>s passed segmentation'
148
- USER_FAILED_SEGMENTATION = '(%<file>s): UserId:%<user_id>s of campaign:%<campaign_key>s with custom_variables:%<custom_variables>s failed segmentation'
149
-
150
- NO_CUSTOM_VARIABLES = '(%<file>s): In API: %<api_name>s, for UserId:%<user_id>s customVariables are not passed for campaign:%<campaign_key>s and campaign has pre-segmentation'
151
- SKIPPING_SEGMENTATION = '(%<file>s): In API: %<api_name>s, Skipping segmentation:%<variation>s for UserId:%<user_id>s as no valid segments found in campaign:%<campaign_key>s'
152
-
153
- SEGMENTATION_STATUS = '(%<file>s): In API: %<api_name>s, for UserId:%<user_id>s of campaign:%<campaign_key>s with variables:%<custom_variables>s %<status>s %<segmentation_type>s %<variation_name>s'
154
- WHITELISTING_SKIPPED = '(%<file>s): In API: %<api_name>s, Skipping whitelisting for UserId:%<user_id>s of campaign:%<campaign_key>s'
155
- SETTINGS_NOT_UPDATED = '(%<file>s): Settings-file fetched are same as earlier fetched settings'
156
- SETTINGS_FILE_UPDATED = '(%<file>s): %<api_name>s vwo_sdk_instance is updated with the latest settings_file'
157
- CAMPAIGN_NOT_ACTIVATED = '(%<file>s): Activate the campaign:%<campaign_key>s for User ID:%<user_id>s to %<reason>s.'
158
- GOAL_ALREADY_TRACKED = '(%<file>s): Goal:%<goal_identifier>s of Campaign:%<campaign_key>s for User ID:%<user_id>s has already been tracked earlier. Skipping now'
159
- USER_ALREADY_TRACKED = '(%<file>s): User ID:%<user_id>s for Campaign:%<campaign_key>s has already been tracked earlier for "%<api_name>s" API. Skipping now'
160
- API_CALLED = '(%<file>s): API: %<api_name>s called for UserId:%<user_id>s'
161
- BULK_IMPRESSION_SUCCESS = '(%<file>s): Impression event - %<end_point>s was successfully received by VWO having accountId:%<a>s'
162
- AFTER_FLUSHING = '(%<file>s): Events queue having %<length>s events has been flushed %<manually>s queue summary: %<queue_metadata>s'
163
- GOT_WINNER_CAMPAIGN = "(%<file>s): Campaign:%<campaign_key>s is selected from the mutually exclusive group:%<group_name>s for the User ID:%<user_id>s"
164
- GOT_ELIGIBLE_CAMPAIGNS = "(%<file>s): Got %<no_of_eligible_campaigns>s eligible winners out of %<no_of_group_campaigns>s from the Group:%<group_name>s and for User ID:%<user_id>s"
165
- CALLED_CAMPAIGN_NOT_WINNER = "(%<file>s): Campaign:%<campaign_key>s does not qualify from the mutually exclusive group:%<group_name>s for User ID:%<user_id>s"
166
- OTHER_CAMPAIGN_SATISFIES_WHITELISTING_OR_STORAGE = "(%<file>s): Campaign:%<campaign_key>s of Group:%<group_name>s satisfies %<type>s for User ID:%<user_id>s"
167
- OPT_OUT_API_CALLED = "(%<file>s): You have opted out for not tracking i.e. all API calls will stop functioning and will simply early return"
168
- API_NOT_ENABLED = "(%<file>s): %<api>s API is disabled as you opted out for tracking. Reinitialize the SDK to enable the normal functioning of all APIs."
169
- end
170
-
171
- # Warning Messages
172
- module WarningMessages; end
173
-
174
- # Error Messages
175
- module ErrorMessages
176
- SETTINGS_FILE_CORRUPTED = '(%<file>s): Settings file is corrupted. Please contact VWO Support for help.'
177
- ACTIVATE_API_MISSING_PARAMS = '(%<file>s): %<api_name>s API got bad parameters. It expects campaignTestKey(String) as first and userId(String) as second argument, customVariables(Hash) can be passed via options for pre-segmentation'
178
- API_CONFIG_CORRUPTED = '(%<file>s): %<api_name>s API has corrupted configuration'
179
- GET_VARIATION_NAME_API_INVALID_PARAMS = '(%<file>s): %<api_name>s API got bad parameters. It expects campaignTestKey(String) as first and userId(String) as second argument, customVariables(Hash) can be passed via options for pre-segmentation'
180
- GET_VARIATION_API_CONFIG_CORRUPTED = '(%<file>s): "getVariation" API has corrupted configuration'
181
- TRACK_API_INVALID_PARAMS = '(%<file>s): %<api_name>s API got bad parameters. It expects campaignTestKey(Nil/String/Array) as first userId(String) as second and goalIdentifier(String/Number) as third argument. Fourth is revenueValue(Float/Number/String) and is required for revenue goal only. customVariables(Hash) can be passed via options for pre-segmentation'
182
- TRACK_API_CONFIG_CORRUPTED = '(%<file>s): "track" API has corrupted configuration'
183
- TRACK_API_GOAL_NOT_FOUND = '(%<file>s): Goal:%<goal_identifier>s not found for campaign:%<campaign_key>s and userId:%<user_id>s'
184
- TRACK_API_REVENUE_NOT_PASSED_FOR_REVENUE_GOAL = '(%<file>s): Revenue value should be passed for revenue goal:%<goal_identifier>s for campaign:%<campaign_key>s and userId:%<user_id>s'
185
- TRACK_API_VARIATION_NOT_FOUND = '(%<file>s): Variation not found for campaign:%<campaign_key>s and userId:%<user_id>s'
186
- CAMPAIGN_NOT_RUNNING = '(%<file>s): API used:%<api_name>s - Campaign:%<campaign_key>s is not RUNNING. Please verify from VWO App'
187
- LOOK_UP_USER_STORAGE_SERVICE_FAILED = '(%<file>s): Looking data from UserStorageService failed for userId:%<user_id>s'
188
- SAVE_USER_STORAGE_SERVICE_FAILED = '(%<file>s): Saving data into UserStorageService failed for userId:%<user_id>s'
189
- INVALID_CAMPAIGN = '(%<file>s): Invalid campaign passed to %<method>s of this file'
190
- INVALID_USER_ID = '(%<file>s): Invalid userId:%<user_id>s passed to %<method>s of this file'
191
- IMPRESSION_FAILED = '(%<file>s): Impression event could not be sent to VWO - %<end_point>s'
192
- CUSTOM_LOGGER_MISCONFIGURED = '(%<file>s): Custom logger is provided but seems to have mis-configured. %<extra_info>s Please check the API Docs. Using default logger.'
193
- INVALID_API = '(%<file>s): %<api_name>s API is not valid for user ID: %<user_id>s in campaign ID: %<campaign_key>s having campaign type: %<campaign_type>s.'
194
- IS_FEATURE_ENABLED_API_INVALID_PARAMS = '(%<file>s): %<api_name>s API got bad parameters. It expects campaign_key(String) as first and user_id(String) as second argument, customVariables(dict) can be passed via options for pre-segmentation'
195
- GET_FEATURE_VARIABLE_VALUE_API_INVALID_PARAMS = '(%<file>s): "get_feature_variable" API got bad parameters. It expects campaign_key(String) as first, variable_key(string) as second and user_id(String) as third argument, customVariables(dict) can be passed via options for pre-segmentation'
196
-
197
- VARIABLE_NOT_FOUND = '(%<file>s): In API: %<api_name>s Variable %<variable_key>s not found for campaign %<campaign_key>s and type %<campaign_type>s for user ID %<user_id>s'
198
- UNABLE_TO_TYPE_CAST = '(%<file>s): Unable to typecast value: %<value>s of type: %<of_type>s to type: %<variable_type>s.'
199
-
200
- USER_NOT_IN_CAMPAIGN = '(%<file>s): userId:%<user_id>s did not become part of campaign:%<campaign_key>s and campaign type:%<campaign_type>s'
201
- API_NOT_WORKING = '(%<file>s): API: %<api_name>s not working, exception caught: %<exception>s. Please contact VWO Support for help.'
202
-
203
- SEGMENTATION_ERROR = '(%<file>s): Error while segmenting the UserId:%<user_id>s of campaign:%<campaign_key>s with custom_variables:%<custom_variables>s. Error message: %<error_message>s'
204
-
205
- PUSH_API_INVALID_PARAMS = '(%<file>s): %<api_name>s API got bad parameters. It expects tag_key(String) as first and tag_value(String) as second argument and user_id(String) as third argument'
206
- TAG_VALUE_LENGTH_EXCEEDED = '(%<file>s): In API: %<api_name>s, the length of tag_value:%<tag_value>s and userID: %<user_id>s can not be greater than 255'
207
- TAG_KEY_LENGTH_EXCEEDED = '(%<file>s): In API: %<api_name>s, the length of tag_key:%<tag_key>s and userID: %<user_id>s can not be greater than 255'
208
- TRACK_API_MISSING_PARAMS = '(%<file>s): "track" API got bad parameters. It expects campaignKey(null/String/array) as first, userId(String/Number) as second and goalIdentifier (string) as third argument. options is revenueValue(Float/Number/String) and is required for revenue goal only.'
209
- NO_CAMPAIGN_FOUND = '(%<file>s): No campaign found for goal_identifier:%<goal_identifier>s. Please verify from VWO app.'
210
- INVALID_GOAL_TYPE = '(%<file>s): goal_type_to_track should be certain strings'
211
- EVENT_BATCHING_NOT_OBJECT = '(%<file>s): Batch events settings are not of type object.'
212
- EVENTS_PER_REQUEST_INVALID = '(%<file>s): events_per_request should be an integer'
213
- REQUEST_TIME_INTERVAL_INVALID = '(%<file>s): request_time_interval should be a number'
214
- EVENTS_PER_REQUEST_OUT_OF_BOUNDS = '(%<file>s): events_per_request should be >= %<min_value>s and <= %<max_value>s'
215
- REQUEST_TIME_INTERVAL_OUT_OF_BOUNDS = '(%<file>s): request_time_interval should be >= %<min_value>s'
216
- FLUSH_CALLBACK_INVALID = '(%<file>s): flush_callback is not callable'
217
- end
65
+ VWO = "#{VWO_PATH}/vwo"
66
+ BUCKETER = "#{VWO_PATH}/core/bucketer"
67
+ VARIATION_DECIDER = "#{VWO_PATH}/core/variation_decider"
68
+ EVENT_DISPATCHER = "#{VWO_PATH}/services/event_dispatcher"
69
+ SEGMENT_EVALUATOR = "#{VWO_PATH}/services/segment_evaluator"
70
+ LOGGER = "#{VWO_PATH}/logger"
71
+ SETTINGS_FILE_PROCESSOR = "#{VWO_PATH}/services/settings_file_processor"
72
+ BATCH_EVENTS_QUEUE = "#{VWO_PATH}/services/batch_events_queue"
73
+ BATCH_EVENTS_DISPATCHER = "#{VWO_PATH}/services/batch_events_dispatcher"
74
+
75
+ CAMPAIGN_UTIL = "#{UTIL_PATH}/campaign"
76
+ FUNCTION_UTIL = "#{UTIL_PATH}/function"
77
+ FEATURE_UTIL = "#{UTIL_PATH}/feature"
78
+ IMPRESSION_UTIL = "#{UTIL_PATH}/impression"
79
+ UUID_UTIL = "#{UTIL_PATH}/uuid"
80
+ VALIDATE_UTIL = "#{UTIL_PATH}/validations"
81
+ CUSTOM_DIMENSTIONS_UTIL = "#{UTIL_PATH}/custom_dimensions_util"
218
82
  end
219
83
 
220
84
  module LogLevelEnum
@@ -225,4 +89,3 @@ class VWO
225
89
  end
226
90
  end
227
91
  end
228
- # rubocop:enable Metrics/LineLength
data/lib/vwo/logger.rb CHANGED
@@ -16,6 +16,11 @@ require 'logger'
16
16
 
17
17
  class VWO
18
18
  class Logger
19
+ DEBUG = ::Logger::DEBUG
20
+ INFO = ::Logger::INFO
21
+ ERROR = ::Logger::ERROR
22
+ WARN = ::Logger::WARN
23
+
19
24
  @logger = nil
20
25
  @logger_instance = nil
21
26
 
@@ -24,14 +29,12 @@ class VWO
24
29
  end
25
30
 
26
31
  def initialize(logger_instance)
27
- @@logger_instance = logger_instance || ::Logger.new(STDOUT)
32
+ @@logger_instance = logger_instance || ::Logger.new($stdout)
28
33
  end
29
34
 
30
35
  # Override this method to handle logs in a custom manner
31
- def log(level, message, disable_logs = false)
32
- unless disable_logs
33
- @@logger_instance.log(level, message)
34
- end
36
+ def log(level, message)
37
+ @@logger_instance.log(level, message)
35
38
  end
36
39
 
37
40
  def instance
@@ -61,12 +61,12 @@ class VWO
61
61
  weight: {
62
62
  type: %w[number string]
63
63
  },
64
- variables: {
65
- type: 'array',
66
- items: {
67
- '$ref' => '#/definitions/variables_schema'
68
- }
69
- }
64
+ variables: {
65
+ type: 'array',
66
+ items: {
67
+ '$ref' => '#/definitions/variables_schema'
68
+ }
69
+ }
70
70
  },
71
71
  required: %w[id name weight]
72
72
  },
@@ -102,6 +102,7 @@ class VWO
102
102
  },
103
103
  isBucketingSeedEnabled: ['boolean'],
104
104
  isUserListEnabled: ['boolean'],
105
+ isAlwaysCheckSegment: ['boolean'],
105
106
  minItems: 2
106
107
  }
107
108
  },
@@ -12,10 +12,10 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- require_relative '../logger'
16
15
  require_relative '../enums'
17
16
  require_relative '../utils/request'
18
17
  require_relative '../utils/utility'
18
+ require_relative '../utils/log_message'
19
19
  class VWO
20
20
  module Services
21
21
  class BatchEventsDispatcher
@@ -26,8 +26,9 @@ class VWO
26
26
  # @param [Boolean] : To specify whether the request
27
27
  # to our server should be made or not.
28
28
  #
29
- def initialize
30
- @logger = VWO::Logger.get_instance
29
+ def initialize(development_mode = false)
30
+ @logger = VWO::Utils::Logger
31
+ @development_mode = development_mode
31
32
  @queue = []
32
33
  end
33
34
 
@@ -41,72 +42,78 @@ class VWO
41
42
  url = CONSTANTS::HTTPS_PROTOCOL + get_url(CONSTANTS::ENDPOINTS::BATCH_EVENTS)
42
43
  account_id = query_params[:a]
43
44
  resp = VWO::Utils::Request.post(url, query_params, impression)
44
- if resp.code == '200'
45
+ case resp.code
46
+ when '200'
45
47
  @logger.log(
46
48
  LogLevelEnum::INFO,
47
- format(
48
- LogMessageEnum::InfoMessages::BULK_IMPRESSION_SUCCESS,
49
- file: FileNameEnum::BatchEventsDispatcher,
50
- end_point: url,
51
- a: account_id
52
- )
49
+ 'IMPRESSION_BATCH_SUCCESS',
50
+ {
51
+ '{file}' => FILE,
52
+ '{endPoint}' => url,
53
+ '{accountId}' => account_id
54
+ }
53
55
  )
54
56
  message = nil
55
- elsif resp.code == '413'
57
+ when '413'
56
58
  @logger.log(
57
59
  LogLevelEnum::DEBUG,
58
- format(
59
- LogMessageEnum::DebugMessages::BATCH_EVENT_LIMIT_EXCEEDED,
60
- file: FileNameEnum::BatchEventsDispatcher,
61
- end_point: url,
62
- accountId: impression[:a],
63
- eventsPerRequest: impression.length()
64
- )
60
+ 'CONFIG_BATCH_EVENT_LIMIT_EXCEEDED',
61
+ {
62
+ '{file}' => FileNameEnum::BATCH_EVENTS_DISPATCHER,
63
+ '{endPoint}' => url,
64
+ '{eventsPerRequest}' => impression.length,
65
+ '{accountId}' => impression[:a]
66
+ }
65
67
  )
66
68
 
67
69
  @logger.log(
68
70
  LogLevelEnum::ERROR,
69
- format(
70
- LogMessageEnum::ErrorMessages::IMPRESSION_FAILED,
71
- file: FileNameEnum::BatchEventsDispatcher,
72
- end_point: url
73
- )
71
+ 'IMPRESSION_FAILED',
72
+ {
73
+ '{file}' => FileNameEnum::BATCH_EVENTS_DISPATCHER,
74
+ '{err}' => resp.message,
75
+ '{endPoint}' => url
76
+ }
74
77
  )
75
78
  message = resp.message
76
79
  else
77
80
  @logger.log(
78
- LogLevelEnum::DEBUG,
79
- format(
80
- LogMessageEnum::DebugMessages::BULK_NOT_PROCESSED,
81
- file: FileNameEnum::BatchEventsDispatcher
82
- )
81
+ LogLevelEnum::INFO,
82
+ 'IMPRESSION_BATCH_FAILED',
83
+ { '{file}' => FileNameEnum::BATCH_EVENTS_DISPATCHER }
83
84
  )
84
85
 
85
86
  @logger.log(
86
87
  LogLevelEnum::ERROR,
87
- format(LogMessageEnum::ErrorMessages::IMPRESSION_FAILED, file: FileNameEnum::BatchEventsDispatcher, end_point: url)
88
+ 'IMPRESSION_FAILED',
89
+ {
90
+ '{file}' => FileNameEnum::BATCH_EVENTS_DISPATCHER,
91
+ '{err}' => resp.message,
92
+ '{endPoint}' => url
93
+ }
88
94
  )
89
95
  message = resp.message
90
96
  end
91
- if callback
92
- callback.call(message, impression)
93
- end
97
+ callback&.call(message, impression)
98
+ true
94
99
  rescue StandardError => e
95
100
  @logger.log(
96
101
  LogLevelEnum::DEBUG,
97
- format(
98
- LogMessageEnum::DebugMessages::BULK_NOT_PROCESSED,
99
- file: FileNameEnum::BatchEventsDispatcher
100
- )
102
+ 'IMPRESSION_BATCH_FAILED',
103
+ { '{file}' => FileNameEnum::BATCH_EVENTS_DISPATCHER }
101
104
  )
102
105
 
103
106
  @logger.log(
104
107
  LogLevelEnum::ERROR,
105
- format(LogMessageEnum::ErrorMessages::IMPRESSION_FAILED, file: FileNameEnum::BatchEventsDispatcher, end_point: url)
108
+ 'IMPRESSION_FAILED',
109
+ {
110
+ '{file}' => FileNameEnum::BATCH_EVENTS_DISPATCHER,
111
+ '{err}' => e.message,
112
+ '{endPoint}' => url
113
+ }
106
114
  )
107
115
  false
108
116
  end
109
-
110
117
  end
111
118
  end
112
119
  end
@@ -12,9 +12,9 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- require_relative '../logger'
16
15
  require_relative '../enums'
17
16
  require_relative '../utils/request'
17
+ require_relative '../utils/log_message'
18
18
 
19
19
  class VWO
20
20
  module Services
@@ -23,7 +23,7 @@ class VWO
23
23
 
24
24
  def initialize(batch_config, is_development_mode = false)
25
25
  @is_development_mode = is_development_mode
26
- @logger = VWO::Logger.get_instance
26
+ @logger = VWO::Utils::Logger
27
27
  @queue = []
28
28
  @queue_metadata = {}
29
29
  @batch_config = batch_config
@@ -33,12 +33,13 @@ class VWO
33
33
  else
34
34
  @request_time_interval = CONSTANTS::DEFAULT_REQUEST_TIME_INTERVAL
35
35
  @logger.log(
36
- LogLevelEnum::DEBUG,
37
- format(
38
- LogMessageEnum::DebugMessages::EVENT_BATCHING_INSUFFICIENT,
39
- file: FileNameEnum::BatchEventsQueue,
40
- key: 'request_time_interval'
41
- )
36
+ LogLevelEnum::INFO,
37
+ 'EVENT_BATCH_DEFAULTS',
38
+ {
39
+ '{file}' => FileNameEnum::BATCH_EVENTS_QUEUE,
40
+ '{parameter}' => 'request_time_interval',
41
+ '{defaultValue}' => "#{@request_time_interval} ms"
42
+ }
42
43
  )
43
44
  end
44
45
 
@@ -47,19 +48,18 @@ class VWO
47
48
  else
48
49
  @events_per_request = CONSTANTS::DEFAULT_EVENTS_PER_REQUEST
49
50
  @logger.log(
50
- LogLevelEnum::DEBUG,
51
- format(
52
- LogMessageEnum::DebugMessages::EVENT_BATCHING_INSUFFICIENT,
53
- file: FileNameEnum::BatchEventsQueue,
54
- key: 'events_per_request'
55
- )
51
+ LogLevelEnum::INFO,
52
+ 'EVENT_BATCH_DEFAULTS',
53
+ {
54
+ '{file}' => FileNameEnum::BATCH_EVENTS_QUEUE,
55
+ '{parameter}' => 'events_per_request',
56
+ '{defaultValue}' => @events_per_request.to_s
57
+ }
56
58
  )
57
59
  end
58
60
 
59
61
  @flush_callback = nil
60
- if batch_config.key?(:flushCallback) && batch_config[:flushCallback].is_a?(Method)
61
- @flush_callback = batch_config[:flushCallback]
62
- end
62
+ @flush_callback = batch_config[:flushCallback] if batch_config.key?(:flushCallback) && batch_config[:flushCallback].is_a?(Method)
63
63
 
64
64
  @dispatcher = batch_config[:dispatcher]
65
65
  end
@@ -70,69 +70,62 @@ class VWO
70
70
 
71
71
  def enqueue(event)
72
72
  return true if @is_development_mode
73
+
73
74
  @queue.push(event)
74
75
  update_queue_metadata(event)
75
76
  unless @timer
76
77
  create_new_batch_timer
77
- @thread = Thread.new{flush_when_request_times_up}
78
- end
79
- if @events_per_request === @queue.length()
80
- flush
81
- kill_old_thread
78
+ @thread = Thread.new { flush_when_request_times_up }
82
79
  end
80
+ return unless @events_per_request == @queue.length
81
+
82
+ flush
83
+ kill_old_thread
83
84
  end
84
85
 
85
86
  def flush_when_request_times_up
86
- while @timer > Time.now
87
- sleep(1)
88
- end
87
+ sleep(1) while @timer > Time.now
89
88
  flush
90
89
  kill_old_thread
91
90
  end
92
91
 
93
92
  def flush(manual = false)
94
- if @queue.length() > 0
93
+ if @queue.length > 0
95
94
  @logger.log(
96
95
  LogLevelEnum::DEBUG,
97
- format(
98
- LogMessageEnum::DebugMessages::BEFORE_FLUSHING,
99
- file: FileNameEnum::BatchEventsQueue,
100
- manually: manual ? 'manually' : '',
101
- length: @queue.length(),
102
- timer: manual ? 'Timer will be cleared and registered again,' : '',
103
- queue_metadata: @queue_metadata
104
- )
96
+ 'EVENT_BATCH_BEFORE_FLUSHING',
97
+ {
98
+ '{file}' => FileNameEnum::BATCH_EVENTS_QUEUE,
99
+ '{manually}' => manual ? 'manually' : '',
100
+ '{length}' => @queue.length,
101
+ '{timer}' => manual ? 'Timer will be cleared and registered again,' : '',
102
+ '{accountId}' => @batch_config[:account_id]
103
+ }
105
104
  )
106
105
 
107
106
  @dispatcher.call(@queue, @flush_callback)
107
+
108
108
  @logger.log(
109
109
  LogLevelEnum::INFO,
110
- format(
111
- LogMessageEnum::InfoMessages::AFTER_FLUSHING,
112
- file: FILE,
113
- manually: manual ? 'manually,' : '',
114
- length: @queue.length(),
115
- queue_metadata: @queue_metadata
116
- )
110
+ 'EVENT_BATCH_After_FLUSHING',
111
+ {
112
+ '{file}' => FileNameEnum::BATCH_EVENTS_QUEUE,
113
+ '{manually}' => manual ? 'manually,' : '',
114
+ '{length}' => @queue.length
115
+ }
117
116
  )
118
117
  @queue_metadata = {}
119
118
  @queue = []
120
119
  else
121
120
  @logger.log(
122
121
  LogLevelEnum::INFO,
123
- format(
124
- 'Batch queue is empty. Nothing to flush.',
125
- file: FILE
126
- )
122
+ 'Batch queue is empty. Nothing to flush.',
123
+ { '{file}' => FILE }
127
124
  )
128
125
  end
129
126
 
130
127
  clear_request_timer
131
- unless manual
132
- if @thread
133
- @old_thread = @thread
134
- end
135
- end
128
+ @old_thread = @thread if !manual && @thread
136
129
  true
137
130
  end
138
131
 
@@ -141,32 +134,23 @@ class VWO
141
134
  end
142
135
 
143
136
  def kill_thread
144
- if @thread
145
- @thread.kill
146
- end
137
+ @thread&.kill
147
138
  end
148
139
 
149
140
  def kill_old_thread
150
- if @old_thread
151
- @old_thread.kill
152
- end
141
+ @old_thread&.kill
153
142
  end
154
143
 
155
144
  def update_queue_metadata(event)
156
- if event[:eT] == 1
157
- unless @queue_metadata.key?(VWO::EVENTS::TRACK_USER)
158
- @queue_metadata[VWO::EVENTS::TRACK_USER] = 0
159
- end
145
+ case event[:eT]
146
+ when 1
147
+ @queue_metadata[VWO::EVENTS::TRACK_USER] = 0 unless @queue_metadata.key?(VWO::EVENTS::TRACK_USER)
160
148
  @queue_metadata[VWO::EVENTS::TRACK_USER] = @queue_metadata[VWO::EVENTS::TRACK_USER] + 1
161
- elsif event[:eT] == 2
162
- unless @queue_metadata.key?(VWO::EVENTS::TRACK_GOAL)
163
- @queue_metadata[VWO::EVENTS::TRACK_GOAL] = 0
164
- end
149
+ when 2
150
+ @queue_metadata[VWO::EVENTS::TRACK_GOAL] = 0 unless @queue_metadata.key?(VWO::EVENTS::TRACK_GOAL)
165
151
  @queue_metadata[VWO::EVENTS::TRACK_GOAL] = @queue_metadata[VWO::EVENTS::TRACK_GOAL] + 1
166
- elsif event[:eT] == 3
167
- unless @queue_metadata.key?(VWO::EVENTS::PUSH)
168
- @queue_metadata[VWO::EVENTS::PUSH] = 0
169
- end
152
+ when 3
153
+ @queue_metadata[VWO::EVENTS::PUSH] = 0 unless @queue_metadata.key?(VWO::EVENTS::PUSH)
170
154
  @queue_metadata[VWO::EVENTS::PUSH] = @queue_metadata[VWO::EVENTS::PUSH] + 1
171
155
  end
172
156
  end