Skip to content

Commit

Permalink
feat(api.py): enforce username and password as required for Api class
Browse files Browse the repository at this point in the history
feat(api.py): add class method to create Api instance with user details
docs(api.py): update constructor docstring to explain username and password necessity
feat(api.py): introduce member home studio and timezone attributes in Api class
  • Loading branch information
NodeJSmith committed Jun 11, 2024
1 parent 9a200e8 commit def9aca
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/otf/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ class Api:
user: User
session: aiohttp.ClientSession

def __init__(self, username: str | None = None, password: str | None = None):
def __init__(self, username: str, password: str):
"""Create a new API instance. The username and password are required arguments because even though
we cache the token, they expire so quickly that we usually end up needing to re-authenticate.
Args:
username (str): The username of the user.
password (str): The password of the user.
"""
self.user = User.load_from_disk(username, password)

self.session = aiohttp.ClientSession()
Expand All @@ -35,6 +42,25 @@ def __init__(self, username: str | None = None, password: str | None = None):
self.classes_api = ClassesApi(self)
self.studios_api = StudiosApi(self)
self.dna_api = DnaApi(self)
self.member_home_studio = None
self.home_studio_uuid = None
self.member_tz = None

@classmethod
async def create(cls, username: str, password: str) -> "Api":
"""Create a new API instance. The username and password are required arguments because even though
we cache the token, they expire so quickly that we usually end up needing to re-authenticate.
Args:
username (str): The username of the user.
password (str): The password of the user.
"""
self = cls(username, password)
details = await self.member_api.get_member_detail()
self.member_home_studio = details.home_studio
self.home_studio_uuid = details.home_studio.studio_uuid
self.member_tz = self.member_home_studio.time_zone
return self

def __del__(self):
try:
Expand Down

0 comments on commit def9aca

Please sign in to comment.