eater.api package¶
Submodules¶
eater.api.base module¶
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.BaseEaterEat JSON HTTP APIs for breakfast.
Instances of this class can’t be created directly, you must subclass this class and set
urlandresponse_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_datawhen creating an instance ofrequest_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_datawhen creating an instance ofrequest_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_clsor None. - kwargs (dict) – kwargs to be supplied as the
raw_dataparameter 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(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
authkwarg when to supply when instantiatingrequests.Session. - headers (requests.structures.CaseInsensitiveDict) – A dict of headers to be supplied as the
headerskwarg when instantiatingrequests.Session.
Returns: An instance of
requests.SessionReturn 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_clsor None. - kwargs (dict) – kwargs to be supplied as the
raw_dataparameter 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() → str[source]¶ Retrieve the URL to be used for the request.
Note that this method should always use
type(self).urlto access theurlproperty defined on the class. This is necessary because theurlproperty is replaced inHTTPEater.__init__().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.
Note that this property is replaced with the value of
HTTPEater.get_url()withinHTTPEater.__init__().