Module: VWO::Utils::Validations
Constant Summary
Constants included
from CONSTANTS
CONSTANTS::API_VERSION, CONSTANTS::DEFAULT_EVENTS_PER_REQUEST, CONSTANTS::DEFAULT_REQUEST_TIME_INTERVAL, CONSTANTS::GOAL_TYPES, CONSTANTS::HTTPS_PROTOCOL, CONSTANTS::HTTP_PROTOCOL, CONSTANTS::LIBRARY_PATH, CONSTANTS::MAX_EVENTS_PER_REQUEST, CONSTANTS::MAX_RANGE, CONSTANTS::MAX_TRAFFIC_PERCENT, CONSTANTS::MAX_TRAFFIC_VALUE, CONSTANTS::MIN_EVENTS_PER_REQUEST, CONSTANTS::MIN_REQUEST_TIME_INTERVAL, CONSTANTS::PLATFORM, CONSTANTS::RUBY_VARIABLE_TYPES, CONSTANTS::SDK_NAME, CONSTANTS::SDK_VERSION, CONSTANTS::SEED_VALUE, CONSTANTS::STATUS_RUNNING, CONSTANTS::URL_NAMESPACE, CONSTANTS::VWO_DELIMITER
Instance Method Summary
collapse
-
#invalid_config_log(parameter, type, api_name) ⇒ Object
-
#valid_basic_data_type?(val) ⇒ Boolean
-
#valid_batch_event_settings(batch_events, api_name) ⇒ Object
Validates if the value passed batch_events has correct data type and values or not.
-
#valid_boolean?(val) ⇒ Boolean
-
#valid_config_log(parameter, type) ⇒ Object
-
#valid_goal?(goal, campaign, user_id, goal_identifier, revenue_value, is_event_arch_enabled) ⇒ Boolean
-
#valid_hash?(val) ⇒ Boolean
-
#valid_number?(val) ⇒ Boolean
-
#valid_settings_file?(settings_file) ⇒ Boolean
Validates the settings_file.
-
#valid_string?(val) ⇒ Boolean
-
#valid_value?(val) ⇒ Boolean
-
#validate_sdk_config?(user_storage, is_development_mode, api_name) ⇒ Boolean
Instance Method Details
#invalid_config_log(parameter, type, api_name) ⇒ Object
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/vwo/utils/validations.rb', line 143
def invalid_config_log(parameter, type, api_name)
Logger.log(
LogLevelEnum::ERROR,
'CONFIG_PARAMETER_INVALID',
{
'{file}' => VWO::FileNameEnum::VALIDATE_UTIL,
'{parameter}' => parameter,
'{type}' => type,
'{api}' => api_name
}
)
end
|
#valid_basic_data_type?(val) ⇒ Boolean
64
65
66
|
# File 'lib/vwo/utils/validations.rb', line 64
def valid_basic_data_type?(val)
valid_number?(val) || valid_string?(val) || valid_boolean?(val)
end
|
#valid_batch_event_settings(batch_events, api_name) ⇒ Object
Validates if the value passed batch_events has correct data type and values or not.
Args: batch_events [Hash]: value to be tested
api_name [String]: current api name
@return: [Boolean]: True if all conditions are passed else False
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/vwo/utils/validations.rb', line 74
def valid_batch_event_settings(batch_events, api_name)
events_per_request = batch_events[:events_per_request]
request_time_interval = batch_events[:request_time_interval]
unless events_per_request || request_time_interval
invalid_config_log('batch_events', 'object', api_name)
return false
end
if request_time_interval && !valid_number?(request_time_interval)
invalid_config_log('batch_events', 'object', api_name)
return false
end
if events_per_request && !valid_number?(events_per_request)
invalid_config_log('batch_events', 'object', api_name)
return false
end
if events_per_request && (events_per_request < VWO::MIN_EVENTS_PER_REQUEST || events_per_request > VWO::MAX_EVENTS_PER_REQUEST)
invalid_config_log('batch_events', 'object', api_name)
return false
end
if request_time_interval && request_time_interval < VWO::MIN_REQUEST_TIME_INTERVAL
invalid_config_log('batch_events', 'object', api_name)
return false
end
if batch_events.key?(:flushCallback) && !batch_events[:flushCallback].is_a?(Method)
invalid_config_log('batch_events', 'object', api_name)
return false
end
true
end
|
#valid_boolean?(val) ⇒ Boolean
59
60
61
|
# File 'lib/vwo/utils/validations.rb', line 59
def valid_boolean?(val)
val.is_a?(TrueClass) || val.is_a?(FalseClass)
end
|
#valid_config_log(parameter, type) ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/vwo/utils/validations.rb', line 131
def valid_config_log(parameter, type)
Logger.log(
LogLevelEnum::INFO,
'CONFIG_PARAMETER_USED',
{
'{file}' => VWO::FileNameEnum::VALIDATE_UTIL,
'{parameter}' => parameter,
'{type}' => type
}
)
end
|
#valid_goal?(goal, campaign, user_id, goal_identifier, revenue_value, is_event_arch_enabled) ⇒ Boolean
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/vwo/utils/validations.rb', line 156
def valid_goal?(goal, campaign, user_id, goal_identifier, revenue_value, is_event_arch_enabled)
if goal.nil? || !goal['id']
Logger.log(
LogLevelEnum::ERROR,
'TRACK_API_GOAL_NOT_FOUND',
{
'{file}' => FILE,
'{goalIdentifier}' => goal_identifier,
'{userId}' => user_id,
'{campaignKey}' => campaign['key']
}
)
return false
elsif goal['type'] == GoalTypes::REVENUE && !valid_value?(revenue_value) && !is_event_arch_enabled
Logger.log(
LogLevelEnum::ERROR,
'TRACK_API_REVENUE_NOT_PASSED_FOR_REVENUE_GOAL',
{
'{file}' => FILE,
'{userId}' => user_id,
'{goalIdentifier}' => goal_identifier,
'{campaignKey}' => campaign['key']
}
)
return false
end
true
end
|
#valid_hash?(val) ⇒ Boolean
54
55
56
|
# File 'lib/vwo/utils/validations.rb', line 54
def valid_hash?(val)
val.is_a?(Hash)
end
|
#valid_number?(val) ⇒ Boolean
44
45
46
|
# File 'lib/vwo/utils/validations.rb', line 44
def valid_number?(val)
val.is_a?(Numeric)
end
|
#valid_settings_file?(settings_file) ⇒ Boolean
Validates the settings_file
31
32
33
34
35
36
|
# File 'lib/vwo/utils/validations.rb', line 31
def valid_settings_file?(settings_file)
settings_file = JSON.parse(settings_file)
JSON::Validator.validate!(VWO::Schema::SETTINGS_FILE_SCHEMA, settings_file)
rescue StandardError
false
end
|
#valid_string?(val) ⇒ Boolean
49
50
51
|
# File 'lib/vwo/utils/validations.rb', line 49
def valid_string?(val)
val.is_a?(String)
end
|
#valid_value?(val) ⇒ Boolean
39
40
41
|
# File 'lib/vwo/utils/validations.rb', line 39
def valid_value?(val)
!val.nil? && val != {} && val != []
end
|
#validate_sdk_config?(user_storage, is_development_mode, api_name) ⇒ Boolean
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/vwo/utils/validations.rb', line 110
def validate_sdk_config?(user_storage, is_development_mode, api_name)
if is_development_mode
if [true, false].include? is_development_mode
valid_config_log('isDevelopmentMode', 'boolean')
else
invalid_config_log('isDevelopmentMode', 'boolean', api_name)
return false
end
end
if user_storage
if user_storage.is_a?(UserStorage)
valid_config_log('UserStorageService', 'object')
else
invalid_config_log('UserStorageService', 'object', api_name)
return false
end
end
true
end
|