Skip to content

Commit 73f19d5

Browse files
committed
docs(http): add usage info to Authentication classes.
This does not include a basic usage for BearerAuthentication, as that needs more setup.
1 parent ca942b6 commit 73f19d5

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

nextcore/http/authentication/base.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ class BaseAuthentication(ABC):
3636
.. warning::
3737
This is a base class. You should probably use :class:`BotAuthentication` or :class:`BearerAuthentication` instead.
3838
39+
**Example implementation**
40+
41+
.. this is relative to the docs directory
42+
.. literalinclude:: ../nextcore/http/authentication/bot.py
43+
:language: python3
44+
:lines: 34-
45+
3946
Attributes
4047
----------
4148
prefix:
@@ -52,6 +59,12 @@ def rate_limit_key(self) -> str | None:
5259
"""The key used for rate limiting
5360
5461
This is usually the prefix + token for for example ``Bot AABBCC.DDEEFF.GGHHII``
62+
63+
**Example usage**
64+
65+
.. code-block:: python3
66+
67+
await http_client.request(route, rate_limit_key=authentication.rate_limit_key, ...)
5568
"""
5669
...
5770

@@ -61,5 +74,12 @@ def headers(self) -> dict[str, str]:
6174
"""Headers used for making a authenticated request.
6275
6376
This may return a empty dict if headers is not used for authenticating this type of authentication.
77+
78+
**Example usage**
79+
80+
.. code-block:: python3
81+
82+
await http_client.request(route, rate_limit_key=authentication.rate_limit_key, headers=authentication.headers, ...)
83+
6484
"""
6585
...

nextcore/http/authentication/bearer.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ def rate_limit_key(self) -> str:
5858
"""The key used for rate limiting
5959
6060
This will be in the format ``Bearer AABBCCDDEEFFGGHHII``
61+
62+
**Example usage**
63+
64+
.. code-block:: python3
65+
66+
await http_client.request(route, rate_limit_key=authentication.rate_limit_key, headers=authentication.headers, ...)
6167
"""
6268
return f"{self.prefix} {self.token}"
6369

@@ -66,5 +72,11 @@ def headers(self) -> dict[str, str]:
6672
"""Headers for doing a authenticated request.
6773
6874
This will return a dict with a ``Authorization`` field.
75+
76+
**Example usage**
77+
78+
.. code-block:: python3
79+
80+
await http_client.request(route, rate_limit_key=authentication.rate_limit_key, headers=authentication.headers, ...)
6981
"""
7082
return {"Authorization": f"{self.prefix} {self.token}"}

nextcore/http/authentication/bot.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@
3434
class BotAuthentication(BaseAuthentication):
3535
"""A wrapper around bot token authentication.
3636
37+
**Example usage**
38+
39+
.. code-block:: python3
40+
41+
authentication = BotAuthentication(os.environ["TOKEN"])
42+
43+
route = Route("GET", "/gateway/bot")
44+
await http_client.request(route, rate_limit_key=authentication.rate_limit_key, headers=authentication.headers)
45+
3746
Parameters
3847
----------
3948
token:
@@ -58,6 +67,12 @@ def rate_limit_key(self) -> str:
5867
"""The key used for rate limiting
5968
6069
This will be in the format ``Bot AABBCC.DDEEFF.GGHHII``
70+
71+
**Example usage**
72+
73+
.. code-block:: python3
74+
75+
await http_client.request(route, rate_limit_key=authentication.rate_limit_key, headers=authentication.headers, ...)
6176
"""
6277
return f"{self.prefix} {self.token}"
6378

@@ -66,6 +81,12 @@ def headers(self) -> dict[str, str]:
6681
"""Headers for doing a authenticated request.
6782
6883
This will return a dict with a ``Authorization`` field.
84+
85+
**Example usage**
86+
87+
.. code-block:: python3
88+
89+
await http_client.request(route, rate_limit_key=authentication.rate_limit_key, headers=authentication.headers, ...)
6990
"""
7091

7192
return {"Authorization": f"{self.prefix} {self.token}"}

0 commit comments

Comments
 (0)