Skip to content

Commit

Permalink
Merge 910ef0b into 968a54e
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonhudavid committed Jul 23, 2019
2 parents 968a54e + 910ef0b commit fd1e398
Show file tree
Hide file tree
Showing 2 changed files with 722 additions and 101 deletions.
23 changes: 21 additions & 2 deletions optimizely/optimizely.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ def _get_feature_variable_for_type(self, feature_key, variable_key, variable_typ
if not variable:
return None

# Return None if type differs
if variable.type != variable_type:
# For non-typed method, use type of variable; else, return None if type differs
if not variable_type:
variable_type = variable.type
elif variable.type != variable_type:
self.logger.warning(
'Requested variable type "%s", but variable is of type "%s". '
'Use correct API to retrieve value. Returning None.' % (variable_type, variable.type)
Expand Down Expand Up @@ -513,6 +515,23 @@ def get_enabled_features(self, user_id, attributes=None):

return enabled_features

def get_feature_variable(self, feature_key, variable_key, user_id, attributes=None):
""" Returns value for a variable attached to a feature flag.
Args:
feature_key: Key of the feature whose variable's value is being accessed.
variable_key: Key of the variable whose value is to be accessed.
user_id: ID for user.
attributes: Dict representing user attributes.
Returns:
Value of the variable. None if:
- Feature key is invalid.
- Variable key is invalid.
"""

return self._get_feature_variable_for_type(feature_key, variable_key, None, user_id, attributes)

def get_feature_variable_boolean(self, feature_key, variable_key, user_id, attributes=None):
""" Returns value for a certain boolean variable attached to a feature flag.
Expand Down
Loading

0 comments on commit fd1e398

Please sign in to comment.