optimizely-sdk 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/optimizely.rb +8 -4
- data/lib/optimizely/helpers/constants.rb +115 -5
- data/lib/optimizely/version.rb +1 -1
- data/lib/start.rb +131 -6
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78af637c6334c098627f0f83824494fb30fb0de4
|
4
|
+
data.tar.gz: d9d32f68014ec5866e521e274ac384fef1e22e81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09fdf5e75b3fb050d43f627af4f81225d8bdd2ed0f10c89b8dfe8b485f1849b669497315645e54d7eb8fdcec7209892ebdb9a5a5af68805bd7f3873051738eb7
|
7
|
+
data.tar.gz: 1bd6b64f56ef37dc6c2c38af651fce3c967832da5cf22a05e67683befb0bd3aeaec61c441a8d4ca6a961b97a6654f1362a8d5ea1d4a63b568c55a0858ff72d15
|
data/lib/optimizely.rb
CHANGED
@@ -18,7 +18,7 @@ module Optimizely
|
|
18
18
|
attr_accessor :logger
|
19
19
|
attr_accessor :error_handler
|
20
20
|
|
21
|
-
def initialize(datafile, event_dispatcher = nil, logger = nil, error_handler = nil)
|
21
|
+
def initialize(datafile, event_dispatcher = nil, logger = nil, error_handler = nil, skip_json_validation = false)
|
22
22
|
# Constructor for Projects.
|
23
23
|
#
|
24
24
|
# datafile - JSON string representing the project.
|
@@ -26,11 +26,12 @@ module Optimizely
|
|
26
26
|
# logger - Optional param which provides a log method to log messages. By default nothing would be logged.
|
27
27
|
# error_handler - Optional param which provides a handle_error method to handle exceptions.
|
28
28
|
# By default all exceptions will be suppressed.
|
29
|
+
# skip_json_validation - Optional boolean param to skip JSON schema validation of the provided datafile.
|
29
30
|
|
30
31
|
@logger = logger || NoOpLogger.new
|
31
32
|
@error_handler = error_handler || NoOpErrorHandler.new
|
32
33
|
@event_dispatcher = event_dispatcher || EventDispatcher.new
|
33
|
-
validate_inputs(datafile)
|
34
|
+
validate_inputs(datafile, skip_json_validation)
|
34
35
|
|
35
36
|
@config = ProjectConfig.new(datafile, @logger, @error_handler)
|
36
37
|
@bucketer = Bucketer.new(@config)
|
@@ -172,8 +173,11 @@ module Optimizely
|
|
172
173
|
true
|
173
174
|
end
|
174
175
|
|
175
|
-
def validate_inputs(datafile)
|
176
|
-
|
176
|
+
def validate_inputs(datafile, skip_json_validation)
|
177
|
+
unless skip_json_validation
|
178
|
+
raise InvalidDatafileError unless Helpers::Validator.datafile_valid?(datafile)
|
179
|
+
end
|
180
|
+
|
177
181
|
raise InvalidLoggerError unless Helpers::Validator.logger_valid?(@logger)
|
178
182
|
raise InvalidErrorHandlerError unless Helpers::Validator.error_handler_valid?(@error_handler)
|
179
183
|
raise InvalidEventDispatcherError unless Helpers::Validator.event_dispatcher_valid?(@event_dispatcher)
|
@@ -10,6 +10,115 @@ module Optimizely
|
|
10
10
|
'accountId' => {
|
11
11
|
'type' => 'string'
|
12
12
|
},
|
13
|
+
'groups' => {
|
14
|
+
'type' => 'array',
|
15
|
+
'items' => {
|
16
|
+
'type' => 'object',
|
17
|
+
'properties' => {
|
18
|
+
'id' => {
|
19
|
+
'type' => 'string'
|
20
|
+
},
|
21
|
+
'policy' => {
|
22
|
+
'type' => 'string'
|
23
|
+
},
|
24
|
+
'trafficAllocation' => {
|
25
|
+
'type' => 'array',
|
26
|
+
'items' => {
|
27
|
+
'type' => 'object',
|
28
|
+
'properties' => {
|
29
|
+
'entityId' => {
|
30
|
+
'type' => 'string'
|
31
|
+
},
|
32
|
+
'endOfRange' => {
|
33
|
+
'type' => 'integer'
|
34
|
+
}
|
35
|
+
},
|
36
|
+
'required' => [
|
37
|
+
'entityId',
|
38
|
+
'endOfRange'
|
39
|
+
]
|
40
|
+
}
|
41
|
+
},
|
42
|
+
'experiments' => {
|
43
|
+
'type' => 'array',
|
44
|
+
'items' => {
|
45
|
+
'type' => 'object',
|
46
|
+
'properties' => {
|
47
|
+
'id' => {
|
48
|
+
'type' => 'string'
|
49
|
+
},
|
50
|
+
'key' => {
|
51
|
+
'type' => 'string'
|
52
|
+
},
|
53
|
+
'status' => {
|
54
|
+
'type' => 'string'
|
55
|
+
},
|
56
|
+
'variations' => {
|
57
|
+
'type' => 'array',
|
58
|
+
'items' => {
|
59
|
+
'type' => 'object',
|
60
|
+
'properties' => {
|
61
|
+
'id' => {
|
62
|
+
'type' => 'string'
|
63
|
+
},
|
64
|
+
'key' => {
|
65
|
+
'type' => 'string'
|
66
|
+
}
|
67
|
+
},
|
68
|
+
'required' => [
|
69
|
+
'id',
|
70
|
+
'key'
|
71
|
+
]
|
72
|
+
}
|
73
|
+
},
|
74
|
+
'trafficAllocation' => {
|
75
|
+
'type' => 'array',
|
76
|
+
'items' => {
|
77
|
+
'type' => 'object',
|
78
|
+
'properties' => {
|
79
|
+
'entityId' => {
|
80
|
+
'type' => 'string'
|
81
|
+
},
|
82
|
+
'endOfRange' => {
|
83
|
+
'type' => 'integer'
|
84
|
+
}
|
85
|
+
},
|
86
|
+
'required' => [
|
87
|
+
'entityId',
|
88
|
+
'endOfRange'
|
89
|
+
]
|
90
|
+
}
|
91
|
+
},
|
92
|
+
'audienceIds' => {
|
93
|
+
'type' => 'array',
|
94
|
+
'items' => {
|
95
|
+
'type' => 'string'
|
96
|
+
}
|
97
|
+
},
|
98
|
+
'forcedVariations' => {
|
99
|
+
'type' => 'object'
|
100
|
+
}
|
101
|
+
},
|
102
|
+
'required' => [
|
103
|
+
'id',
|
104
|
+
'key',
|
105
|
+
'status',
|
106
|
+
'variations',
|
107
|
+
'trafficAllocation',
|
108
|
+
'audienceIds',
|
109
|
+
'forcedVariations'
|
110
|
+
]
|
111
|
+
}
|
112
|
+
}
|
113
|
+
},
|
114
|
+
'required' => [
|
115
|
+
'id',
|
116
|
+
'policy',
|
117
|
+
'trafficAllocation',
|
118
|
+
'experiments'
|
119
|
+
]
|
120
|
+
}
|
121
|
+
},
|
13
122
|
'experiments' => {
|
14
123
|
'type' => 'array',
|
15
124
|
'items' => {
|
@@ -21,6 +130,9 @@ module Optimizely
|
|
21
130
|
'key' => {
|
22
131
|
'type' => 'string'
|
23
132
|
},
|
133
|
+
'status' => {
|
134
|
+
'type' => 'string'
|
135
|
+
},
|
24
136
|
'variations' => {
|
25
137
|
'type' => 'array',
|
26
138
|
'items' => {
|
@@ -57,9 +169,6 @@ module Optimizely
|
|
57
169
|
]
|
58
170
|
}
|
59
171
|
},
|
60
|
-
'percentageIncluded' => {
|
61
|
-
'type' => 'integer'
|
62
|
-
},
|
63
172
|
'audienceIds' => {
|
64
173
|
'type' => 'array',
|
65
174
|
'items' => {
|
@@ -75,9 +184,9 @@ module Optimizely
|
|
75
184
|
'key',
|
76
185
|
'variations',
|
77
186
|
'trafficAllocation',
|
78
|
-
'percentageIncluded',
|
79
187
|
'audienceIds',
|
80
|
-
'forcedVariations'
|
188
|
+
'forcedVariations',
|
189
|
+
'status'
|
81
190
|
]
|
82
191
|
}
|
83
192
|
},
|
@@ -162,6 +271,7 @@ module Optimizely
|
|
162
271
|
'accountId',
|
163
272
|
'experiments',
|
164
273
|
'events',
|
274
|
+
'groups',
|
165
275
|
'audiences',
|
166
276
|
'dimensions',
|
167
277
|
'version',
|
data/lib/optimizely/version.rb
CHANGED
data/lib/start.rb
CHANGED
@@ -1,6 +1,131 @@
|
|
1
|
-
require
|
2
|
-
require '
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
@
|
1
|
+
require './optimizely'
|
2
|
+
require 'benchmark'
|
3
|
+
|
4
|
+
class PerformanceTests
|
5
|
+
@error_handler = Optimizely::NoOpErrorHandler.new
|
6
|
+
@logger = Optimizely::NoOpLogger.new
|
7
|
+
|
8
|
+
def self.test_initialize(testdata, optly)
|
9
|
+
Optimizely::Project.new(testdata)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.test_initialize_logger(testdata, optly)
|
13
|
+
Optimizely::Project.new(testdata, nil, @logger)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.test_initialize_logger_and_error_handler(testdata, optly)
|
17
|
+
Optimizely::Project.new(testdata, nil, @logger, @error_handler)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.test_initialize_no_schema_validation(testdata, optly)
|
21
|
+
Optimizely::Project.new(testdata, nil, nil, nil, true)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.test_initialize_logger_no_schema_validation(testdata, optly)
|
25
|
+
Optimizely::Project.new(testdata, nil, @logger, nil, true)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.test_initialize_error_handler_no_schema_validation(testdata, optly)
|
29
|
+
Optimizely::Project.new(testdata, nil, nil, @error_handler, true)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.test_initialize_logger_error_handler_no_schema_validation(testdata, optly)
|
33
|
+
Optimizely::Project.new(testdata, nil, @logger, @error_handler, true)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.test_initialize_error_handler_no_schema_validation(testdata, optly)
|
37
|
+
Optimizely::Project.new(testdata, nil, nil, @error_handler, true)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.test_activate(testdata, optly)
|
41
|
+
optly.activate('testExperiment2', 'optimizely_user')
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.test_activate_with_attributes(testdata, optly)
|
45
|
+
optly.activate('testExperimentWithFirefoxAudience', 'optimizely_user', {'browser_type' => 'firefox'})
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.test_activate_with_forced_variation(testdata, optly)
|
49
|
+
optly.activate('testExperiment2', 'variation_user')
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.test_activate_grouped_exp(testdata, optly)
|
53
|
+
optly.activate('mutex_exp2', 'optimizely_user')
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.test_activate_grouped_exp_with_attributes(testdata, optly)
|
57
|
+
optly.activate('mutex_exp1', 'optimizely_user', {'browser_type' => 'firefox'})
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.test_get_variation(testdata, optly)
|
61
|
+
optly.get_variation('testExperiment2', 'optimizely_user')
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.test_get_variation_with_attributes(testdata, optly)
|
65
|
+
optly.get_variation('testExperimentWithFirefoxAudience', 'optimizely_user', {'browser_type' => 'firefox'})
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.test_get_variation_with_forced_variation(testdata, optly)
|
69
|
+
optly.get_variation('testExperiment2', 'variation_user')
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.test_get_variation_grouped_exp(testdata, optly)
|
73
|
+
optly.get_variation('mutex_exp2', 'optimizely_user')
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.test_get_variation_grouped_exp_with_attributes(testdata, optly)
|
77
|
+
optly.get_variation('mutex_exp1', 'optimizely_user')
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.test_track(testdata, optly)
|
81
|
+
optly.track('testEvent', 'optimizely_user')
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.test_track_with_attributes(testdata, optly)
|
85
|
+
optly.track('testEventWithAudiences' 'optimizely_user', {'browser_type' => 'firefox'})
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.test_track_with_revenue(testdata, optly)
|
89
|
+
optly.track('testEvent', 'optimizely_user', nil, 666)
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.test_track_with_attributes_and_revenue(testdata, optly)
|
93
|
+
optly.track('testEventWithAudiences', 'optimizely_user', {'browser_type' => 'firefox'}, 666)
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.test_track_grouped_exp(testdata, optly)
|
97
|
+
optly.track('testEventWithMultipleGroupedExperiments', 'optimizely_user')
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.test_track_grouped_exp_with_attributes(testdata, optly)
|
101
|
+
optly.track('testEventWithMultipleExperiments', 'optimizely_user', {'browser_type' => 'firefox'})
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.test_track_grouped_exp_with_revenue(testdata, optly)
|
105
|
+
optly.track('testEventWithMultipleGroupedExperiments', 'optimizely_user', nil, 666)
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.test_track_grouped_exp_with_attributes_and_revenue(testdata, optly)
|
109
|
+
optly.track('testEventWithMultipleExperiments', 'optimizely_user', {'browser_type' => 'firefox'}, 666)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def run_tests
|
114
|
+
testdata10 = File.read('testdata_10.json')
|
115
|
+
testdata25 = File.read('testdata_25.json')
|
116
|
+
testdata50 = File.read('testdata_50.json')
|
117
|
+
optly10 = Optimizely::Project.new(testdata10)
|
118
|
+
optly25 = Optimizely::Project.new(testdata25)
|
119
|
+
optly50 = Optimizely::Project.new(testdata50)
|
120
|
+
|
121
|
+
tests = PerformanceTests.methods(false)
|
122
|
+
tests.each do |test|
|
123
|
+
puts '', test
|
124
|
+
Benchmark.bmbm do |x|
|
125
|
+
x.report('10 exps') { PerformanceTests.send(test, testdata10, optly10) }
|
126
|
+
x.report('25 exps') { PerformanceTests.send(test, testdata25, optly25) }
|
127
|
+
x.report('50 exps') { PerformanceTests.send(test, testdata50, optly50) }
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: optimizely-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Delikat
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-08-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -110,10 +110,10 @@ dependencies:
|
|
110
110
|
- - "~>"
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: 2.6.2
|
113
|
-
description: A Ruby SDK for Optimizely's server-side testing, which is currently
|
114
|
-
private beta.
|
113
|
+
description: A Ruby SDK for Optimizely's server-side testing product, which is currently
|
114
|
+
in private beta.
|
115
115
|
email:
|
116
|
-
-
|
116
|
+
- developers@optimizely.com
|
117
117
|
executables: []
|
118
118
|
extensions: []
|
119
119
|
extra_rdoc_files: []
|
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
154
|
version: '0'
|
155
155
|
requirements: []
|
156
156
|
rubyforge_project:
|
157
|
-
rubygems_version: 2.
|
157
|
+
rubygems_version: 2.4.8
|
158
158
|
signing_key:
|
159
159
|
specification_version: 4
|
160
160
|
summary: Ruby SDK for Optimizely's testing framework
|