Ledge Helper Functions¶
Ledge supplied helper functions.
These functions are meant to be used in plugin implementations to facilitate common workflows.
-
ledge.helpers.content_to_json(content, json_loads_args=None, json_loads_kwargs=None, encoding='utf-8')¶ Convert request content into JSON.
- Parameters
- Return type
- Returns
The JSON content of the request.
-
ledge.helpers.get_headers(request, encoding='utf-8')¶ Wrap twisted.web.http.Request.getAllHeaders so it returns strs.
- Parameters
request (twisted.web.http.Request) – The request to get the headers from.
encoding (str) – The encoding to use to decode the header bytes to text.
- Return type
- Returns
A dictionary, whose keys and values are strs, representing the request headers.
-
ledge.helpers.json_response(request, dictionary, json_dumps_args=None, json_dumps_kwargs=None, encoding='utf-8', finish=True)¶ Reply to the given request with a JSON object.
- Parameters
request (twisted.web.http.Request) – The request to respond to.
dictionary (dict) – A JSON serializable dictionary to use as the response.
json_dumps_args (tuple) – Arguments to pass through to the call to json.dumps
json_dumps_kwargs (dict) – Keyword arguments to pass through to the call to json.dumps
encoding (str) – The encoding to use to encode the JSON obj to bytes.
finish (bool) – If true, finish the request after writing the JSON.
-
ledge.helpers.text_response(request, text, encoding='utf-8', finish=True)¶ Reply to the given request with text.
- Parameters
request (twisted.web.http.Request) – The request to respond to.
text (str) – The text to reply with.
encoding (str) – The encoding to use to encode the text to bytes.
finish (bool) – If true, finish the request after writing the text.
Slack Events API Helper Functions¶
Helpers for working with the slack events API.
-
ledge.helpers.slack.verify_slack_request(request, content, secret)¶ Use Slacks hmac impl. to verify a request.
- Parameters
request (twisted.web.http.Request) – The request
content (bytes) – The request content
secret (str) – Slack signing secret
- Return type
- Returns
Whether or not the request is from Slack