Skip to content

Commit

Permalink
Clean up the FAQ a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
ubernostrum committed Jan 1, 2024
1 parent c0df6eb commit e14f302
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ including comments, contact-form submissions, user signups and more. See

.. _alt-constructor:

Why is there an alternate constructor?
--------------------------------------
Why shouldn't I create the client directly?
-------------------------------------------

Both of the API clients provide a ``classmethod`` which serves as an alternate
constructor: :meth:`akismet.SyncClient.validated_client` and
:meth:`akismet.AsyncClient.validated_client`, and you're encouraged to use the
alternate constructor when you need an instance of one of the clients.
:meth:`akismet.AsyncClient.validated_client`, and you're encouraged to use
these alternate constructors when you need an instance of one of the clients.

The short explanation for this is that the ``validated_client()`` constructor
will automatically read your Akismet API key and site URL from environment
Expand All @@ -68,7 +68,7 @@ constructor, and you'll want to ensure you call the verify-key operation to
validate that configuration.

The longer explanation is that the ``validated_client()`` constructor allows
both the sync and async clients to provide the same overall
both the sync and async clients to provide the same
interface. :class:`~akismet.SyncClient` could easily just read the
configuration and do the validation in its own ``__init__()`` method. But
:class:`~akismet.AsyncClient` cannot do this, because its
Expand Down Expand Up @@ -99,26 +99,27 @@ If you're not able to do this, you can also manually instantiate a client and
then call its ``verify_key()`` method, passing the key and URL you want to
check as the arguments. For example:

.. code-block:: python
.. tab:: Sync

.. code-block:: python
import akismet
import akismet
config = akismet.Config(key=key_to_test, url=url_to_test)
client = akismet.SyncClient(config=config)
if not client.verify_key(key_to_test, url_to_test):
# The key/URL were invalid.
config = akismet.Config(key=key_to_test, url=url_to_test)
client = akismet.SyncClient(config=config)
if not client.verify_key(key_to_test, url_to_test):
# The key/URL were invalid.
The same :meth:`~akismet.AsyncClient.verify_key` method also exists on the
async client:
.. tab:: Async

.. code-block:: python
.. code-block:: python
import akismet
import akismet
config = akismet.Config(key=key_to_test, url=url_to_test)
client = akismet.AyncClient(config=config)
if not await client.verify_key(key_to_test, url_to_test):
# The key/URL were invalid.
config = akismet.Config(key=key_to_test, url=url_to_test)
client = akismet.AyncClient(config=config)
if not await client.verify_key(key_to_test, url_to_test):
# The key/URL were invalid.
How can I test that it's working?
Expand Down

0 comments on commit e14f302

Please sign in to comment.