Skip to content

Commit 5a295f6

Browse files
authored
Merge pull request #73 from reddit/dc_docs
Add DC docs
2 parents 4a9cff3 + d679e39 commit 5a295f6

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

docs/index.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Upgrade or integrate reddit-experiments package:
5959
.. code-block:: python
6060
6161
# import latest reddit-experiments package in service requirements.txt
62-
reddit-experiments>=1.3.7
62+
reddit-experiments>=1.3.8
6363
6464
Initialize :code:`decider` instance on Baseplate context
6565
--------------------------------------------------------
@@ -117,7 +117,7 @@ Make sure :code:`EdgeContext` is accessible on :code:`request` object like so:
117117
# - locale
118118
# - origin_service
119119
# - is_employee
120-
# - loid_created_ms
120+
# - loid_created_ms (>=1.3.8)
121121
122122
# Customized fields can be defined below to be extracted from a baseplate request
123123
# and will override above edge_context fields.
@@ -144,6 +144,11 @@ or optionally, if manual exposure is necessary, use::
144144
...
145145
request.decider.expose(experiment_name='experiment_name', variant_name=variant)
146146
147+
and this is an example of using a dynamic configuration::
148+
149+
def my_method(request):
150+
if request.decider.get_bool("foo") == True:
151+
...
147152
148153
Decider API
149154
-----------
@@ -171,5 +176,6 @@ Legacy API docs:
171176
----------------
172177
173178
.. toctree::
179+
:maxdepth: 1
174180
175181
legacy/index

reddit_decider/__init__.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,30 +782,75 @@ def _get_dynamic_config_value(
782782
return res.val()
783783

784784
def get_bool(self, feature_name: str, default: bool = False) -> bool:
785+
"""Fetch a Dynamic Configuration of boolean type.
786+
787+
:param feature_name: Name of the dynamic config you want a value for.
788+
789+
:param default: what is returned if dynamic config is not active
790+
(:code:`False` unless overriden).
791+
792+
:return: the boolean value of the dyanimc config if it is active/exists, :code:`default` parameter otherwise.
793+
"""
785794
decider = self._get_decider()
786795
if not decider:
787796
return default
788797
return self._get_dynamic_config_value(feature_name, decider.get_bool, default)
789798

790799
def get_int(self, feature_name: str, default: int = 0) -> int:
800+
"""Fetch a Dynamic Configuration of int type.
801+
802+
:param feature_name: Name of the dynamic config you want a value for.
803+
804+
:param default: what is returned if dynamic config is not active
805+
(:code:`0` unless overriden).
806+
807+
:return: the int value of the dyanimc config if it is active/exists, :code:`default` parameter otherwise.
808+
"""
791809
decider = self._get_decider()
792810
if not decider:
793811
return default
794812
return self._get_dynamic_config_value(feature_name, decider.get_int, default)
795813

796814
def get_float(self, feature_name: str, default: float = 0.0) -> float:
815+
"""Fetch a Dynamic Configuration of float type.
816+
817+
:param feature_name: Name of the dynamic config you want a value for.
818+
819+
:param default: what is returned if dynamic config is not active
820+
(:code:`0.0` unless overriden).
821+
822+
:return: the float value of the dyanimc config if it is active/exists, :code:`default` parameter otherwise.
823+
"""
797824
decider = self._get_decider()
798825
if not decider:
799826
return default
800827
return self._get_dynamic_config_value(feature_name, decider.get_float, default)
801828

802829
def get_string(self, feature_name: str, default: str = "") -> str:
830+
"""Fetch a Dynamic Configuration of string type.
831+
832+
:param feature_name: Name of the dynamic config you want a value for.
833+
834+
:param default: what is returned if dynamic config is not active
835+
(:code:`""` unless overriden).
836+
837+
:return: the string value of the dyanimc config if it is active/exists, :code:`default` parameter otherwise.
838+
"""
803839
decider = self._get_decider()
804840
if not decider:
805841
return default
806842
return self._get_dynamic_config_value(feature_name, decider.get_string, default)
807843

808844
def get_map(self, feature_name: str, default: Optional[dict] = None) -> Optional[dict]:
845+
"""Fetch a Dynamic Configuration of map type.
846+
847+
:param feature_name: Name of the dynamic config you want a value for.
848+
849+
:param default: what is returned if dynamic config is not active
850+
(:code:`None` unless overriden).
851+
852+
:return: the map value of the dyanimc config if it is active/exists, :code:`default` parameter otherwise.
853+
"""
809854
decider = self._get_decider()
810855
if not decider:
811856
return default

0 commit comments

Comments
 (0)