optimizely-sdk 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50614c45e6266670a008909d27b7baf89d443500
4
- data.tar.gz: 89c89c31817a26ef93d516d19f406c12be5617f2
3
+ metadata.gz: 0fde3ad17097c2d63569bade1f3e4095bd8b8d36
4
+ data.tar.gz: ac971b0cff7db95a591b742a19cc9e9b82e6016d
5
5
  SHA512:
6
- metadata.gz: 8e443c5554673b3c209d3a8d85135d843db8e417df827a14d414f954f5eb3bbd70804163d948f48beb1174e909427761fd8e19acf77e2c7d7879fbe2dfcca013
7
- data.tar.gz: 52e4ec4502499c9a831590ec0557fd418e09e0b89d2c1f11b786d6685cf8533cdf9820937bfa66778f627f8612ab2a45ac1044be79827c83b49ff4efcc942fcf
6
+ metadata.gz: d6cfdff4bef0344791fea78458ef57d7aa81e7de2fdaf3eb843e8ae6196f72766f0257bdef37a00feeae802390fd6016e8db96e2b90d5484fbd0d2317a94bdb4
7
+ data.tar.gz: f721214b5c3e6a71fb1ef21609d5180e232720ad201fca0c31b2baf62c925a76aea13c4c75ea9bdb312f2bb1ec555f93b6067e31fe931df4843b95db230c6655
@@ -31,28 +31,22 @@ require_relative 'optimizely/project_config'
31
31
 
32
32
  module Optimizely
33
33
  class Project
34
- # Boolean representing if the instance represents a usable Optimizely Project
35
- attr_reader :is_valid
36
-
37
- attr_reader :config
38
- attr_reader :decision_service
39
- attr_reader :error_handler
40
- attr_reader :event_builder
41
- attr_reader :event_dispatcher
42
- attr_reader :logger
43
34
  attr_reader :notification_center
35
+ # @api no-doc
36
+ attr_reader :is_valid, :config, :decision_service, :error_handler,
37
+ :event_builder, :event_dispatcher, :logger
38
+
39
+ # Constructor for Projects.
40
+ #
41
+ # @param datafile - JSON string representing the project.
42
+ # @param event_dispatcher - Provides a dispatch_event method which if given a URL and params sends a request to it.
43
+ # @param logger - Optional component which provides a log method to log messages. By default nothing would be logged.
44
+ # @param error_handler - Optional component which provides a handle_error method to handle exceptions.
45
+ # By default all exceptions will be suppressed.
46
+ # @param user_profile_service - Optional component which provides methods to store and retreive user profiles.
47
+ # @param skip_json_validation - Optional boolean param to skip JSON schema validation of the provided datafile.
44
48
 
45
49
  def initialize(datafile, event_dispatcher = nil, logger = nil, error_handler = nil, skip_json_validation = false, user_profile_service = nil)
46
- # Constructor for Projects.
47
- #
48
- # datafile - JSON string representing the project.
49
- # event_dispatcher - Provides a dispatch_event method which if given a URL and params sends a request to it.
50
- # logger - Optional component which provides a log method to log messages. By default nothing would be logged.
51
- # error_handler - Optional component which provides a handle_error method to handle exceptions.
52
- # By default all exceptions will be suppressed.
53
- # user_profile_service - Optional component which provides methods to store and retreive user profiles.
54
- # skip_json_validation - Optional boolean param to skip JSON schema validation of the provided datafile.
55
-
56
50
  @is_valid = true
57
51
  @logger = logger || NoOpLogger.new
58
52
  @error_handler = error_handler || NoOpErrorHandler.new
@@ -70,35 +64,31 @@ module Optimizely
70
64
 
71
65
  begin
72
66
  @config = ProjectConfig.new(datafile, @logger, @error_handler)
73
- rescue
67
+ rescue StandardError => e
74
68
  @is_valid = false
75
69
  @logger = SimpleLogger.new
76
- @logger.log(Logger::ERROR, InvalidInputError.new('datafile').message)
77
- return
78
- end
79
-
80
- unless @config.parsing_succeeded?
81
- @is_valid = false
82
- @logger = SimpleLogger.new
83
- @logger.log(Logger::ERROR, InvalidDatafileVersionError.new.message)
70
+ error_msg = e.class == InvalidDatafileVersionError ? e.message : InvalidInputError.new('datafile').message
71
+ error_to_handle = e.class == InvalidDatafileVersionError ? InvalidDatafileVersionError : InvalidInputError
72
+ @logger.log(Logger::ERROR, error_msg)
73
+ @error_handler.handle_error error_to_handle
84
74
  return
