API Base Class
- class API(api_obj, url)
Bases:
objectThis is the backbone of all API definitions. It performs all requests, validations, logging, re-authentication, and holds the raw response. This class MUST be inherited by all API definitions.
- Parameters
api_obj – This is passed down from the API type object (eg. WebSDK, etc.) and represents that type. This type is REQUIRED because it contains the authenticated sessions, base URL, and re-authentication methods. It is through these properties this class is able to send and receive requests to TPP.
url (str) – This is the URL extension from the base URL.
- property retries
- class APIResponse(response)
Bases:
object- Parameters
response (Response) –
- property api_response: Response
- assert_valid_response()
Use this method when no response property is available after an API call or to simply throw an error if the return code is invalid. This simply asserts that a valid response status code was returned by TPP.
- is_valid_response()
Returns
Truewhen the response is valid, meaning a valid return code was returned by TPP, otherwiseFalse.
- exception InvalidResponseError
Bases:
Exception
- api_response_property(return_on_204=None)
This function serves as a decorator for all API response objects. Each response property must be validated before returning the object. This function depends upon the API class.
The
on_204parameter suggests what data type is expected to be returned when the response status code is valid, but has no content. Since there is no content to return, an empty object representing that object will be returned instead. For example,# No 204 should ever be returned, so just validate the response # status codes and return the object on 200. @property @api_response_property() def value1(self) -> str: return self._from_json(key='Value1') # 204 could be returned by TPP, so just send an empty response # of the same object type as the expected response. @property @api_response_property(on_204=list) def value2(self) -> list: return self._from_json(key='Value2')
- Parameters
return_on_204 (Optional[type]) – type
Returns: Key of response content returned by TPP.