preheat_open.api.ApiSession¶
- class preheat_open.api.ApiSession(*args, **kwargs)¶
Bases:
object
Singleton class to handle API connection sessions
- __init__()¶
Methods
__init__
()addr
()Making a representation of the session object for use in logging
api_get
(endpoint[, out, payload, headers, ...])Method to send a GET request to the API
api_post
(endpoint[, out, json_payload, bare_url])Method to send a POST request to the API
api_put
(endpoint[, out, json_payload, ...])Method to send a PUT request to the API
Getter for the API key of the user
set_api_key
([api_key])Sets the API key
set_api_url
([api_url])DEPRECATED (only kept for backwards-compatibility)
- addr()¶
Making a representation of the session object for use in logging
- Return type:
str
- Returns:
string representing the session
- api_get(endpoint, out='json', payload=None, headers=None, bare_url=False)¶
Method to send a GET request to the API
- Parameters:
endpoint (
str
) – URL of the endpointout (
str
) – output type (json or csv)payload (
Optional
[dict
[str
,Any
]]) – payload for the requestheaders (
Optional
[dict
[str
,Any
]]) – headers to use for the requestbare_url (
bool
) – if True, uses the endpoint as full URL (and skips base URL additions)
- Returns:
API response in request.Response format
- api_post(endpoint, out='json', json_payload=None, bare_url=False)¶
Method to send a POST request to the API
- Parameters:
endpoint (
str
) – URL of the endpointout (
str
) – output type (json or csv)json_payload (
Optional
[dict
[str
,Any
]]) – payload for the requestbare_url (
bool
) – if True, uses the endpoint as full URL (and skips base URL additions)
- Return type:
Response
- Returns:
API response in request.Response format
- api_put(endpoint, out='json', json_payload=None, headers=None, bare_url=False)¶
Method to send a PUT request to the API
- Parameters:
endpoint (
str
) – URL of the endpointout (
str
) – output type (json or csv)json_payload (
Optional
[dict
[str
,Any
]]) – payload for the requestheaders (
Optional
[dict
[str
,Any
]]) – headers to use for the requestbare_url (
bool
) – if True, uses the endpoint as full URL (and skips base URL additions)
- Return type:
Response
- Returns:
API response in request.Response format
- get_api_key()¶
Getter for the API key of the user
- Return type:
str
- Returns:
the API key for the user
- set_api_key(api_key=None)¶
Sets the API key
- Parameters:
api_key (
Optional
[str
]) – value of the API key (if None, loads from the configuration file)- Return type:
None
- Returns:
/
- set_api_url(api_url=None)¶
DEPRECATED (only kept for backwards-compatibility)