optimizely-sdk 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/optimizely.rb +36 -31
- data/lib/optimizely/helpers/constants.rb +10 -1
- data/lib/optimizely/helpers/validator.rb +22 -1
- data/lib/optimizely/project_config.rb +13 -10
- data/lib/optimizely/version.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 948c6214e7f77820c80ba9f419260555c17419ba
|
4
|
+
data.tar.gz: 0dfe6752f4194aa537c9364587f292a39125f4f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d81fc2852d21a471d14c5a20c80c967baba140ee0387326cb427474b71e215056e51aa4c0d75dba23ceb1024b576c9eef988ff653ab40ea4afd3a74a1cefba1b
|
7
|
+
data.tar.gz: 9010d5770d5b5e446b0494ca7de9f21f91d1e2949acf91958a1afa48492b8fe18aa3255a7b68315918ca3a175f57743f9b2b1eb815ad7d33a0efda42b47acda7
|
data/lib/optimizely.rb
CHANGED
@@ -105,6 +105,13 @@ module Optimizely
|
|
105
105
|
return nil
|
106
106
|
end
|
107
107
|
|
108
|
+
return nil unless Optimizely::Helpers::Validator.inputs_valid?(
|
109
|
+
{
|
110
|
+
experiment_key: experiment_key,
|
111
|
+
user_id: user_id
|
112
|
+
}, @logger, Logger::ERROR
|
113
|
+
)
|
114
|
+
|
108
115
|
variation_key = get_variation(experiment_key, user_id, attributes)
|
109
116
|
|
110
117
|
if variation_key.nil?
|
@@ -135,10 +142,12 @@ module Optimizely
|
|
135
142
|
return nil
|
136
143
|
end
|
137
144
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
145
|
+
return nil unless Optimizely::Helpers::Validator.inputs_valid?(
|
146
|
+
{
|
147
|
+
experiment_key: experiment_key,
|
148
|
+
user_id: user_id
|
149
|
+
}, @logger, Logger::ERROR
|
150
|
+
)
|
142
151
|
|
143
152
|
unless user_inputs_valid?(attributes)
|
144
153
|
@logger.log(Logger::INFO, "Not activating user '#{user_id}.")
|
@@ -196,10 +205,12 @@ module Optimizely
|
|
196
205
|
return nil
|
197
206
|
end
|
198
207
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
208
|
+
return nil unless Optimizely::Helpers::Validator.inputs_valid?(
|
209
|
+
{
|
210
|
+
event_key: event_key,
|
211
|
+
user_id: user_id
|
212
|
+
}, @logger, Logger::ERROR
|
213
|
+
)
|
203
214
|
|
204
215
|
return nil unless user_inputs_valid?(attributes, event_tags)
|
205
216
|
|
@@ -254,15 +265,12 @@ module Optimizely
|
|
254
265
|
return false
|
255
266
|
end
|
256
267
|
|
257
|
-
unless
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
@logger.log(Logger::ERROR, 'User ID cannot be empty.')
|
264
|
-
return false
|
265
|
-
end
|
268
|
+
return false unless Optimizely::Helpers::Validator.inputs_valid?(
|
269
|
+
{
|
270
|
+
feature_flag_key: feature_flag_key,
|
271
|
+
user_id: user_id
|
272
|
+
}, @logger, Logger::ERROR
|
273
|
+
)
|
266
274
|
|
267
275
|
feature_flag = @config.get_feature_flag_from_key(feature_flag_key)
|
268
276
|
unless feature_flag
|
@@ -312,6 +320,8 @@ module Optimizely
|
|
312
320
|
return enabled_features
|
313
321
|
end
|
314
322
|
|
323
|
+
return enabled_features unless Optimizely::Helpers::Validator.inputs_valid?({user_id: user_id}, @logger, Logger::ERROR)
|
324
|
+
|
315
325
|
@config.feature_flags.each do |feature|
|
316
326
|
enabled_features.push(feature['key']) if is_feature_enabled(
|
317
327
|
feature['key'],
|
@@ -426,20 +436,15 @@ module Optimizely
|
|
426
436
|
# Returns nil if the feature flag or variable or user ID is empty
|
427
437
|
# in case of variable type mismatch
|
428
438
|
|
429
|
-
unless
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
if user_id.to_s.empty?
|
440
|
-
@logger.log(Logger::ERROR, 'User ID cannot be empty.')
|
441
|
-
return nil
|
442
|
-
end
|
439
|
+
return nil unless Optimizely::Helpers::Validator.inputs_valid?(
|
440
|
+
{
|
441
|
+
feature_flag_key: feature_flag_key,
|
442
|
+
variable_key: variable_key,
|
443
|
+
variable_type: variable_type,
|
444
|
+
user_id: user_id
|
445
|
+
},
|
446
|
+
@logger, Logger::ERROR
|
447
|
+
)
|
443
448
|
|
444
449
|
feature_flag = @config.get_feature_flag_from_key(feature_flag_key)
|
445
450
|
unless feature_flag
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
#
|
4
|
-
# Copyright 2016-
|
4
|
+
# Copyright 2016-2018, Optimizely and contributors
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
@@ -306,6 +306,15 @@ module Optimizely
|
|
306
306
|
'INTEGER' => 'integer',
|
307
307
|
'STRING' => 'string'
|
308
308
|
}.freeze
|
309
|
+
|
310
|
+
INPUT_VARIABLES = {
|
311
|
+
'FEATURE_FLAG_KEY' => 'Feature flag key',
|
312
|
+
'EXPERIMENT_KEY' => 'Experiment key',
|
313
|
+
'USER_ID' => 'User ID',
|
314
|
+
'VARIATION_KEY' => 'Variation key',
|
315
|
+
'VARIABLE_KEY' => 'Variable key',
|
316
|
+
'VARIABLE_TYPE' => 'Variable type'
|
317
|
+
}.freeze
|
309
318
|
end
|
310
319
|
end
|
311
320
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
#
|
4
|
-
# Copyright 2016-
|
4
|
+
# Copyright 2016-2018, Optimizely and contributors
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
@@ -95,6 +95,27 @@ module Optimizely
|
|
95
95
|
rescue
|
96
96
|
false
|
97
97
|
end
|
98
|
+
|
99
|
+
def inputs_valid?(variables, logger = NoOpLogger.new, level = Logger::ERROR)
|
100
|
+
# Determines if values of variables in given array are non empty string.
|
101
|
+
#
|
102
|
+
# variables - array values to validate.
|
103
|
+
#
|
104
|
+
# logger - logger.
|
105
|
+
#
|
106
|
+
# Returns boolean True if all of the values are valid, False otherwise.
|
107
|
+
|
108
|
+
return false unless variables.respond_to?(:each) && !variables.empty?
|
109
|
+
is_valid = true
|
110
|
+
variables.each do |key, value|
|
111
|
+
next if value.is_a?(String) && !value.empty?
|
112
|
+
is_valid = false
|
113
|
+
if logger_valid?(logger) && level
|
114
|
+
logger.log(level, "#{Optimizely::Helpers::Constants::INPUT_VARIABLES[key.to_s.upcase]} is invalid")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
is_valid
|
118
|
+
end
|
98
119
|
end
|
99
120
|
end
|
100
121
|
end
|
@@ -15,6 +15,7 @@
|
|
15
15
|
# limitations under the License.
|
16
16
|
#
|
17
17
|
require 'json'
|
18
|
+
require_relative 'helpers/validator'
|
18
19
|
|
19
20
|
module Optimizely
|
20
21
|
V1_CONFIG_VERSION = '1'
|
@@ -275,11 +276,12 @@ module Optimizely
|
|
275
276
|
#
|
276
277
|
# Returns Variation The variation which the given user and experiment should be forced into.
|
277
278
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
279
|
+
return nil unless Optimizely::Helpers::Validator.inputs_valid?(
|
280
|
+
{
|
281
|
+
experiment_key: experiment_key,
|
282
|
+
user_id: user_id
|
283
|
+
}, @logger, Logger::DEBUG
|
284
|
+
)
|
283
285
|
|
284
286
|
unless @forced_variation_map.key? user_id
|
285
287
|
@logger.log(Logger::DEBUG, "User '#{user_id}' is not in the forced variation map.")
|
@@ -323,11 +325,12 @@ module Optimizely
|
|
323
325
|
#
|
324
326
|
# Returns a boolean value that indicates if the set completed successfully.
|
325
327
|
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
328
|
+
return false unless Optimizely::Helpers::Validator.inputs_valid?(
|
329
|
+
{
|
330
|
+
user_id: user_id,
|
331
|
+
experiment_key: experiment_key
|
332
|
+
}, @logger, Logger::DEBUG
|
333
|
+
)
|
331
334
|
|
332
335
|
experiment = get_experiment_from_key(experiment_key)
|
333
336
|
experiment_id = experiment['id'] if experiment
|
data/lib/optimizely/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
#
|
4
|
-
# Copyright 2016-
|
4
|
+
# Copyright 2016-2018, Optimizely and contributors
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
@@ -17,5 +17,5 @@
|
|
17
17
|
#
|
18
18
|
module Optimizely
|
19
19
|
CLIENT_ENGINE = 'ruby-sdk'
|
20
|
-
VERSION = '2.0.
|
20
|
+
VERSION = '2.0.1'
|
21
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: optimizely-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Optimizely
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
155
|
version: '0'
|
156
156
|
requirements: []
|
157
157
|
rubyforge_project:
|
158
|
-
rubygems_version: 2.
|
158
|
+
rubygems_version: 2.5.1
|
159
159
|
signing_key:
|
160
160
|
specification_version: 4
|
161
161
|
summary: Ruby SDK for Optimizely's testing framework
|