optimizely-sdk 2.1.1 → 3.0.0
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 +19 -47
- data/lib/optimizely/audience.rb +67 -13
- data/lib/optimizely/bucketer.rb +4 -1
- data/lib/optimizely/condition_tree_evaluator.rb +121 -0
- data/lib/optimizely/custom_attribute_condition_evaluator.rb +273 -0
- data/lib/optimizely/decision_service.rb +14 -9
- data/lib/optimizely/event_builder.rb +17 -26
- data/lib/optimizely/helpers/constants.rb +26 -1
- data/lib/optimizely/helpers/validator.rb +57 -4
- data/lib/optimizely/notification_center.rb +1 -0
- data/lib/optimizely/project_config.rb +30 -20
- data/lib/optimizely/version.rb +2 -2
- metadata +47 -18
- data/lib/optimizely/condition.rb +0 -135
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-2019, 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 = '
|
20
|
+
VERSION = '3.0.0'
|
21
21
|
end
|
metadata
CHANGED
@@ -1,71 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: optimizely-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Optimizely
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coveralls
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
25
32
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - "
|
45
|
+
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
47
|
+
version: '0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - "
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - "
|
59
|
+
- - ">="
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
61
|
+
version: '0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- - "
|
66
|
+
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rubocop
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
75
|
+
version: '0.62'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
82
|
+
version: '0.62'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: httparty
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,7 +146,8 @@ files:
|
|
118
146
|
- lib/optimizely.rb
|
119
147
|
- lib/optimizely/audience.rb
|
120
148
|
- lib/optimizely/bucketer.rb
|
121
|
-
- lib/optimizely/
|
149
|
+
- lib/optimizely/condition_tree_evaluator.rb
|
150
|
+
- lib/optimizely/custom_attribute_condition_evaluator.rb
|
122
151
|
- lib/optimizely/decision_service.rb
|
123
152
|
- lib/optimizely/error_handler.rb
|
124
153
|
- lib/optimizely/event_builder.rb
|
@@ -155,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
184
|
version: '0'
|
156
185
|
requirements: []
|
157
186
|
rubyforge_project:
|
158
|
-
rubygems_version: 2.
|
187
|
+
rubygems_version: 2.6.14
|
159
188
|
signing_key:
|
160
189
|
specification_version: 4
|
161
190
|
summary: Ruby SDK for Optimizely's testing framework
|
data/lib/optimizely/condition.rb
DELETED
@@ -1,135 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#
|
4
|
-
# Copyright 2016-2017, Optimizely and contributors
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
require 'json'
|
19
|
-
|
20
|
-
module Optimizely
|
21
|
-
class ConditionalOperatorTypes
|
22
|
-
AND = 'and'
|
23
|
-
OR = 'or'
|
24
|
-
NOT = 'not'
|
25
|
-
end
|
26
|
-
|
27
|
-
class ConditionEvaluator
|
28
|
-
DEFAULT_OPERATOR_TYPES = [
|
29
|
-
ConditionalOperatorTypes::AND,
|
30
|
-
ConditionalOperatorTypes::OR,
|
31
|
-
ConditionalOperatorTypes::NOT
|
32
|
-
].freeze
|
33
|
-
|
34
|
-
attr_reader :user_attributes
|
35
|
-
|
36
|
-
def initialize(user_attributes)
|
37
|
-
@user_attributes = user_attributes
|
38
|
-
end
|
39
|
-
|
40
|
-
def and_evaluator(conditions)
|
41
|
-
# Evaluates an array of conditions as if the evaluator had been applied
|
42
|
-
# to each entry and the results AND-ed together.
|
43
|
-
#
|
44
|
-
# conditions - Array of conditions ex: [operand_1, operand_2]
|
45
|
-
#
|
46
|
-
# Returns boolean true if all operands evaluate to true.
|
47
|
-
|
48
|
-
conditions.each do |condition|
|
49
|
-
result = evaluate(condition)
|
50
|
-
return result if result == false
|
51
|
-
end
|
52
|
-
|
53
|
-
true
|
54
|
-
end
|
55
|
-
|
56
|
-
def or_evaluator(conditions)
|
57
|
-
# Evaluates an array of conditions as if the evaluator had been applied
|
58
|
-
# to each entry and the results AND-ed together.
|
59
|
-
#
|
60
|
-
# conditions - Array of conditions ex: [operand_1, operand_2]
|
61
|
-
#
|
62
|
-
# Returns boolean true if any operand evaluates to true.
|
63
|
-
|
64
|
-
conditions.each do |condition|
|
65
|
-
result = evaluate(condition)
|
66
|
-
return result if result == true
|
67
|
-
end
|
68
|
-
|
69
|
-
false
|
70
|
-
end
|
71
|
-
|
72
|
-
def not_evaluator(single_condition)
|
73
|
-
# Evaluates an array of conditions as if the evaluator had been applied
|
74
|
-
# to a single entry and NOT was applied to the result.
|
75
|
-
#
|
76
|
-
# single_condition - Array of a single condition ex: [operand_1]
|
77
|
-
#
|
78
|
-
# Returns boolean true if the operand evaluates to false.
|
79
|
-
|
80
|
-
return false if single_condition.length != 1
|
81
|
-
|
82
|
-
!evaluate(single_condition[0])
|
83
|
-
end
|
84
|
-
|
85
|
-
def evaluator(condition_array)
|
86
|
-
# Method to compare single audience condition against provided user data i.e. attributes.
|
87
|
-
#
|
88
|
-
# condition_array - Array consisting of condition key and corresponding value.
|
89
|
-
#
|
90
|
-
# Returns boolean indicating the result of comparing the condition value against the user attributes.
|
91
|
-
|
92
|
-
condition_array[1] == @user_attributes[condition_array[0]]
|
93
|
-
end
|
94
|
-
|
95
|
-
def evaluate(conditions)
|
96
|
-
# Top level method to evaluate audience conditions.
|
97
|
-
#
|
98
|
-
# conditions - Nested array of and/or conditions.
|
99
|
-
# Example: ['and', operand_1, ['or', operand_2, operand_3]]
|
100
|
-
#
|
101
|
-
# Returns boolean result of evaluating the conditions evaluated.
|
102
|
-
|
103
|
-
if conditions.is_a? Array
|
104
|
-
operator_type = conditions[0]
|
105
|
-
return false unless DEFAULT_OPERATOR_TYPES.include?(operator_type)
|
106
|
-
case operator_type
|
107
|
-
when ConditionalOperatorTypes::AND
|
108
|
-
return and_evaluator(conditions[1..-1])
|
109
|
-
when ConditionalOperatorTypes::OR
|
110
|
-
return or_evaluator(conditions[1..-1])
|
111
|
-
when ConditionalOperatorTypes::NOT
|
112
|
-
return not_evaluator(conditions[1..-1])
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
# Create array of condition key and corresponding value of audience condition.
|
117
|
-
condition_array = audience_condition_deserializer(conditions)
|
118
|
-
|
119
|
-
# Compare audience condition against provided user data i.e. attributes.
|
120
|
-
evaluator(condition_array)
|
121
|
-
end
|
122
|
-
|
123
|
-
private
|
124
|
-
|
125
|
-
def audience_condition_deserializer(condition)
|
126
|
-
# Deserializer defining how hashes need to be decoded for audience conditions.
|
127
|
-
#
|
128
|
-
# condition - Hash representing one audience condition.
|
129
|
-
#
|
130
|
-
# Returns array consisting of condition key and corresponding value.
|
131
|
-
|
132
|
-
[condition['name'], condition['value']]
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|