85
75
  end
86
76
 
87
77
  @decision_service = DecisionService.new(@config, @user_profile_service)
88
- @event_builder = EventBuilder.new(@config, logger)
78
+ @event_builder = EventBuilder.new(@config, @logger)
89
79
  @notification_center = NotificationCenter.new(@logger, @error_handler)
90
80
  end
91
81
 
92
- def activate(experiment_key, user_id, attributes = nil)
93
- # Buckets visitor and sends impression event to Optimizely.
94
- #
95
- # experiment_key - Experiment which needs to be activated.
96
- # user_id - String ID for user.
97
- # attributes - Hash representing user attributes and values to be recorded.
98
- #
99
- # Returns variation key representing the variation the user will be bucketed in.
100
- # Returns nil if experiment is not Running, if user is not in experiment, or if datafile is invalid.
82
+ # Buckets visitor and sends impression event to Optimizely.
83
+ #
84
+ # @param experiment_key - Experiment which needs to be activated.
85
+ # @param user_id - String ID for user.
86
+ # @param attributes - Hash representing user attributes and values to be recorded.
87
+ #
88
+ # @return [Variation Key] representing the variation the user will be bucketed in.
89
+ # @return [nil] if experiment is not Running, if user is not in experiment, or if datafile is invalid.
101
90
 
91
+ def activate(experiment_key, user_id, attributes = nil)
102
92
  unless @is_valid
103
93
  @logger.log(Logger::ERROR, InvalidDatafileError.new('activate').message)
104
94
  return nil
@@ -125,16 +115,16 @@ module Optimizely
125
115
  variation_key
126
116
  end
127
117
 
128
- def get_variation(experiment_key, user_id, attributes = nil)
129
- # Gets variation where visitor will be bucketed.
130
- #
131
- # experiment_key - Experiment for which visitor variation needs to be determined.
132
- # user_id - String ID for user.
133
- # attributes - Hash representing user attributes.
134
- #
135
- # Returns variation key where visitor will be bucketed.
136
- # Returns nil if experiment is not Running, if user is not in experiment, or if datafile is invalid.
118
+ # Gets variation where visitor will be bucketed.
119
+ #
120
+ # @param experiment_key - Experiment for which visitor variation needs to be determined.
121
+ # @param user_id - String ID for user.
122
+ # @param attributes - Hash representing user attributes.
123
+ #
124
+ # @return [variation key] where visitor will be bucketed.
125
+ # @return [nil] if experiment is not Running, if user is not in experiment, or if datafile is invalid.
137
126
 
127
+ def get_variation(experiment_key, user_id, attributes = nil)
138
128
  unless @is_valid
139
129
  @logger.log(Logger::ERROR, InvalidDatafileError.new('get_variation').message)
140
130
  return nil
@@ -161,27 +151,27 @@ module Optimizely
161
151
  nil
162
152
  end
163
153
 
164
- def set_forced_variation(experiment_key, user_id, variation_key)
165
- # Force a user into a variation for a given experiment.
166
- #
167
- # experiment_key - String - key identifying the experiment.
168
- # user_id - String - The user ID to be used for bucketing.
169
- # variation_key - The variation key specifies the variation which the user will
170
- # be forced into. If nil, then clear the existing experiment-to-variation mapping.
171
- #
172
- # Returns - Boolean - indicates if the set completed successfully.
154
+ # Force a user into a variation for a given experiment.
155
+ #
156
+ # @param experiment_key - String - key identifying the experiment.
157
+ # @param user_id - String - The user ID to be used for bucketing.
158
+ # @param variation_key - The variation key specifies the variation which the user will
159
+ # be forced into. If nil, then clear the existing experiment-to-variation mapping.
160
+ #
161
+ # @return [Boolean] indicates if the set completed successfully.
173
162
 
163
+ def set_forced_variation(experiment_key, user_id, variation_key)
174
164
  @config.set_forced_variation(experiment_key, user_id, variation_key)
175
165
  end
176
166
 
177
- def get_forced_variation(experiment_key, user_id)
178
- # Gets the forced variation for a given user and experiment.
179
- #
180
- # experiment_key - String - Key identifying the experiment.
181
- # user_id - String - The user ID to be used for bucketing.
182
- #
183
- # Returns String|nil The forced variation key.
167
+ # Gets the forced variation for a given user and experiment.
168
+ #
169
+ # @param experiment_key - String - Key identifying the experiment.
170
+ # @param user_id - String - The user ID to be used for bucketing.
171
+ #
172
+ # @return [String] The forced variation key.
184
173
 
174
+ def get_forced_variation(experiment_key, user_id)
185
175
  forced_variation_key = nil
186
176
  forced_variation = @config.get_forced_variation(experiment_key, user_id)
187
177
  forced_variation_key = forced_variation['key'] if forced_variation
@@ -189,14 +179,14 @@ module Optimizely
189
179
  forced_variation_key
190
180
  end
191
181
 
192
- def track(event_key, user_id, attributes = nil, event_tags = nil)
193
- # Send conversion event to Optimizely.
194
- #
195
- # event_key - Event key representing the event which needs to be recorded.
196
- # user_id - String ID for user.
197
- # attributes - Hash representing visitor attributes and values which need to be recorded.
198
- # event_tags - Hash representing metadata associated with the event.
182
+ # Send conversion event to Optimizely.
183
+ #
184
+ # @param event_key - Event key representing the event which needs to be recorded.
185
+ # @param user_id - String ID for user.
186
+ # @param attributes - Hash representing visitor attributes and values which need to be recorded.
187
+ # @param event_tags - Hash representing metadata associated with the event.
199
188
 
189
+ def track(event_key, user_id, attributes = nil, event_tags = nil)
200
190
  unless @is_valid
201
191
  @logger.log(Logger::ERROR, InvalidDatafileError.new('track').message)
202
192
  return nil
@@ -244,17 +234,18 @@ module Optimizely
244
234
  nil
245
235
  end
246
236
 
237
+ # Determine whether a feature is enabled.
238
+ # Sends an impression event if the user is bucketed into an experiment using the feature.
239
+ #
240
+ # @param feature_flag_key - String unique key of the feature.
241
+ # @param user_id - String ID of the user.
242
+ # @param attributes - Hash representing visitor attributes and values which need to be recorded.
243
+ #
244
+ # @return [True] if the feature is enabled.
245
+ # @return [False] if the feature is disabled.
246
+ # @return [False] if the feature is not found.
247
+
247
248
  def is_feature_enabled(feature_flag_key, user_id, attributes = nil)
248
- # Determine whether a feature is enabled.
249
- # Sends an impression event if the user is bucketed into an experiment using the feature.
250
- #
251
- # feature_flag_key - String unique key of the feature.
252
- # userId - String ID of the user.
253
- # attributes - Hash representing visitor attributes and values which need to be recorded.
254
- #
255
- # Returns True if the feature is enabled.
256
- # False if the feature is disabled.
257
- # False if the feature is not found.
258
249
  unless @is_valid
259
250
  @logger.log(Logger::ERROR, InvalidDatafileError.new('is_feature_enabled').message)
260
251
  return false
@@ -300,14 +291,13 @@ module Optimizely
300
291
  end
301
292
  end
302
293
 
294
+ # Gets keys of all feature flags which are enabled for the user.
295
+ #
296
+ # @param user_id - ID for user.
297
+ # @param attributes - Dict representing user attributes.
298
+ # @return [feature flag keys] A List of feature flag keys that are enabled for the user.
299
+
303
300
  def get_enabled_features(user_id, attributes = nil)
304
- # Gets keys of all feature flags which are enabled for the user.
305
- # Args:
306
- # user_id: ID for user.
307
- # attributes: Dict representing user attributes.
308
- # Returns:
309
- # A List of feature flag keys that are enabled for the user.
310
- #
311
301
  enabled_features = []
312
302
 
313
303
  unless @is_valid
@@ -327,17 +317,17 @@ module Optimizely
327
317
  enabled_features
328
318
  end
329
319
 
