Endpoint
toggl_api.meta.enums.RequestMethod
¶
Bases: Enum
Self explanatory enumerations describing the different request types primarily for selecting request methods.
Source code in toggl_api/meta/enums.py
4 5 6 7 8 9 10 11 12 |
|
toggl_api.meta.base_endpoint.TogglEndpoint
¶
Bases: ABC
, Generic[T]
Base class with basic functionality for all API requests.
Attributes:
-
BASE_ENDPOINT
(str
) –Base URL of the Toggl API.
-
HEADERS
(Final[dict]
) –Default headers that the API requires for most endpoints.
Parameters:
-
workspace_id
(int | None
) –DEPRECATED and moved to child classes.
-
auth
(BasicAuth
) –Authentication for the client.
-
timeout
(int
, default:10
) –How long it takes for the client to timeout. Keyword Only. Defaults to 10 seconds.
-
re_raise
(bool
, default:False
) –Whether to raise all HTTPStatusError errors and not handle them internally. Keyword Only.
-
retries
(int
, default:3
) –Max retries to attempt if the server returns a 5xx status_code. Has no effect if re_raise is
True
. Keyword Only.
Source code in toggl_api/meta/base_endpoint.py
34 35 36 37 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 |
|
endpoint: str
abstractmethod
property
¶
model: type[T]
abstractmethod
property
¶
request(parameters: str, headers: Optional[dict] = None, body: Optional[dict | list] = None, method: RequestMethod = RequestMethod.GET, *, raw: bool = False, retries: int | None = None) -> Any
¶
Main request method which handles putting together the final API request.
Parameters:
-
parameters
(str
) –Request parameters with the endpoint excluded. Will concate with the endpoint property.
-
headers
(dict
, default:None
) –Custom request headers. Defaults to class property if set to None.
-
body
(dict | list
, default:None
) –Request body JSON data for specifying info. Defaults to None. Only used with none-GET or DELETE requests.
-
method
(RequestMethod
, default:GET
) –Request method to select. Defaults to GET.
-
raw
(bool
, default:False
) –Whether to use the raw data. Defaults to False.
-
retries
(int
, default:None
) –For recursive calls if the server fails multiple times.
Raises:
-
HTTPStatusError
–If the request is not a success.
Returns:
-
Any
–Response data or None if request does not return any data.
Source code in toggl_api/meta/base_endpoint.py
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 |
|
method(method: RequestMethod) -> Callable
¶
Source code in toggl_api/meta/base_endpoint.py
86 87 88 89 90 91 92 93 94 |
|
process_models(data: list[dict[str, Any]]) -> list[T]
¶
Source code in toggl_api/meta/base_endpoint.py
183 184 |
|
api_status() -> bool
staticmethod
¶
Method for verifying that the Toggl API is up.
Source code in toggl_api/meta/base_endpoint.py
194 195 196 197 198 199 200 201 202 203 204 |
|
toggl_api.meta.cached_endpoint.TogglCachedEndpoint
¶
Bases: TogglEndpoint[T]
Abstract cached endpoint for requesting toggl API data to disk.
See parent endpoint for more details.
Parameters:
-
auth
(BasicAuth
) –Authentication for the client.
-
cache
(TogglCache[T]
) –Cache object for caching toggl API data to disk. Builtin cache types are JSONCache and SqliteCache.
-
timeout
(int
, default:10
) –How long it takes for the client to timeout. Keyword Only. Defaults to 10 seconds.
-
re_raise
(bool
, default:False
) –Whether to raise all HTTPStatusError errors and not handle them internally. Keyword Only.
-
retries
(int
, default:3
) –Max retries to attempt if the server returns a 5xx status_code. Has no effect if re_raise is
True
. Keyword Only.
Attributes:
-
cache
(TogglCache[T]
) –Cache object the endpoint will use for storing models. Assigns itself as the parent automatically.
Methods:
-
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 toggl_api/meta/cached_endpoint.py
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 |
|
cache: TogglCache[T]
property
writable
¶
request(parameters: str, headers: Optional[dict] = None, body: Optional[dict | list] = None, method: RequestMethod = RequestMethod.GET, *, refresh: bool = False, raw: bool = False) -> Any
¶
Overridden request method with builtin cache.
Parameters:
-
parameters
(str
) –Request parameters with the endpoint excluded.
-
headers
(Optional[dict]
, default:None
) –Request headers. Custom headers can be added here.
-
body
(Optional[dict | list]
, default:None
) –Request body for GET, POST, PUT, PATCH requests. Defaults to None.
-
method
(RequestMethod
, default:GET
) –Request method. Defaults to GET.
-
refresh
(bool
, default:False
) –Whether to refresh the cache or not. Defaults to False.
-
raw
(bool
, default:False
) –Whether to use the raw data. Defaults to False.
Raises:
-
HTTPStatusError
–If the request is not a success.
Returns:
-
Any
–Toggl API response data processed into TogglClass objects or not depending on arguments.
Source code in 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 145 |
|
load_cache() -> Iterable[T]
¶
Direct loading method for retrieving all models from cache.
Source code in toggl_api/meta/cached_endpoint.py
147 148 149 |
|
save_cache(response: list[T] | T, method: RequestMethod) -> None
¶
Direct saving method for retrieving all models from cache.
Source code in toggl_api/meta/cached_endpoint.py
151 152 153 154 155 156 157 158 159 |
|
query(*query: TogglQuery, 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.
Parameters:
-
query
(TogglQuery
, default:()
) –An arbitary amount of queries to match the models to.
-
distinct
(bool
, default:False
) –A boolean that remove duplicate values if present.
Returns:
-
list[T]
–A list objects depending on the endpoint.
Source code in toggl_api/meta/cached_endpoint.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|