eater.api package¶
Submodules¶
eater.api.base module¶
eater.api.http module¶
eater.api¶
Eater HTTP API classes.
-
class
eater.api.http.
HTTPEater
(*, session: requests.sessions.Session = None, auth: tuple = None, headers: requests.structures.CaseInsensitiveDict = None)[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
andresponse_cls
.See Usage for more details.
-
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 instantiatingrequest_cls
.
Returns: An instance of
request_cls
.Return type: schematics.Model
- request_model (Model|None) – An instance of
-
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
(auth: tuple = None, headers: requests.structures.CaseInsensitiveDict = None) → requests.sessions.Session[source]¶ Create an instance of a requests Session.
Parameters: - auth (tupel|None) – The
auth
kwarg when to supply when instantiatingrequests.Session
. - headers (requests.structures.CaseInsensitiveDict) – A dict of headers to be supplied as the
headers
kwarg when instantiatingrequests.Session
.
Returns: An instance of
requests.Session
Return type: requests.Session
- auth (tupel|None) – The
-
get_request_kwargs
(request_model: typing.Union[schematics.models.Model, NoneType], **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 instantiatingrequest_cls
.
Returns: A dict of kwargs to be supplied to requests when making a HTTP call.
Return type: dict
- request_model (Model|None) – An instance of
-
get_url
(request_model: typing.Union[schematics.models.Model, NoneType]) → str[source]¶ Retrieve the URL to be used for the request.
Parameters: request_model (Model|None) – An instance of the request_cls
orNone
.Returns: The URL to the API endpoint. Return type: str
-
method
= 'get'¶ The HTTP method to use to make the API call.
-
request
(request_model: schematics.models.Model = None, **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.
-