-

site_api#

+

site_api#

An API wrapper around the Site API.

-class APIClient(site_api_url, site_api_token, **session_kwargs)[source]#
-

Bases: object

+class APIClient(site_api_url, site_api_token, **session_kwargs)[source]# +

Bases: object

A wrapper for the Django Site API.

-__init__(site_api_url, site_api_token, **session_kwargs)[source]#
+__init__(site_api_url, site_api_token, **session_kwargs)[source]#

Initialize a new APIClient instance.

Parameters:
    -
  • site_api_url (str) – The URL of the site API.

  • -
  • site_api_token (str) – The token to use for authentication.

  • +
  • site_api_url (str) – The URL of the site API.

  • +
  • site_api_token (str) – The token to use for authentication.

  • session_kwargs – Keyword arguments to pass to the aiohttp.ClientSession constructor.

@@ -443,29 +447,29 @@
-async close()[source]#
+async close()[source]#

Close the aiohttp session.

Return type:
-

None

+

None

-async delete(endpoint, *, raise_for_status=True, **kwargs)[source]#
+async delete(endpoint, *, raise_for_status=True, **kwargs)[source]#

Send a DELETE request to the site API and return the JSON response.

Parameters:
    -
  • endpoint (str) – The endpoint to send the request to.

  • -
  • raise_for_status (bool) – Whether or not to raise an exception if the response is not OK.

  • +
  • endpoint (str) – The endpoint to send the request to.

  • +
  • raise_for_status (bool) – Whether or not to raise an exception if the response is not OK.

  • **kwargs – Any extra keyword arguments to pass to aiohttp.request().

Return type:
-

Optional[dict]

+

Optional[dict]

Returns:

The JSON response the API returns, or None if the response is 204 No Content.

@@ -475,83 +479,83 @@
-async get(endpoint, *, raise_for_status=True, **kwargs)[source]#
+async get(endpoint, *, raise_for_status=True, **kwargs)[source]#

Equivalent to APIClient.request() with GET passed as the method.

Return type:
-

dict

+

dict

-async static maybe_raise_for_status(response, should_raise)[source]#
+async static maybe_raise_for_status(response, should_raise)[source]#

Raise ResponseCodeError for non-OK response if an exception should be raised.

Parameters:
  • response (aiohttp.ClientResponse) – The response to check.

  • -
  • should_raise (bool) – Whether or not to raise an exception.

  • +
  • should_raise (bool) – Whether or not to raise an exception.

Raises:

ResponseCodeError – If the response is not OK and should_raise is True.

Return type:
-

None

+

None

-async patch(endpoint, *, raise_for_status=True, **kwargs)[source]#
+async patch(endpoint, *, raise_for_status=True, **kwargs)[source]#

Equivalent to APIClient.request() with PATCH passed as the method.

Return type:
-

dict

+

dict

-async post(endpoint, *, raise_for_status=True, **kwargs)[source]#
+async post(endpoint, *, raise_for_status=True, **kwargs)[source]#

Equivalent to APIClient.request() with POST passed as the method.

Return type:
-

dict

+

dict

-async put(endpoint, *, raise_for_status=True, **kwargs)[source]#
+async put(endpoint, *, raise_for_status=True, **kwargs)[source]#

Equivalent to APIClient.request() with PUT passed as the method.

Return type:
-

dict

+

dict

-async request(method, endpoint, *, raise_for_status=True, **kwargs)[source]#
+async request(method, endpoint, *, raise_for_status=True, **kwargs)[source]#

Send an HTTP request to the site API and return the JSON response.

Parameters:
    -
  • method (str) – The HTTP method to use.

  • -
  • endpoint (str) – The endpoint to send the request to.

  • -
  • raise_for_status (bool) – Whether or not to raise an exception if the response is not OK.

  • +
  • method (str) – The HTTP method to use.

  • +
  • endpoint (str) – The endpoint to send the request to.

  • +
  • raise_for_status (bool) – Whether or not to raise an exception if the response is not OK.

  • **kwargs – Any extra keyword arguments to pass to aiohttp.request().

Return type:
-

dict

+

dict

Returns:

The JSON response the API returns.

@@ -566,19 +570,19 @@
-exception ResponseCodeError(response, response_json=None, response_text=None)[source]#
-

Bases: ValueError

+exception ResponseCodeError(response, response_json=None, response_text=None)[source]# +

Bases: ValueError

Raised in APIClient.request() when a non-OK HTTP response is received.

-__init__(response, response_json=None, response_text=None)[source]#
+__init__(response, response_json=None, response_text=None)[source]#

Initialize a new ResponseCodeError instance.

Parameters:
  • response (aiohttp.ClientResponse) – The response object from the request.

  • -
  • response_json (Optional[dict]) – The JSON response returned from the request, if any.

  • -
  • response_text (Optional[str]) – The text of the request, if any.

  • +
  • response_json (Optional[dict]) – The JSON response returned from the request, if any.

  • +
  • response_text (Optional[str]) – The text of the request, if any.

@@ -586,7 +590,7 @@
-__str__()[source]#
+__str__()[source]#

Return a string representation of the error.

@@ -678,10 +682,10 @@ - - - - - + + + + + \ No newline at end of file -- cgit v1.2.3