Skip to content

Commit

Permalink
feat(api.py): add options to cache device data, remember device, and …
Browse files Browse the repository at this point in the history
…cache tokens in plaintext

Refactor user initialization to always create an OtfUser instance,
removing conditional logic for user creation. This simplifies the
initialization process and ensures consistent handling of user-related
data.
  • Loading branch information
NodeJSmith committed Jan 4, 2025
1 parent 4020001 commit 3747783
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/otf_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def __init__(
access_token: str | None = None,
id_token: str | None = None,
refresh_token: str | None = None,
user: OtfUser | None = None,
cache_device_data: bool = True,
remember_device: bool = True,
cache_tokens_plaintext: bool = False,
):
"""Create a new Otf instance.
Expand All @@ -53,22 +55,21 @@ def __init__(
access_token (str, optional): The access token. Default is None.
id_token (str, optional): The id token. Default is None.
refresh_token (str, optional): The refresh token. Default is None.
device_key (str, optional): The device key. Default is None.
user (OtfUser, optional): A user object. Default is None.
cache_device_data (bool, optional): Whether to cache the device data. Default is True.
remember_device (bool, optional): Whether to remember the device. Default is True.
cache_tokens_plaintext (bool, optional): Whether to cache the tokens in plaintext. Default is False.
"""

if user:
self.user = user
elif (username and password) or (access_token and id_token):
self.user = OtfUser(
username=username,
password=password,
access_token=access_token,
id_token=id_token,
refresh_token=refresh_token,
)
else:
raise ValueError("No valid authentication method provided")
self.user = OtfUser(
username=username,
password=password,
access_token=access_token,
id_token=id_token,
refresh_token=refresh_token,
cache_device_data=cache_device_data,
remember_device=remember_device,
cache_tokens_plaintext=cache_tokens_plaintext,
)

self.member = self.get_member_detail()
self.home_studio_uuid = self.member.home_studio.studio_uuid
Expand Down

0 comments on commit 3747783

Please sign in to comment.