-
Notifications
You must be signed in to change notification settings - Fork 48
[4.0.0]: PoC: Refactor api client #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
some question:
and in docs it's not mentioned at all what the init returns: should it return anything at all? EDIT: return values as:
EDIT 2: the device auth was added in: but perhaps it wasn't reviewed properly what it returns. my suggestion is to change function not to return anything. EDIT 3: removed in 97a8541 |
it's not consistent, and not useful see moogar0880/PyTrakt#178 (comment)
|
Also device_auth prints on success: success_message = (
"You've been successfully authenticated. "
"With access_token {access_token} and refresh_token {refresh_token}"
)while oauth_auth does basically the same, it doesn't print anything... |
|
tree at 4e143b8: tested application run, tested device auth, oauth auth. could not test pin auth as I don't have application id, it's no longer supported method? |
This reverts commit 9e165f1.
|
Carrying to glensc/python-pytrakt#51 |
Carrying: - moogar0880/PyTrakt#178 --- Refactors bunch of different logic stuffed to `core.py` into more specific classes following `SOLID` principles. New classes: - `HttpClient` - trakt api client that takes `base_url` and implements `get`/`post`/`put`/`delete` methods, additionally can use requests `auth` - `TokenAuth` - class implementing `requests` module custom auth to supply tokens as request headers - <del>`TraktApiTokenAuth` - uses `HttpClient` and returns `client_id`, `client_token`</del> - <del>`TraktApi` - integrates `TraktApiTokenAuth` to `HttpClient`, provides `get`/`post`/`put`/`delete` methods</del> - `AuthConfig` - class to deal with loading/storing auth tokens and carry their state runtime - `DeviceAuthAdapter`, `OAuthAdapter`, `PinAuthAdapter` - dealing with specific `trakt.init()` handling The `HttpClient` could be used directly. if someone wants to make raw queries without the abstraction of the object they can use just the API client class. this is not documented, so we can leave it as an internal detail. reasons of using `HttpClient` directly could be any of: - performance - memory - lack of higher-level abstraction Some implementation comments: - `api()` and `config()` in core module are functions, so they are evaluated after module load, to be able to set constants in `core.py` before the use of these constants - `@lru_cache(maxsize=None)` is used to memorize function result. while `maxsize=1` would work too `maxsize=None` uses simpler code internally (disables lru, never expires) - (in future) in classes, `@lru_cache` stacked with`@property`, could be replaced with `@static_property` if python is bumped to 3.8 - `AuthConfig` was needed to carry the tokens, as they are updated in memory at runtime - <del>bumps python version to 3.7 for `@dataclass`: https://docs.python.org/3/library/dataclasses.html#module-dataclasses</del>
Refactors bunch of different logic stuffed to core.py into more specific classes following SOLID principles.
New classes:
HttpClient- trakt api client that takesbase_urland implementsget/post/put/deletemethods, additionally can use requestsauthTokenAuth- class implementingrequestsmodule custom auth to supply tokens as request headersTraktApiTokenAuth- usesHttpClientand returnsclient_id,client_tokenTraktApi- integratesTraktApiTokenAuthtoHttpClient, providesget/post/put/deletemethodsAuthConfig- class to deal with loading/storing auth tokens and carry their state runtimetrakt.init()handlingThe
HttpClientcould be used directlyif someone wants to make raw queries without the abstraction of the object they can use just the API client class. this is not documented, so can leave it as internal detail.
reasons of using
HttpClientdirectly could be any of:Some implementation comments:
api()andconfig()in core module are functions, so they are evaluated after module load, to be able to set constants incore.pybefore the use of these constants@lru_cache(maxsize=None)is used to memorize function result. whilemaxsize=1would work toomaxsize=Noneuses simpler code internally (disables lru, never expires)@lru_cachestacked with@property, could be replaced with@static_propertyif python is bumped to 3.8AuthConfigwas needed to carry the tokens, as they are updated in memory at runtime@dataclass: