Refactor create AcAccount from json

This commit is contained in:
2024-02-24 17:46:46 +00:00
parent 3d6fc32030
commit bec839e98e
2 changed files with 8 additions and 8 deletions
+6
View File
@@ -10,3 +10,9 @@ class AcAccount:
position: int position: int
class_: str class_: str
status: str status: str
def account_from_json(a) -> AcAccount:
a["class_"] = a["class"]
del a["class"]
return AcAccount(**a)
+2 -8
View File
@@ -4,7 +4,7 @@ from ActiveCollabAPI import AC_API_VERSION
from ActiveCollabAPI.ACAuthenticator import ACAuthenticator from ActiveCollabAPI.ACAuthenticator import ACAuthenticator
from ActiveCollabAPI.ACClient import ACClient from ActiveCollabAPI.ACClient import ACClient
from ActiveCollabAPI.ACTokenAuthenticator import ACTokenAuthenticator from ActiveCollabAPI.ACTokenAuthenticator import ACTokenAuthenticator
from ActiveCollabAPI.AcAccount import AcAccount from ActiveCollabAPI.AcAccount import AcAccount, account_from_json
from ActiveCollabAPI.AcLoginResponse import AcLoginResponse from ActiveCollabAPI.AcLoginResponse import AcLoginResponse
from ActiveCollabAPI.AcProject import AcProject, project_from_json from ActiveCollabAPI.AcProject import AcProject, project_from_json
from ActiveCollabAPI.AcSession import AcSession from ActiveCollabAPI.AcSession import AcSession
@@ -37,13 +37,7 @@ class ActiveCollab:
res_data = res.json() res_data = res.json()
if res_data['is_ok'] != 1: if res_data['is_ok'] != 1:
raise Exception('Login failed! (2)') raise Exception('Login failed! (2)')
accounts = list(map(lambda a: account_from_json(a), res_data['accounts']))
def map_acccount(a) -> AcAccount:
a["class_"] = a["class"]
del a["class"]
return AcAccount(**a)
accounts = list(map(lambda a: map_acccount(a), res_data['accounts']))
return AcLoginResponse(AcUser(**res_data['user']), accounts) return AcLoginResponse(AcUser(**res_data['user']), accounts)
def select_first_account(self, accounts: list[AcAccount]) -> AcAccount: def select_first_account(self, accounts: list[AcAccount]) -> AcAccount: