|
31 | 31 | class Optimizely(object):
|
32 | 32 | """ Class encapsulating all SDK functionality. """
|
33 | 33 |
|
34 |
| - def __init__(self, datafile, event_dispatcher=None, logger=None, error_handler=None, skip_json_validation=False): |
| 34 | + def __init__(self, |
| 35 | + datafile, |
| 36 | + event_dispatcher=None, |
| 37 | + logger=None, |
| 38 | + error_handler=None, |
| 39 | + skip_json_validation=False, |
| 40 | + user_profile_service=None): |
35 | 41 | """ Optimizely init method for managing Custom projects.
|
36 | 42 |
|
37 | 43 | Args:
|
38 | 44 | datafile: JSON string representing the project.
|
39 | 45 | event_dispatcher: Provides a dispatch_event method which if given a URL and params sends a request to it.
|
40 |
| - logger: Optional param which provides a log method to log messages. By default nothing would be logged. |
41 |
| - error_handler: Optional param which provides a handle_error method to handle exceptions. |
| 46 | + logger: Optional component which provides a log method to log messages. By default nothing would be logged. |
| 47 | + error_handler: Optional component which provides a handle_error method to handle exceptions. |
42 | 48 | By default all exceptions will be suppressed.
|
43 | 49 | skip_json_validation: Optional boolean param which allows skipping JSON schema validation upon object invocation.
|
44 | 50 | By default JSON schema validation will be performed.
|
| 51 | + user_profile_service: Optional component which provides methods to store and manage user profiles. |
45 | 52 | """
|
46 | 53 |
|
47 | 54 | self.is_valid = True
|
48 | 55 | self.event_dispatcher = event_dispatcher or default_event_dispatcher
|
49 | 56 | self.logger = logger or noop_logger
|
50 | 57 | self.error_handler = error_handler or noop_error_handler
|
| 58 | + self.user_profile_service = user_profile_service |
51 | 59 |
|
52 | 60 | try:
|
53 | 61 | self._validate_instantiation_options(datafile, skip_json_validation)
|
@@ -274,15 +282,17 @@ def get_variation(self, experiment_key, user_id, attributes=None):
|
274 | 282 |
|
275 | 283 | experiment = self.config.get_experiment_from_key(experiment_key)
|
276 | 284 | if not experiment:
|
277 |
| - self.logger.log(enums.LogLevels.INFO, 'Experiment key "%s" is invalid. Not activating user "%s".' % (experiment_key, user_id)) |
| 285 | + self.logger.log(enums.LogLevels.INFO, |
| 286 | + 'Experiment key "%s" is invalid. Not activating user "%s".' % (experiment_key, |
| 287 | + user_id)) |
278 | 288 | return None
|
279 | 289 |
|
280 | 290 | if not self._validate_preconditions(experiment, attributes):
|
281 | 291 | return None
|
282 | 292 |
|
283 |
| - forcedVariation = self.bucketer.get_forced_variation(experiment, user_id) |
284 |
| - if forcedVariation: |
285 |
| - return forcedVariation.key |
| 293 | + forced_variation = self.bucketer.get_forced_variation(experiment, user_id) |
| 294 | + if forced_variation: |
| 295 | + return forced_variation.key |
286 | 296 |
|
287 | 297 | if not audience_helper.is_user_in_experiment(self.config, experiment, attributes):
|
288 | 298 | self.logger.log(
|
|
0 commit comments