Skip to content

Add common request method with token refresh handling and caching#132

Merged
tr4nt0r merged 5 commits intomiaucl:mainfrom
tr4nt0r:reauth
Feb 5, 2025
Merged

Add common request method with token refresh handling and caching#132
tr4nt0r merged 5 commits intomiaucl:mainfrom
tr4nt0r:reauth

Conversation

@tr4nt0r
Copy link
Collaborator

@tr4nt0r tr4nt0r commented Jan 22, 2025

Adds a request method to be used by other API methods.

  • Reduces duplicate code for exception handling, but exception messages have to be more generic
  • Ensures the access token is valid.
    • If token is expired, the token will be refreshed before the actual request
    • If token is not expired it continues with the request
    • If the request fails with an authentication exception, is refreshed and the request retried
    • If we don't have a valid refresh token the token refresh method will raise an auth exception
  • Support for cache headers
    • Responses that contain an etag will be cached in a dict for later re-use
    • When sending a request for an endpoint were an etag is available from a previous request, it will be sent in the headers
    • If the endpoint responds with a not modified status the response will be served from the cache
    • if the endpoint returns with a Ok status and contains en etag, the cache is updated before serving the response
    • If the API returns a not modified status but there is nothing cached, the request is retried without cache headers.

Currently only the load_lists method has been refactored to use the method. If this change is approved, I will proceed with the refactoring.

@tr4nt0r tr4nt0r requested a review from miaucl January 22, 2025 02:05
@tr4nt0r tr4nt0r force-pushed the reauth branch 2 times, most recently from 8c195d7 to 0173203 Compare February 5, 2025 00:26
@tr4nt0r tr4nt0r changed the title RFC: Request method with support for automatic token refresh and caching Add common request method with automatic token refresh and caching Feb 5, 2025
@tr4nt0r tr4nt0r changed the title Add common request method with automatic token refresh and caching Add common request method with token refresh handling and caching Feb 5, 2025
@tr4nt0r tr4nt0r force-pushed the reauth branch 2 times, most recently from 6098b7e to 37ca38d Compare February 5, 2025 01:43
@tr4nt0r tr4nt0r requested a review from miaucl February 5, 2025 02:01
@tr4nt0r tr4nt0r added the 🚀 feature New feature or request label Feb 5, 2025
@tr4nt0r tr4nt0r merged commit 4cfff2f into miaucl:main Feb 5, 2025
13 checks passed
tr4nt0r added a commit that referenced this pull request Mar 16, 2025
* reauth

* reauth

* fix tests

* refine debug msg

* refactor get_all_item_details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🚀 feature New feature or request run smoke test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants