Skip to content

Commit

Permalink
Documentation updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdlaird committed Sep 17, 2020
1 parent 0ca0d40 commit a5b82f6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Added
- Output of enabled plugins on startup
- `HookeeManager` class is now available with a simple `from hookee import HookeeManager` import.
- `HookeeManager` can now be instantiated with a `config` arg, making programmatic use more accessible.
- `response_callback` as a new config. Not accessible from command line, meant for programmatic use, and not compatible with `--response`.
- `HookeeManager` can now be instantiated with a `config` arg, making integration more accessible.
- `response_callback` as a new config. Not accessible from the command line, meant for integrations, and not compatible with `--response`.
- When `--response`, a lambda is created for `response_callback` (in conjunction with `--content-type`, if present) and that is now used in `PluginManager.run_response_plugins()`.
- Documentation improvements.

### Changed
- `PluginManager`'s `response_body` and `response_content_type` variables have been replaced with `response_callback`, a lambda that is generated if these configuration values are given.
- Removed `PluginManager`'s `request_script` and `response_script` variables, instead these are added to `loaded_plugins` after their `Plugin` is validated and instantiated.
- If `hookee` was instantiated programmatically rather than from the CLI (i.e. `click.Context` is `None`), `HookeeManager` throws exceptions and `PrintUtil` appends to a logger instead of interacting with `click.Context` or `echo` functions.
- If `hookee` was instantiated via its API rather than from the CLI (i.e. `click.Context` is `None`), `HookeeManager` throws exceptions and `PrintUtil` appends to a logger instead of interacting with `click.Context` or `echo` functions.

### Removed
- `conf.Context` in favor of using `click.Context`.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ hookee --help
## Documentation

For more advanced usage, including how `hookee`'s default configuration can be changed, extended through plugins,
integrated with programmatically, and more, see its official documentation is available at [http://hookee.readthedocs.io](http://hookee.readthedocs.io).
API integrations, and more, see its official documentation is available at [http://hookee.readthedocs.io](http://hookee.readthedocs.io).

## Contributing

Expand Down
2 changes: 2 additions & 0 deletions docs/_templates/sidebartoc.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ <h3>Getting Around</h3>
<li><a class="reference internal" href="index.html#customizing-the-response">Customizing the Response</a>
</li>
<li><a class="reference internal" href="index.html#plugins">Plugins</a></li>
<li><a class="reference internal" href="index.html#integrating-with-hookee">Integrating with <span
class="pre">hookee</span></a></li>
</ul>
</li>
<li><a class="reference internal" href="index.html#dive-deeper">Dive Deeper</a>
Expand Down
26 changes: 16 additions & 10 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,17 @@ must implement ``run(request)`` (and return the ``request``), and a response plu
The `built-in plugins that come with hookee <https://github.com/alexdlaird/hookee/tree/master/hookee/plugins>`_ may
be a useful reference when developing new plugins for ``hookee``.

Dive Deeper
===========
Integrating with ``hookee``
===========================

Under the hood, ``hookee`` uses `Flask <https://flask.palletsprojects.com/en/1.1.x/>`_ as its server and
`pyngrok <https://pyngrok.readthedocs.io/en/latest/>`_ to open and manage its tunnel. Being familiar with these
two packages would allow ``hookee`` to be configured and extended further.
.. image:: https://colab.research.google.com/assets/colab-badge.svg
:target: https://colab.research.google.com/drive/1DO1yOw8sCkybSFP_Ci8sDmsSbOgB8r54?usp=sharing

``hookee`` can also be instantiated programmatically instead of as a command line utility. To integrate with
``hookee`` this way, have a look at the :class:`~hookee.hookeemanager.HookeeManager` as a starting point. To still
get access to the output that would otherwise go to the console (for instance, request data dumped from plugins),
`setup the hookee logger <https://docs.python.org/3/howto/logging.html>`_. For example, this would add a handler
to the ``hookee`` logger that just logs output back to the console:
We can also integrate with ``hookee`` instead of using its command line interface.
:class:`~hookee.hookeemanager.HookeeManager` is a good starting point for custom integrations. If we still want
access to the output that would otherwise have gone to the console (for instance, request data dumped from plugins),
we can `setup the logger <https://docs.python.org/3/howto/logging.html>`_. For example, this would add a handler
to the ``hookee`` logger that logs output back to the console:

.. code-block:: python
Expand All @@ -206,6 +205,13 @@ to the ``hookee`` logger that just logs output back to the console:
logger.setLevel(logging.INFO)
logging.getLogger().addHandler(logging.StreamHandler())
Dive Deeper
===========

Under the hood, ``hookee`` uses `Flask <https://flask.palletsprojects.com/en/1.1.x/>`_ as its server and
`pyngrok <https://pyngrok.readthedocs.io/en/latest/>`_ to open and manage its tunnel. Being familiar with these
two packages would allow ``hookee`` to be configured and extended further.

For more advanced ``hookee`` usage, API documentation is also available.

.. toctree::
Expand Down
6 changes: 3 additions & 3 deletions hookee/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

__author__ = "Alex Laird"
__copyright__ = "Copyright 2020, Alex Laird"
__version__ = "1.2.0"
__version__ = "1.2.1"

from hookee.exception import HookeeConfigError

Expand Down Expand Up @@ -34,7 +34,7 @@ class Config:
values from the command line, this is where updated values are stored) which in turn can be overridden by
passing args to the CLI.
If instantiating programmatically, args that would otherwise have been passed to and validated by the CLI
If instantiating for a custom integration, args that would otherwise have been passed to and validated by the CLI
(see ``hookee --help``) can instead be passed as ``kwargs`` here to ensure the same validation is done.
For example:
Expand All @@ -46,7 +46,7 @@ class Config:
region="eu")
A callback function can also be passed instead of ``response`` and ``content-type`` (or needing to use
plugins) when instantiating programmatically:
plugins) when integrating with ``hookee``'s APIs:
.. code-block:: python
Expand Down
8 changes: 4 additions & 4 deletions hookee/hookeemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class HookeeManager:
An object that manages the state of a ``hookee`` runtime. Reads app configuration, loads enabled plugins,
and manages the long-lived state of ``hookee`` if a server and tunnel are started.
If instantiating programmatically, pass a :class:`~hookee.conf.Config` with args that otherwise would have
If instantiating for a custom integration, pass a :class:`~hookee.conf.Config` with args that otherwise would have
been passed to the CLI (see ``hookee --help``). For example:
.. code-block:: python
Expand All @@ -32,7 +32,7 @@ class HookeeManager:
hookee_manager = HookeeManager(config=config)
A ``response_callback`` function can also be passed instead of defining a raw ``response`` and ``content-type``
(or needing to use plugins) when instantiating programmatically:
(or needing to use plugins) when integrating with ``hookee``:
.. code-block:: python
Expand Down Expand Up @@ -156,8 +156,8 @@ def print_ready(self):

def fail(self, msg, e=None):
"""
Shutdown the curent application with a failure. If a CLI Context exists, that will be used to invoke the failure,
otherwise an exception will be thrown for failures to be caught programmatically.
Shutdown the current application with a failure. If a CLI Context exists, that will be used to invoke the
failure, otherwise an exception will be thrown for failures to be caught.
:param msg: The failure message.
:type msg: str
Expand Down

0 comments on commit a5b82f6

Please sign in to comment.