Internal use¶
These objects are meant only for internal use by LabStats API but their documentation is included here for completeness (or if you want to contribute)
-
class
labstats_api.models.
LabStatsObject
(requester, attributes)¶ Base class for all classes representing objects returned by the API. This makes a call to
labstats_api.models.LabStatsObject.set_attributes()
to dynamically construct this object’s attributes with a JSON object.Parameters: - requester (
labstats_api.requester.Requester
) – The requester to pass HTTP requests through. - attributes (dict) – The JSON object to build this object with.
-
set_attributes
(attributes)¶ Load this object with attributes. This method attempts to detect special types based on the field’s content and will create an additional attribute of that type.
Consider a JSON response with the following fields:
{ "id": 1000 "start_time": "2019-06-20T11:04:36.967" "name": "Microsoft Word" }
The
start_time
field matches a date in RFC3339 format, so an additional datetime attribute is created,start_time_date
.start_time
will hold the original string representing the date.start_time_date
contains a datetime object representing the date.Parameters: attributes (dict) – The JSON object to build this object with.
-
to_json
()¶ Return the original JSON that was used to construct the object
- requester (
Abstracts away the pagination of the LabStats API
-
class
labstats_api.paginated_list.
AfterIDPaginatedList
(content_class, requester, request_endpoint, request_method='GET', first_id=1, **kwargs)¶ Abstracts the
after_id
type pagination in LabStats, such as that used on/apps
Parameters: - content_class (
labstats_api.models.LabStatsObject
) – The type of object that this list will contain. All data received from LabStats will be used to create this type of object. - requester (
labstats_api.requester.Requester
) – Requester instance to use to get data into this list - request_endpoint (str) – The LabStats API endpoint to get data from. Omit
the leading slash. Add a trailing slash. For
example,
apps/
- request_method (str) –
GET
is the only supported method for now - first_id (int) – The exclusive ID of the minimum element that should go in the list. LabStats returns data starting at the nearest ID larger than it.
Additional parameters to the request can be passed as
kwargs
.- content_class (
Abstractions for communication with the LabStats REST API
-
class
labstats_api.requester.
Requester
(api_url, api_key, session, timeout=10)¶ Abstracts communication with the LabStats REST API.
Parameters: - api_url (str) – URL to LabStats API starting with
https://
- api_key (str) – API authorization key to query the LabStats server with. See API Key Creation for more information.
- session – A Requests Session object to use for this instance. See Advanced Usage – Requests for more information.
- timeout (int or tuple) – A Requests-compatible timeout value to be used on all requests. See Timeouts – Requests for more information.
-
request_data
(method, endpoint, parameters=None, headers=None)¶ Request data from the LabStats API
Parameters: - method (str) – The method to use. Only
"GET"
is implemented - endpoint (str) – The endpoint URL in LabStats, such as
"apps/"
. Do not give a leading slash. Give a trailing slash. - parameters (dict) – URL parameters
- headers (dict) – Extra HTTP headers to send with the request
- method (str) – The method to use. Only
- api_url (str) – URL to LabStats API starting with