Skip to content

Commit da419bc

Browse files
committed
Clarify and update some more documentation.
1 parent 7ea0e94 commit da419bc

File tree

5 files changed

+53
-43
lines changed

5 files changed

+53
-43
lines changed

README.rst

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ Two API clients are available from this library:
1818

1919
Aside from one being sync and the other async, the two clients expose
2020
identical APIs, and implement all methods of `the Akismet web API
21-
<https://akismet.com/developers/>`_, including the v1.2 key and API
22-
usage metrics.
21+
<https://akismet.com/developers/>`_.
2322

2423
To use this library, you will need to obtain an Akismet API key and
2524
register a site for use with the Akismet web service; you can do this
@@ -29,6 +28,9 @@ variables ``PYTHON_AKISMET_API_KEY`` and ``PYTHON_AKISMET_BLOG_URL``,
2928
and they will be automatically detected and used.
3029

3130
You can then construct a client instance and call its methods. For
31+
creating a long-lived API client instance, it's recommended that you
32+
use the ``validated_client()`` constructor method, which will
33+
automatically validate your API key with the Akismet web service. For
3234
example, to check a submitted forum post for spam:
3335

3436
.. code-block:: python
@@ -61,19 +63,9 @@ Or using the asynchronous client:
6163
):
6264
# This piece of content was classified as spam; handle it appropriately.
6365
64-
Note that in both cases the client instance is created via the
65-
alternate constructor ``validated_client()``. This is recommended
66-
instead of using the default constructor (i.e., directly calling
67-
``akismet.SyncClient()`` or ``akismet.AsyncClient()``); the
68-
``validated_client()`` constructor will perform automatic discovery of
69-
the environment-variable configuration and validate the configuration
70-
with the Akismet web service before returning the client, while
71-
directly constructing an instance will not (so if you do directly
72-
construct an instance, you must manually provide and validate its
73-
configuration).
74-
75-
You can also use either client class as a context manager. This also
76-
will validate the configuration for you prior to returning the client:
66+
You can also use either client class as a context manager. This does
67+
*not* require the ``validated_client()`` constructor, because your API
68+
key is validated on entering the ``with`` block.
7769

7870
.. code-block:: python
7971

docs/usage.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ API client creation and basic use
4141
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4242

4343
To create an Akismet API client, call the ``validated_client()`` constructor
44-
method; this will automatically read your Akismet API key and site URL from the
45-
environment variables, and validate them with Akismet (see :ref:`the FAQ
46-
<alt-constructor>` for an explanation of why this is done through an alternate
47-
constructor). If they're not valid, or if they're not found in the environment
48-
variables mentioned above, you'll get an :exc:`akismet.ConfigurationError`
49-
exception.
44+
method of the appropriate client class; this will automatically read your
45+
Akismet API key and site URL from the environment variables, and validate them
46+
with Akismet (see :ref:`the FAQ <alt-constructor>` for an explanation of why
47+
this is done through an alternate constructor). If they're not valid, or if
48+
they're not found in the environment variables mentioned above, you'll get an
49+
:exc:`akismet.ConfigurationError` exception.
5050

5151
.. tab:: Sync
5252

@@ -65,9 +65,9 @@ exception.
6565
akismet_client = await akismet.AsyncClient.validated_client()
6666
6767
68-
If you're not able to, or don't want to, set the environment variables, you can
69-
create a :class:`~akismet.Config` instance and use that to manually configure
70-
your Akismet API client:
68+
If don't want to or can't set the environment variables you can use a
69+
:class:`~akismet.Config` instance and use that to manually configure your
70+
Akismet API client:
7171

7272
.. tab:: Sync
7373

@@ -103,8 +103,8 @@ following arguments:
103103
you can also pass other values depending on the type of user-submitted
104104
content you're dealing with.
105105

106-
* ``comment_author`` and/or ``comment_email`` -- The identifier (such as a
107-
username) and/or the email address of the user who submitted the content.
106+
* ``comment_author`` and/or ``comment_author_email`` -- The identifier (such as
107+
a username) and/or the email address of the user who submitted the content.
108108

109109
For example, suppose you're using `the Django web framework
110110
<https://www.djangoproject.com>`_ to build an online forum. You might write a
@@ -301,9 +301,9 @@ use, it's available as :data:`akismet.USER_AGENT`.
301301
)
302302
303303
Finally, note that if all you want is to set a custom timeout value for
304-
connections to the Akismet web service, you *can* do this with a custom HTTP
305-
client, or you can simply set the environment variable
306-
``PYTHON_AKISMET_TIMEOUT`` as described above.
304+
connections to the Akismet web service, you do not need a custom HTTP client;
305+
you can set the environment variable ``PYTHON_AKISMET_TIMEOUT`` as described
306+
above.
307307

