Skip to content

Commit e999534

Browse files
authored
Merge pull request #104 from reddit/update_docs_for_no_edge_context_case
Update docs: use `internal_decider()` if w/o `edge_context`
2 parents 635a5b3 + 9e837a3 commit e999534

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

docs/index.rst

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. _reddit_decider:
22

33
``reddit_decider``
4-
===============================
4+
==================
55

66
.. automodule:: reddit_decider
77

@@ -103,6 +103,24 @@ Make sure :code:`EdgeContext` is accessible on :code:`request` object like so:
103103
104104
request.edge_context
105105
106+
If you **don't have access** to :code:`edge_context` in your service/request, you can access the SDK’s internal decider instance for a lower level API,
107+
allowing you to pass in targeting context fields as a :code:`dict` param,
108+
e.g. "user_is_employee", "country_code", or other targeting fields (instead of them being auto-derived from :code:`edge_context`).
109+
110+
See full API in `readme <https://github.snooguts.net/reddit/decider/tree/master/decider-py#class-decider>`_ (reddit internal).
111+
112+
The internal decider instance can be accessed from the SDK's top-level decider instance via:
113+
114+
.. code-block:: python
115+
116+
internal_decider = request.decider.internal_decider() # requires `reddit-experiments >= 1.4.1`
117+
internal_decider.choose("experiment_name", {
118+
"user_id": "t2_abc",
119+
"user_is_employee": True,
120+
"other_info": { "arbitrary_field": "some_val" }
121+
}
122+
)
123+
106124
107125
[Optional] Define request field extractor function (`example <https://github.snooguts.net/reddit/reddit-service-graphql/blob/master/graphql-py/graphql_api/models/experiment.py#L67-L92>`_)
108126

@@ -132,7 +150,7 @@ Make sure :code:`EdgeContext` is accessible on :code:`request` object like so:
132150
133151
Basic Usage
134152
-----------
135-
Use the attached :py:class:`~reddit_decider.Decider` object in request to call
153+
Use the attached :py:class:`~reddit_decider.Decider` instance in request to call
136154
:code:`decider.get_variant()` (automatically sends an expose event)::
137155

138156
def my_method(request):
@@ -146,12 +164,13 @@ or optionally, if manual exposure is necessary, use::
146164
...
147165
request.decider.expose(experiment_name='experiment_name', variant_name=variant)
148166

149-
and this is an example of using a dynamic configuration::
167+
This is an example of using a dynamic configuration::
150168

151169
def my_method(request):
152170
if request.decider.get_bool("foo") == True:
153171
...
154172

173+
155174
Decider API
156175
-----------
157176

0 commit comments

Comments
 (0)