330
- def get_feature_variable_string(feature_flag_key, variable_key, user_id, attributes = nil)
331
- # Get the String value of the specified variable in the feature flag.
332
- #
333
- # feature_flag_key - String key of feature flag the variable belongs to
334
- # variable_key - String key of variable for which we are getting the string value
335
- # user_id - String user ID
336
- # attributes - Hash representing visitor attributes and values which need to be recorded.
337
- #
338
- # Returns the string variable value.
339
- # Returns nil if the feature flag or variable are not found.
320
+ # Get the String value of the specified variable in the feature flag.
321
+ #
322
+ # @param feature_flag_key - String key of feature flag the variable belongs to
323
+ # @param variable_key - String key of variable for which we are getting the string value
324
+ # @param user_id - String user ID
325
+ # @param attributes - Hash representing visitor attributes and values which need to be recorded.
326
+ #
327
+ # @return [String] the string variable value.
328
+ # @return [nil] if the feature flag or variable are not found.
340
329
 
330
+ def get_feature_variable_string(feature_flag_key, variable_key, user_id, attributes = nil)
341
331
  unless @is_valid
342
332
  @logger.log(Logger::ERROR, InvalidDatafileError.new('get_feature_variable_string').message)
343
333
  return nil
@@ -354,17 +344,17 @@ module Optimizely
354
344
  variable_value
355
345
  end
356
346
 
357
- def get_feature_variable_boolean(feature_flag_key, variable_key, user_id, attributes = nil)
358
- # Get the Boolean value of the specified variable in the feature flag.
359
- #
360
- # feature_flag_key - String key of feature flag the variable belongs to
361
- # variable_key - String key of variable for which we are getting the string value
362
- # user_id - String user ID
363
- # attributes - Hash representing visitor attributes and values which need to be recorded.
364
- #
365
- # Returns the boolean variable value.
366
- # Returns nil if the feature flag or variable are not found.
347
+ # Get the Boolean value of the specified variable in the feature flag.
348
+ #
349
+ # @param feature_flag_key - String key of feature flag the variable belongs to
350
+ # @param variable_key - String key of variable for which we are getting the string value
351
+ # @param user_id - String user ID
352
+ # @param attributes - Hash representing visitor attributes and values which need to be recorded.
353
+ #
354
+ # @return [Boolean] the boolean variable value.
355
+ # @return [nil] if the feature flag or variable are not found.
367
356
 
357
+ def get_feature_variable_boolean(feature_flag_key, variable_key, user_id, attributes = nil)
368
358
  unless @is_valid
369
359
  @logger.log(Logger::ERROR, InvalidDatafileError.new('get_feature_variable_boolean').message)
370
360
  return nil
@@ -381,17 +371,17 @@ module Optimizely
381
371
  variable_value
382
372
  end
383
373
 
384
- def get_feature_variable_double(feature_flag_key, variable_key, user_id, attributes = nil)
385
- # Get the Double value of the specified variable in the feature flag.
386
- #
387
- # feature_flag_key - String key of feature flag the variable belongs to
388
- # variable_key - String key of variable for which we are getting the string value
389
- # user_id - String user ID
390
- # attributes - Hash representing visitor attributes and values which need to be recorded.
391
- #
392
- # Returns the double variable value.
393
- # Returns nil if the feature flag or variable are not found.
374
+ # Get the Double value of the specified variable in the feature flag.
375
+ #
376
+ # @param feature_flag_key - String key of feature flag the variable belongs to
377
+ # @param variable_key - String key of variable for which we are getting the string value
378
+ # @param user_id - String user ID
379
+ # @param attributes - Hash representing visitor attributes and values which need to be recorded.
380
+ #
381
+ # @return [Boolean] the double variable value.
382
+ # @return [nil] if the feature flag or variable are not found.
394
383
 
384
+ def get_feature_variable_double(feature_flag_key, variable_key, user_id, attributes = nil)
395
385
  unless @is_valid
396
386
  @logger.log(Logger::ERROR, InvalidDatafileError.new('get_feature_variable_double').message)
397
387
  return nil
@@ -408,22 +398,21 @@ module Optimizely
408
398
  variable_value
409
399
  end
410
400
 
411
- def get_feature_variable_integer(feature_flag_key, variable_key, user_id, attributes = nil)
412
- # Get the Integer value of the specified variable in the feature flag.
413
- #
414
- # feature_flag_key - String key of feature flag the variable belongs to
415
- # variable_key - String key of variable for which we are getting the string value
416
- # user_id - String user ID
417
- # attributes - Hash representing visitor attributes and values which need to be recorded.
418
- #
419
- # Returns the integer variable value.
420
- # Returns nil if the feature flag or variable are not found.
401
+ # Get the Integer value of the specified variable in the feature flag.
402
+ #
403
+ # @param feature_flag_key - String key of feature flag the variable belongs to
404
+ # @param variable_key - String key of variable for which we are getting the string value
405
+ # @param user_id - String user ID
406
+ # @param attributes - Hash representing visitor attributes and values which need to be recorded.
407
+ #
408
+ # @return [Integer] variable value.
409
+ # @return [nil] if the feature flag or variable are not found.
421
410
 
411
+ def get_feature_variable_integer(feature_flag_key, variable_key, user_id, attributes = nil)
422
412
  unless @is_valid
423
413
  @logger.log(Logger::ERROR, InvalidDatafileError.new('get_feature_variable_integer').message)
424
414
  return nil
425
415
  end
426
-
427
416
  variable_value = get_feature_variable_for_type(
428
417
  feature_flag_key,
429
418
  variable_key,
@@ -153,7 +153,7 @@ module Optimizely
153
153
 
154
154
  event_params = get_common_params(user_id, attributes)
155
155
  conversion_params = get_conversion_params(event_key, event_tags, experiment_variation_map)
156
- event_params[:visitors][0][:snapshots] = conversion_params
156
+ event_params[:visitors][0][:snapshots] = [conversion_params]
157
157
 
158
158
  Event.new(:post, ENDPOINT, event_params, POST_HEADERS)
159
159
  end
@@ -195,43 +195,38 @@ module Optimizely
195
195
  # event_tags - +Hash+ Values associated with the event.
196
196
  # experiment_variation_map - +Hash+ Map of experiment IDs to bucketed variation IDs
197
197
  #
198
- # Returns +Hash+ Impression event params
199
-
200
- conversion_event_params = []
198
+ # Returns +Hash+ Conversion event params
201
199
 
200
+ single_snapshot = {}
201
+ single_snapshot[:decisions] = []
202
202
  experiment_variation_map.each do |experiment_id, variation_id|
203
- single_snapshot = {
204
- decisions: [{
205
- campaign_id: @config.experiment_id_map[experiment_id]['layerId'],
206
- experiment_id: experiment_id,
207
- variation_id: variation_id
208
- }],
209
- events: []
210
- }
211
-
212
- event_object = {
213
- entity_id: @config.event_key_map[event_key]['id'],
214
- timestamp: create_timestamp,
215
- uuid: create_uuid,
216
- key: event_key
217
- }
218
-
219
- if event_tags
220
- revenue_value = Helpers::EventTagUtils.get_revenue_value(event_tags, @logger)
221
- event_object[:revenue] = revenue_value if revenue_value
203
+ next unless variation_id
204
+ single_snapshot[:decisions].push(
205
+ campaign_id: @config.experiment_id_map[experiment_id]['layerId'],
206
+ experiment_id: experiment_id,
207
+ variation_id: variation_id
208
+ )
209
+ end
222
210
 
223
- numeric_value = Helpers::EventTagUtils.get_numeric_value(event_tags, @logger)
224
- event_object[:value] = numeric_value if numeric_value
211
+ event_object = {
212
+ entity_id: @config.event_key_map[event_key]['id'],
213
+ timestamp: create_timestamp,
214
+ uuid: create_uuid,
215
+ key: event_key
216
+ }
225
217
 
226
- event_object[:tags] = event_tags
227
- end
218
+ if event_tags
219
+ revenue_value = Helpers::EventTagUtils.get_revenue_value(event_tags, @logger)
220
+ event_object[:revenue] = revenue_value if revenue_value
228
221
 
229
- single_snapshot[:events] = [event_object]
222
+ numeric_value = Helpers::EventTagUtils.get_numeric_value(event_tags, @logger)
223
+ event_object[:value] = numeric_value if numeric_value
230
224
 
231
- conversion_event_params.push(single_snapshot)
225
+ event_object[:tags] = event_tags unless event_tags.empty?
232
226
  end
233
227
 
234
- conversion_event_params
228
+ single_snapshot[:events] = [event_object]
229
+ single_snapshot
235
230
  end
236
231
 
237
232
  def create_timestamp
@@ -25,13 +25,13 @@ module Optimizely
25
25
  end
26
26
 
27
27
  class EventDispatcher
28
+ # @api constants
28
29
  REQUEST_TIMEOUT = 10
29
30
 
31
+ # Dispatch the event being represented by the Event object.
32
+ #
33
+ # @param event - Event object
30
34
  def dispatch_event(event)
31
- # Dispatch the event being represented by the Event object.
32
- #
33
- # event - Event object
34
-
35
35
  if event.http_verb == :get
36
36
  begin
37
37
  HTTParty.get(event.url, headers: event.headers, query: event.params, timeout: REQUEST_TIMEOUT)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Copyright 2016-2017, Optimizely and contributors
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.
@@ -85,9 +85,8 @@ module Optimizely
85
85
  class InvalidDatafileVersionError < Error
86
86
  # Raised when a datafile with an unsupported version is provided
87
87
 
88
- def initialize(msg = 'Provided datafile is an unsupported version. Please use SDK version 1.1.2 or earlier '\
89
- 'for datafile version 1.')
90
- super
88
+ def initialize(version)
89
+ super("This version of the Ruby SDK does not support the given datafile version: #{version}.")
91
90
  end
92
91
  end
93
92
 
@@ -321,6 +321,12 @@ module Optimizely
321
321
  'BUCKETING_ID' => '$opt_bucketing_id',
322
322
  'USER_AGENT' => '$opt_user_agent'
323
323
  }.freeze
324
+
325
+ SUPPORTED_VERSIONS = {
326
+ 'v2' => '2',
327
+ 'v3' => '3',
328
+ 'v4' => '4'
329
+ }.freeze
324
330
  end
325
331
  end
326
332
  end
@@ -17,8 +17,8 @@
17
17
  #
18
18
  module Optimizely
19
19
  class NotificationCenter
20
- attr_reader :notifications
21
- attr_reader :notification_id
20
+ # @api no-doc
21
+ attr_reader :notifications, :notification_id
22
22
 
23
23
  NOTIFICATION_TYPES = {
24
24
  ACTIVATE: 'ACTIVATE: experiment, user_id, attributes, variation, event',
@@ -33,18 +33,15 @@ module Optimizely
33
33
  @error_handler = error_handler
34
34
  end
35
35
 
36
- def add_notification_listener(notification_type, notification_callback)
37
- # Adds notification callback to the notification center
38
-
39
- # Args:
40
- # notification_type: one of the constants in NOTIFICATION_TYPES
41
- # notification_callback: function to call when the event is sent
42
-
43
- # Returns:
44
- # notification ID used to remove the notification
36
+ # Adds notification callback to the notification center
37
+ #
38
+ # @param notification_type - One of the constants in NOTIFICATION_TYPES
39
+ # @param notification_callback - Function to call when the event is sent
40
+ #
41
+ # @return [notification ID] Used to remove the notification
45
42
 
43
+ def add_notification_listener(notification_type, notification_callback)
46
44
  return nil unless notification_type_valid?(notification_type)
47
-
48
45
  unless notification_callback
49
46
  @logger.log Logger::ERROR, 'Callback can not be empty.'
50
47
  return nil
@@ -64,13 +61,13 @@ module Optimizely
64
61
  notification_id
65
62
  end
66
63
 
67
- def remove_notification_listener(notification_id)
68
- # Removes previously added notification callback
64
+ # Removes previously added notification callback
65
+ #
66
+ # @param notification_id
67
+ #
68
+ # @return [Boolean] The function returns true if found and removed, false otherwise
69
69
 
70
- # Args:
71
- # notification_id:
72
- # Returns:
73
- # The function returns true if found and removed, false otherwise
70
+ def remove_notification_listener(notification_id)
74
71
  unless notification_id
75
72
  @logger.log Logger::ERROR, 'Notification ID can not be empty.'
76
73
  return nil
@@ -114,13 +111,14 @@ module Optimizely
114
111
  @notifications.each_key { |key| @notifications[key] = [] }
115
112
  end
116
113
 
114
+ # Sends off the notification for the specific event. Uses var args to pass in a
115
+ # arbitrary list of parameters according to which notification type was sent
116
+ #
117
+ # @param notification_type - one of the constants in NOTIFICATION_TYPES
118
+ # @param args - list of arguments to the callback
119
+ #
120
+ # @api no-doc
117
121
  def send_notifications(notification_type, *args)
118
- # Sends off the notification for the specific event. Uses var args to pass in a
119
- # arbitrary list of parameters according to which notification type was sent
120
-
121
- # Args:
122
- # notification_type: one of the constants in NOTIFICATION_TYPES
123
- # args: list of arguments to the callback
124
122
  return nil unless notification_type_valid?(notification_type)
125
123
 
126
124
  @notifications[notification_type].each do |notification|
@@ -19,10 +19,6 @@ require_relative 'helpers/constants'
19
19
  require_relative 'helpers/validator'
20
20
 
21
21
  module Optimizely
22
- V1_CONFIG_VERSION = '1'
23
-
24
- UNSUPPORTED_VERSIONS = [V1_CONFIG_VERSION].freeze
25
-
26
22
  class ProjectConfig
27
23
  # Representation of the Optimizely project config.
28
24
  RUNNING_EXPERIMENT_STATUS = ['Running'].freeze
@@ -39,7 +35,6 @@ module Optimizely
39
35
  attr_reader :experiments
40
36
  attr_reader :feature_flags
41
37
  attr_reader :groups
42
- attr_reader :parsing_succeeded
43
38
  attr_reader :project_id
44
39
  # Boolean - denotes if Optimizely should remove the last block of visitors' IP address before storing event data
45
40
  attr_reader :anonymize_ip
@@ -75,12 +70,11 @@ module Optimizely
75
70
 
76
71
  config = JSON.parse(datafile)
77
72
 
78
- @parsing_succeeded = false
79
73
  @error_handler = error_handler
80
74
  @logger = logger
81
75
  @version = config['version']
82
76
 
83
- return if UNSUPPORTED_VERSIONS.include?(@version)
77
+ raise InvalidDatafileVersionError, @version unless Helpers::Constants::SUPPORTED_VERSIONS.value?(@version)
84
78
 
85
79
  @account_id = config['accountId']
86
80
  @attributes = config.fetch('attributes', [])
@@ -147,7 +141,6 @@ module Optimizely
147
141
  @feature_flag_key_map.each do |key, feature_flag|
148
142
  @feature_variable_key_map[key] = generate_key_map(feature_flag['variables'], 'key')
149
143
  end
150
- @parsing_succeeded = true
151
144
  end
152
145
 
153
146
  def experiment_running?(experiment)
@@ -389,14 +382,6 @@ module Optimizely
389
382
  nil
390
383
  end
391
384
 
392
- def parsing_succeeded?
393
- # Helper method to determine if parsing the datafile was successful.
394
- #
395
- # Returns Boolean depending on whether parsing the datafile succeeded or not.
396
-
397
- @parsing_succeeded
398
- end
399
-
400
385
  def variation_id_exists?(experiment_id, variation_id)
401
386
  # Determines if a given experiment ID / variation ID pair exists in the datafile
402
387
  #
@@ -21,18 +21,15 @@ module Optimizely
21
21
  # Class encapsulating user profile service functionality.
22
22
  # Override with your own implementation for storing and retrieving user profiles.
23
23
 
24
- def lookup(user_id)
25
- # Retrieve the Hash user profile associated with a given user ID.
26
- #
27
- # user_id - String user ID
28
- #
29
- # Returns Hash user profile.
30
- end
24
+ # Retrieve the Hash user profile associated with a given user ID.
25
+ #
26
+ # @param user_id - String user ID
27
+ # @return [Hash] user profile.
28
+ def lookup(user_id); end
31
29
 
32
- def save(user_profile)
33
- # Saves a given user profile.
34
- #
35
- # user_profile - Hash user profile.
36
- end
30
+ # Saves a given user profile.
31
+ #
32
+ # @param user_profile - Hash user profile.
33
+ def save(user_profile); end
37
34
  end
38
35
  end
@@ -17,5 +17,5 @@
17
17
  #
18
18
  module Optimizely
19
19
  CLIENT_ENGINE = 'ruby-sdk'
20
- VERSION = '2.1.0'
20
+ VERSION = '2.1.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.1.0
4
+ version: 2.1.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-07-02 00:00:00.000000000 Z
11
+ date: 2018-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,42 +30,42 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '12.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '12.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.4.0
47
+ version: 3.8.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.4.0
54
+ version: 3.8.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.51.0
61
+ version: 0.58.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.51.0
68
+ version: 0.58.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: httparty
71
71
  requirement: !ruby/object:Gem::Requirement