308308

309309
.. _usage-testing:

src/akismet/__init__.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@
1010
(``async``/``await``/non-blocking) HTTP requests to the Akismet web service.
1111
1212
Aside from one being sync and the other async, the two clients expose identical APIs,
13-
and implement all methods of `the Akismet web API <https://akismet.com/developers/>`_,
14-
including the v1.2 key and API usage metrics.
13+
and implement all methods of `the Akismet web API <https://akismet.com/developers/>`_.
1514
1615
To use this library, you will need to obtain an Akismet API key and register a site for
1716
use with the Akismet web service; you can do this at <https://akismet.com>. Once you
1817
have a key and corresponding registered site URL to use with it, place them in the
1918
environment variables ``PYTHON_AKISMET_API_KEY`` and ``PYTHON_AKISMET_BLOG_URL``, and
2019
they will be automatically detected and used.
2120
22-
You can then construct a client instance and call its methods. For example, to check a
23-
submitted forum post for spam:
21+
You can then construct a client instance and call its methods. For creating a long-lived
22+
API client instance, it's recommended that you use the ``validated_client()``
23+
constructor method, which will automatically validate your API key with the Akismet web
24+
service. For example, to check a submitted forum post for spam:
2425
2526
.. code-block:: python
2627
@@ -52,14 +53,9 @@
5253
):
5354
# This piece of content was classified as spam; handle it appropriately.
5455
55-
Note that in both cases the client instance is created via the alternate constructor
56-
``validated_client()``. This is recommended instead of using the default constructor
57-
(i.e., directly calling ``akismet.SyncClient()`` or ``akismet.AsyncClient()``); the
58-
``validated_client()`` constructor will validate the configuration with the Akismet web
59-
service before returning the client.
60-
61-
You can also use either client class as a context manager. This also will validate the
62-
configuration for you prior to returning the client:
56+
You can also use either client class as a context manager. This does *not* require the
57+
``validated_client()`` constructor, because your API key is validated on entering the
58+
``with`` block.
6359
6460
.. code-block:: python
6561

src/akismet/_common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ class Config(typing.NamedTuple):
8787
of a key and a URL.
8888
8989
You only need to use this if you're manually configuring an Akismet API client
90-
(which should be rare) rather than letting the ``validated_client()`` constructor
91-
automatically read the configuration from environment variables.
90+
rather than letting the configuration be read automatically from environment
91+
variables.
9292
9393
"""
9494

src/akismet/_test_clients.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,17 @@ class TestAsyncClient(AsyncClient):
207207
and instead always uses its own custom HTTP client to produce the desired fixed
208208
responses.
209209
210+
For operations other than comment-check and verify-key, the response values will be:
211+
212+
* submit-ham and submit-spam: :data:`True`
213+
214+
* key-sites: the sample responses (depending on requested format) given in `the
215+
Akismet web service documentation for key-sites
216+
<https://akismet.com/developers/detailed-docs/key-sites-activity/>`_.
217+
218+
* usage-limit: the sample response given in `the Akismet web service documentation
219+
for usage-limit <https://akismet.com/developers/detailed-docs/usage-limit/>`_.
220+
210221
"""
211222

212223
comment_check_response: "akismet.CheckResponse" = _common.CheckResponse.HAM
@@ -260,6 +271,17 @@ class TestSyncClient(SyncClient):
260271
and instead always uses its own custom HTTP client to produce the desired fixed
261272
responses.
262273
274+
For operations other than comment-check and verify-key, the response values will be:
275+
276+
* submit-ham and submit-spam: :data:`True`
277+
278+
* key-sites: the sample responses (depending on requested format) given in `the
279+
Akismet web service documentation for key-sites
280+
<https://akismet.com/developers/detailed-docs/key-sites-activity/>`_.
281+
282+
* usage-limit: the sample response given in `the Akismet web service documentation
283+
for usage-limit <https://akismet.com/developers/detailed-docs/usage-limit/>`_.
284+
263285
"""
264286

265287
comment_check_response: "akismet.CheckResponse" = _common.CheckResponse.HAM

0 commit comments

Comments
 (0)