Refactor create AcAccount from json
This commit is contained in:
@@ -10,3 +10,9 @@ class AcAccount:
|
||||
position: int
|
||||
class_: str
|
||||
status: str
|
||||
|
||||
|
||||
def account_from_json(a) -> AcAccount:
|
||||
a["class_"] = a["class"]
|
||||
del a["class"]
|
||||
return AcAccount(**a)
|
||||
|
||||
@@ -4,7 +4,7 @@ from ActiveCollabAPI import AC_API_VERSION
|
||||
from ActiveCollabAPI.ACAuthenticator import ACAuthenticator
|
||||
from ActiveCollabAPI.ACClient import ACClient
|
||||
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.AcProject import AcProject, project_from_json
|
||||
from ActiveCollabAPI.AcSession import AcSession
|
||||
@@ -37,13 +37,7 @@ class ActiveCollab:
|
||||
res_data = res.json()
|
||||
if res_data['is_ok'] != 1:
|
||||
raise Exception('Login failed! (2)')
|
||||
|
||||
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']))
|
||||
accounts = list(map(lambda a: account_from_json(a), res_data['accounts']))
|
||||
return AcLoginResponse(AcUser(**res_data['user']), accounts)
|
||||
|
||||
def select_first_account(self, accounts: list[AcAccount]) -> AcAccount:
|
||||
|
||||
Reference in New Issue
Block a user