Public APIs
A Flask extension to add support for OpenHeart protocol.
- class flask_openheart.OpenHeart(app=None, **options)
A Flask extension to add support for OpenHeart protocol.
- init_app(app, **options)
Initialize the OpenHeart extension with a Flask application instance.
- Parameters:
app – The Flask application instance.
options – (optional) Configuration overrides.
- class flask_openheart.OpenHeartConfig
An object to represent Flask-OpenHeart configuration options.
- property database_uri
The database URI.
- property post_url_prefix
The URL prefix for OpenHeart API SET requests. Defaults to url_prefix.
- property url_prefix
The URL prefix for OpenHeart API requests.
- class flask_openheart.OpenHeartController
A Flask extension to add support for OpenHeart protocol.
- config_for(endpoint)
Get the OpenHeartConfig associated with a given endpoint.
- is_enabled_for(endpoint)
Check whether OpenHeart is enabled for a given endpoint.
- Returns:
True if enabled, False otherwise.
- post_url_for(endpoint, **values)
Get the OpenHeart POST URL associated with a given endpoint.
This is an alias for url_for but with the _method arg set to “POST”.
- Parameters:
endpoint – The name of the endpoint which supports OpenHeart.
values – Values to use for the variable parts of the URL rule. Passed to flask.url_for.
- Returns:
The URL for the OpenHeart endpoint associated with the specified endpoint.
- react_to(reaction, endpoint, **values)
Add a reaction for the given endpoint.
Similar to flask.url_for, you must provide an endpoint name and all of the values needed to build the endpoint’s URL.
After the reaction is added, the updated set of reactions is returned.
- Parameters:
reaction – The desired reaction emoji, as a string, optionally with trailing data.
endpoint – The endpoint name associated with the slug to generate.
values – Values to use for the variable parts of the URL rule.
- Returns:
The reactions associated with this endpoint (with the given values), as a dict.
- reactions_for(endpoint, **values)
Get all reactions for the given endpoint.
Similar to flask.url_for, you must provide an endpoint name and all of the values needed to build the endpoint’s URL.
This function returns a dictionary containing all reactions for that endpoint (with the given values), where the reaction is the key and the count is the value.
- Parameters:
endpoint – The endpoint name associated with the slug to generate.
values – Values to use for the variable parts of the URL rule.
- Returns:
The reactions associated with this endpoint (with the given values), as a dict.
- slug_for(endpoint, **values)
Compute a unique slug for the resource represented by the given endpoint with the given values.
This function works like flask.url_for; provide an endpoint name and the required arguments for that endpoint, and get back a result. However, instead of the result being a URL, it is a string that defines how reactions get grouped in the database for this endpoint.
- Parameters:
endpoint – The endpoint name associated with the slug to generate.
values – Values to use for the variable parts of the URL rule.
- Returns:
The slug associated with this endpoint (with the given values), as a string.
- url_for(endpoint, _method=None, **values)
Get the OpenHeart URL associated with a given endpoint.
This function behaves like flask.url_for.
By default this is the GET URL, i.e. the URL used to query reactions. To get the POST URL, i.e. the URL which accepts reactions, use the _method arg or use post_url_for instead.
- Parameters:
endpoint – The name of the endpoint which supports OpenHeart.
(optional) (_method) – The HTTP method. Defaults to GET. Supported values: GET, POST.
values – Values to use for the variable parts of the URL rule. Passed to flask.url_for.
- Returns:
The URL for the OpenHeart endpoint associated with the specified endpoint.
- class flask_openheart.OpenHeartRequestController(endpoint, **values)
OpenHeartRequest gets attached to each request to expose OpenHeart functionality.
- property config
The OpenHeart config associated with this request.
- property get_url
The OpenHeart reactions GET URL for this request.
- property get_url_external
The OpenHeart reactions GET URL for this request, formatted as an external link.
- property post_url
The OpenHeart reactions POST URL for this request.
- property post_url_external
The OpenHeart reactions POST URL for this request, formatted as an external link.
- react(reaction)
Add an OpenHeart reaction for this page.
- Parameters:
reaction – The desired reaction emoji, as a string, optionally with trailing data.
- Returns:
The updated reactions, as a dict.
- property reactions
The OpenHeart reactions for this request.