vwo-sdk 1.36.0 → 1.37.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,6 +23,7 @@ class VWO
23
23
  module Utils
24
24
  module Validations
25
25
  include Enums
26
+ include CONSTANTS
26
27
  # Validates the settings_file
27
28
  # @param [Hash]: JSON object received from VWO server
28
29
  # must be JSON.
@@ -70,7 +71,7 @@ class VWO
70
71
  # api_name [String]: current api name
71
72
  #
72
73
  # @return: [Boolean]: True if all conditions are passed else False
73
- def is_valid_batch_event_settings(batch_events, api_name)
74
+ def valid_batch_event_settings(batch_events, api_name)
74
75
  events_per_request = batch_events[:events_per_request]
75
76
  request_time_interval = batch_events[:request_time_interval]
76
77
 
@@ -79,12 +80,12 @@ class VWO
79
80
  return false
80
81
  end
81
82
 
82
- if (request_time_interval && !valid_number?(request_time_interval))
83
+ if request_time_interval && !valid_number?(request_time_interval)
83
84
  invalid_config_log('batch_events', 'object', api_name)
84
85
  return false
85
86
  end
86
87
 
87
- if (events_per_request && !valid_number?(events_per_request))
88
+ if events_per_request && !valid_number?(events_per_request)
88
89
  invalid_config_log('batch_events', 'object', api_name)
89
90
  return false
90
91
  end
@@ -132,7 +133,7 @@ class VWO
132
133
  LogLevelEnum::INFO,
133
134
  'CONFIG_PARAMETER_USED',
134
135
  {
135
- '{file}' => VWO::FileNameEnum::ValidateUtil,
136
+ '{file}' => VWO::FileNameEnum::VALIDATE_UTIL,
136
137
  '{parameter}' => parameter,
137
138
  '{type}' => type
138
139
  }
@@ -144,13 +145,79 @@ class VWO
144
145
  LogLevelEnum::ERROR,
145
146
  'CONFIG_PARAMETER_INVALID',
146
147
  {
147
- '{file}' => VWO::FileNameEnum::ValidateUtil,
148
+ '{file}' => VWO::FileNameEnum::VALIDATE_UTIL,
148
149
  '{parameter}' => parameter,
149
150
  '{type}' => type,
150
151
  '{api}' => api_name
151
152
  }
152
153
  )
153
154
  end
155
+
156
+ def valid_goal?(goal, campaign, user_id, goal_identifier, revenue_value)
157
+ if goal.nil? || !goal['id']
158
+ Logger.log(
159
+ LogLevelEnum::ERROR,
160
+ 'TRACK_API_GOAL_NOT_FOUND',
161
+ {
162
+ '{file}' => FILE,
163
+ '{goalIdentifier}' => goal_identifier,
164
+ '{userId}' => user_id,
165
+ '{campaignKey}' => campaign['key']
166
+ }
167
+ )
168
+ return false
169
+ elsif goal['type'] == GoalTypes::REVENUE && !valid_value?(revenue_value)
170
+ Logger.log(
171
+ LogLevelEnum::ERROR,
172
+ 'TRACK_API_REVENUE_NOT_PASSED_FOR_REVENUE_GOAL',
173
+ {
174
+ '{file}' => FILE,
175
+ '{userId}' => user_id,
176
+ '{goalIdentifier}' => goal_identifier,
177
+ '{campaignKey}' => campaign['key']
178
+ }
179
+ )
180
+ return false
181
+ end
182
+ true
183
+ end
184
+ end
185
+
186
+ def valid_campaign_for_track_api?(user_id, campaign_key, campaign_type)
187
+ if campaign_type == CONSTANTS::CampaignTypes::FEATURE_ROLLOUT
188
+ Logger.log(
189
+ LogLevelEnum::ERROR,
190
+ 'API_NOT_APPLICABLE',
191
+ {
192
+ '{file}' => FILE,
193
+ '{api}' => ApiMethods::TRACK,
194
+ '{userId}' => user_id,
195
+ '{campaignKey}' => campaign_key,
196
+ '{campaignType}' => campaign_type
197
+ }
198
+ )
199
+ return false
200
+ end
201
+ true
202
+ end
203
+
204
+ def valid_track_api_params?(user_id, campaign_key, custom_variables, variation_targeting_variables, goal_type_to_track, goal_identifier)
205
+ unless (valid_string?(campaign_key) || campaign_key.is_a?(Array) || campaign_key.nil?) &&
206
+ valid_string?(user_id) && valid_string?(goal_identifier) &&
207
+ (custom_variables.nil? || valid_hash?(custom_variables)) &&
208
+ (variation_targeting_variables.nil? || valid_hash?(variation_targeting_variables)) && CONSTANTS::GOAL_TYPES.key?(goal_type_to_track)
209
+ # log invalid params
210
+ Logger.log(
211
+ LogLevelEnum::ERROR,
212
+ 'API_BAD_PARAMETERS',
213
+ {
214
+ '{file}' => FILE,
215
+ '{api}' => ApiMethods::TRACK
216
+ }
217
+ )
218
+ return false
219
+ end
220
+ true
154
221
  end
155
222
  end
156
223
  end