eater.api package

Submodules

eater.api.base module

eater.api.base

Base Eater API classes and utilities.

class eater.api.base.BaseEater[source]

Bases: abc.ABC

Base Eater class.

request_cls

A schematics model that represents the API request.

response_cls

A schematics model that represents the API response.

eater.api.http module

eater.api

Eater HTTP API classes.

class eater.api.http.HTTPEater(request_model: schematics.models.Model=None, *, _requests: dict={}, **kwargs)[source]

Bases: eater.api.base.BaseEater

Eat JSON HTTP APIs for breakfast.

Instances of this class can’t be created directly, you must subclass this class and set url and response_cls.

See Usage for more details.

Initialise instance of HTTPEater.

Parameters:
  • request_model (Model) – An instance of a schematics model
  • _requests (dict) – A dict of kwargs to be supplied when creating a requests session.
  • kwargs (dict) – If request_model is not defined a dict of kwargs to be supplied as the first argument raw_data when creating an instance of request_cls.
__init__(request_model: schematics.models.Model=None, *, _requests: dict={}, **kwargs)[source]

Initialise instance of HTTPEater.

Parameters:
  • request_model (Model) – An instance of a schematics model
  • _requests (dict) – A dict of kwargs to be supplied when creating a requests session.
  • kwargs (dict) – If request_model is not defined a dict of kwargs to be supplied as the first argument raw_data when creating an instance of request_cls.
create_request_model(request_model: schematics.models.Model=None, **kwargs) → schematics.models.Model[source]

Create the request model either from kwargs or request_model.

Parameters:
  • request_model (Model|None) – An instance of request_cls or None.
  • kwargs (dict) – kwargs to be supplied as the raw_data parameter when instantiating request_cls.
Returns:

An instance of request_cls.

Return type:

schematics.Model

create_response_model(response: requests.models.Response, request_model: schematics.models.Model) → schematics.models.Model[source]

Given a requests Response object, return the response model.

Parameters:
  • response (requests.Response) – A requests.Response object representing the response from the API.
  • request_model (schematics.Model) – The model used to generate the request - an instance of request_cls.
create_session(session: requests.sessions.Session=None, auth: tuple=None, headers: requests.structures.CaseInsensitiveDict=None) → requests.sessions.Session[source]

Create and return an instance of a requests Session.

Parameters:
  • auth (tupel|None) – The auth kwarg when to supply when instantiating requests.Session.
  • headers (requests.structures.CaseInsensitiveDict) – A dict of headers to be supplied as the headers kwarg when instantiating requests.Session.
Returns:

An instance of requests.Session

Return type:

requests.Session

get_request_kwargs(request_model: typing.Union, **kwargs) → dict[source]

Retrieve a dict of kwargs to supply to requests.

Parameters:
  • request_model (Model|None) – An instance of request_cls or None.
  • kwargs (dict) – kwargs to be supplied as the raw_data parameter when instantiating request_cls.
Returns:

A dict of kwargs to be supplied to requests when making a HTTP call.

Return type:

dict

get_url() → str[source]

Retrieve the URL to be used for the request.

Note that this method should always use type(self).url to access the url property defined on the class. This is necessary because the url property is replaced in HTTPEater.__init__().

Returns:The URL to the API endpoint.
Return type:str
method = 'get'

The HTTP method to use to make the API call.

request(**kwargs) → schematics.models.Model[source]

Make a HTTP request of of type method.

You should generally leave this method alone. If you need to customise the behaviour use the methods that this method uses.

request_cls = None

Default request_cls to None

session = None

An instance of requests Session

url

Returns the URL to the endpoint - property must be defined by a subclass.

Note that this property is replaced with the value of HTTPEater.get_url() within HTTPEater.__init__().

Module contents