Endpoint
toggl_api.meta.RequestMethod
¶
Bases: Enum
Describing the different request types primarily for selecting request methods.
Source code in src/toggl_api/meta/_enums.py
4 5 6 7 8 9 10 11 |
|
toggl_api.meta.TogglEndpoint
¶
Base class with basic functionality for all API requests.
ATTRIBUTE | DESCRIPTION |
---|---|
BASE_ENDPOINT |
Base URL of the Toggl API.
TYPE:
|
HEADERS |
Default headers that the API requires for most endpoints.
TYPE:
|
client |
Httpx client that is used for making requests to the API.
|
PARAMETER | DESCRIPTION |
---|---|
auth
|
Authentication for the client.
TYPE:
|
client
|
Optional client to be passed to be used for requests. Useful when a global client is used and needs to be recycled.
TYPE:
|
timeout
|
How long it takes for the client to timeout. Keyword Only. Defaults to 10 seconds.
TYPE:
|
re_raise
|
Whether to raise all HTTPStatusError errors and not handle them internally. Keyword Only.
TYPE:
|
retries
|
Max retries to attempt if the server returns a 5xx status_code.
Has no effect if re_raise is
TYPE:
|
METHOD | DESCRIPTION |
---|---|
request |
Request & handle data from the Toggl API. |
process_models |
|
api_status |
Verify that the Toggl API is up. |
Source code in src/toggl_api/meta/_base_endpoint.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
|
request
¶
request(
parameters: str,
headers: Headers | None = None,
body: dict[str, Any] | list[dict[str, Any]] | None = None,
method: RequestMethod = GET,
*,
raw: bool = False,
retries: int | None = None,
) -> T | list[T] | Response | None
Request & handle data from the Toggl API.
PARAMETER | DESCRIPTION |
---|---|
parameters
|
Request parameters with the endpoint excluded. Will concate with the endpoint property.
TYPE:
|
headers
|
Custom request headers. Defaults to class property if set to None.
TYPE:
|
body
|
Request body JSON data for specifying info. Defaults to None. Only used with none-GET or DELETE requests. |
method
|
Request method to select. Defaults to GET.
TYPE:
|
raw
|
Whether to use the raw data. Defaults to False.
TYPE:
|
retries
|
For recursive calls if the server fails multiple times.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
If the request is not a success. |
RETURNS | DESCRIPTION |
---|---|
T | list[T] | Response | None
|
Response data or None if request does not return any data. |
Source code in src/toggl_api/meta/_base_endpoint.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
process_models
classmethod
¶
Source code in src/toggl_api/meta/_base_endpoint.py
217 218 219 220 |
|
api_status
staticmethod
¶
api_status() -> bool
Verify that the Toggl API is up.
RETURNS | DESCRIPTION |
---|---|
bool
|
True if the API is up. |
Source code in src/toggl_api/meta/_base_endpoint.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
|
toggl_api.asyncio.TogglAsyncEndpoint
¶
Base class with basic functionality for all async API requests.
ATTRIBUTE | DESCRIPTION |
---|---|
BASE_ENDPOINT |
Base URL of the Toggl API.
TYPE:
|
HEADERS |
Default headers that the API requires for most endpoints.
TYPE:
|
client |
Async httpx client that is used for making requests to the API.
|
PARAMETER | DESCRIPTION |
---|---|
auth
|
Authentication for the client.
TYPE:
|
client
|
Optional async client to be passed to be used for requests.
TYPE:
|
timeout
|
How long it takes for the client to timeout. Keyword Only. Defaults to 10 seconds.
TYPE:
|
re_raise
|
Whether to raise all HTTPStatusError errors and not handle them internally. Keyword Only.
TYPE:
|
retries
|
Max retries to attempt if the server returns a 5xx status_code.
Has no effect if re_raise is
TYPE:
|
METHOD | DESCRIPTION |
---|---|
api_status |
Verify that the Toggl API is up. |
toggl_api.meta.TogglCachedEndpoint
¶
Bases: TogglEndpoint[T]
Abstract cached endpoint for requesting toggl API data to disk.
See parent endpoint for more details.
PARAMETER | DESCRIPTION |
---|---|
auth
|
Authentication for the client.
TYPE:
|
cache
|
Cache object for caching toggl API data to disk. Builtin cache types are JSONCache and SqliteCache.
TYPE:
|
client
|
Optional client to be passed to be used for requests. Useful when a global client is used and needs to be recycled.
TYPE:
|
timeout
|
How long it takes for the client to timeout. Keyword Only. Defaults to 10 seconds.
TYPE:
|
re_raise
|
Whether to raise all HTTPStatusError errors and not handle them internally. Keyword Only.
TYPE:
|
retries
|
Max retries to attempt if the server returns a 5xx status_code.
Has no effect if re_raise is
TYPE:
|
ATTRIBUTE | DESCRIPTION |
---|---|
cache |
Cache object the endpoint will use for storing models. Assigns itself as the parent automatically.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
request |
Overriden method that implements the cache into the request chain. |
load_cache |
Method for loading cache into memory. |
save_cache |
Method for saving cache to disk. Ignored if expiry is set to 0 seconds. |
query |
Wrapper method for accessing querying capabilities within the assigned cache. |
Source code in src/toggl_api/meta/_cached_endpoint.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
request
¶
request(
parameters: str,
headers: Headers | None = None,
body: dict[str, Any] | list[Any] | None = None,
method: RequestMethod = GET,
*,
refresh: bool = False,
raw: bool = False,
) -> T | list[T] | Response | None
Overridden request method with builtin cache.
PARAMETER | DESCRIPTION |
---|---|
parameters
|
Request parameters with the endpoint excluded.
TYPE:
|
headers
|
Request headers. Custom headers can be added here.
TYPE:
|
body
|
Request body for GET, POST, PUT, PATCH requests. Defaults to None. |
method
|
Request method. Defaults to GET.
TYPE:
|
refresh
|
Whether to refresh the cache or not. Defaults to False.
TYPE:
|
raw
|
Whether to use the raw data. Defaults to False.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
If the request is not a success. |
RETURNS | DESCRIPTION |
---|---|
T | list[T] | Response | None
|
Toggl API response data processed into TogglClass objects or not depending on arguments. |
Source code in src/toggl_api/meta/_cached_endpoint.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
load_cache
¶
load_cache() -> Iterable[T]
Direct loading method for retrieving all models from cache.
RAISES | DESCRIPTION |
---|---|
NoCacheAssignedError
|
If no cache is assigned to the endpoint. |
RETURNS | DESCRIPTION |
---|---|
Iterable[T]
|
An iterable of models that have been previously saved. |
Source code in src/toggl_api/meta/_cached_endpoint.py
146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
save_cache
¶
save_cache(response: list[T] | T, method: RequestMethod) -> None
Direct saving method for retrieving all models from cache.
PARAMETER | DESCRIPTION |
---|---|
response
|
A list of values or single value to save.
TYPE:
|
method
|
To method to use when updating the cache.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
NoCacheAssignedError
|
If no cache is assigned to the endpoint. |
Source code in src/toggl_api/meta/_cached_endpoint.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
query
¶
query(*query: TogglQuery[Any], distinct: bool = False) -> list[T]
Query wrapper for the cache method.
If the original data structure is required use the query on the .cache attribute instead.
PARAMETER | DESCRIPTION |
---|---|
*query
|
An arbitary amount of queries to match the models to.
TYPE:
|
distinct
|
A boolean that remove duplicate values if present.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
NoCacheAssignedError
|
If the current cache is set to None. |
RETURNS | DESCRIPTION |
---|---|
list[T]
|
A list objects depending on the endpoint. |
Source code in src/toggl_api/meta/_cached_endpoint.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|
toggl_api.asyncio.TogglAsyncCachedEndpoint
¶
Bases: TogglAsyncEndpoint[T]
Abstract cached endpoint for requesting toggl API data to disk.
See parent endpoint for more details.
PARAMETER | DESCRIPTION |
---|---|
auth
|
Authentication for the client.
TYPE:
|
cache
|
Cache object for caching toggl API data to disk. AsyncSqlitecache only available for now.
TYPE:
|
client
|
Optional async client to be passed to be used for requests.
TYPE:
|
timeout
|
How long it takes for the client to timeout. Keyword Only. Defaults to 10 seconds.
TYPE:
|
re_raise
|
Whether to raise all HTTPStatusError errors and not handle them internally. Keyword Only.
TYPE:
|
retries
|
Max retries to attempt if the server returns a 5xx status_code.
Has no effect if re_raise is
TYPE:
|
ATTRIBUTE | DESCRIPTION |
---|---|
cache |
Cache object the endpoint will use for storing models. Assigns itself as the parent automatically.
TYPE:
|
client |
Async httpx client that is used for making requests to the API.
|
METHOD | DESCRIPTION |
---|---|
request |
Overriden method that implements the cache into the request chain. |
load_cache |
Method for loading cache into memory. |
save_cache |
Method for saving cache to disk. Ignored if expiry is set to 0 seconds. |
request
async
¶
request(
parameters: str,
headers: Headers | None = None,
body: dict[str, Any] | list[Any] | None = None,
method: RequestMethod = GET,
*,
refresh: bool = False,
raw: bool = False,
) -> T | list[T] | Response | None
Overridden request method with builtin cache.
PARAMETER | DESCRIPTION |
---|---|
parameters
|
Request parameters with the endpoint excluded.
TYPE:
|
headers
|
Request headers. Custom headers can be added here.
TYPE:
|
body
|
Request body for GET, POST, PUT, PATCH requests. Defaults to None. |
method
|
Request method. Defaults to GET.
TYPE:
|
refresh
|
Whether to refresh the cache or not. Defaults to False.
TYPE:
|
raw
|
Whether to use the raw data. Defaults to False.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
If the request is not a success. |
RETURNS | DESCRIPTION |
---|---|
T | list[T] | Response | None
|
Toggl API response data processed into TogglClass objects or not depending on arguments. |
load_cache
async
¶
load_cache() -> Iterable[T]
Direct loading method for retrieving all models from cache.
RAISES | DESCRIPTION |
---|---|
NoCacheAssignedError
|
If no cache is assigned to the endpoint. |
RETURNS | DESCRIPTION |
---|---|
Iterable[T]
|
Previously cached objects. |
save_cache
async
¶
save_cache(response: list[T] | T, method: RequestMethod) -> None
Save all provided models to cache.
PARAMETER | DESCRIPTION |
---|---|
response
|
A list of values or single value to save.
TYPE:
|
method
|
To method to use when updating the cache.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
NoCacheAssignedError
|
If no cache is assigned to the endpoint. |