Skip to content

Commit

Permalink
Better support of some API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
brodokk committed Feb 9, 2024
1 parent 863ffdc commit 8e288fa
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 10 deletions.
62 changes: 52 additions & 10 deletions resonitepy/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,29 +147,43 @@ class ProfileData:
"""Representation of a Resonite profile data."""
iconUrl: Optional[str]
tokenOutOut: Optional[List[str]]
displayBadges: Optional[list]
tagline: Optional[str]
description: Optional[str]


@dataclass
class Snapshot:
totalCents: int
patreonRawCents: int
deltaCents: int
pledgeCents: int
email: str
timestamp: str

@dataclass
class PatreonData:
"""Representation of a Resonite Patreon data."""
isPatreonSupporter: bool
patreonId: Optional[str]
lastPatreonEmail: str
snapshots: List[Snapshot]
lastPatreonPledgeCents: int
lastTotalCents: int
minimumTotalUnits: int
externalCents: int
lastExternalCents: int
hasSupported: bool
lastIsAnorak: bool
lastIsAnorak: Optional[bool] # Deprecated
priorityIssue: int
lastPlusActivationTime: datetime
lastActivationTime: datetime
lastPlusPledgeAmount: int
lastPlusActivationTime: Optional[datetime] # Depreacted
lastActivationTime: Optional[datetime] # Deprecated
lastPlusPledgeAmount: Optional[int] # Deprecated
lastPaidPledgeAmount: int
accountName: str
currentAccountType: int
currentAccountCents: int
pledgedAccountType: int
accountName: Optional[str] # Deprecated
currentAccountType: Optional[int] # Deprecated
currentAccountCents: Optional[int] # Deprecated
pledgedAccountType: Optional[int] # Deprecated


@dataclass
Expand All @@ -189,9 +203,11 @@ class ResoniteUserQuotaBytesSources:
@dataclass
class ResoniteUserMigrationData:
username: str
email: str
userId: str
quotaBytes: int
usedBytes: int
patreonData: PatreonData
quotaBytesSources: Optional[ResoniteUserQuotaBytesSources]
registrationDate: datetime

Expand Down Expand Up @@ -258,19 +274,40 @@ class ResoniteUserEntitlementStorageSpace:
'storageSpace': ResoniteUserEntitlementStorageSpace,
}


@dataclass
class supporterMetadataPatreon:
isActiveSupporter: bool
totalSupportMonths: int
totalSupportCents: int
lastTierCents: int
highestTierCents: int
lowestTierCents: int
firstSupportTimestamp: datetime
lastSupportTimestamp: datetime


supporterMetadataTypeMapping = {
'patreon': supporterMetadataPatreon,
}


@dataclass
class ResoniteUser:
"""Representation of a Resonite user."""
id: str
username: str
normalizedUsername: str
email: str
registrationDate: datetime
isVerified: bool
isLocked: bool
supressBanEvasion: bool
#2fa_login: bool # TODO
two_fa_login: bool
profile: Optional[ProfileData]
supporterMetadata: Optional[List[dict]]
supporterMetadata: Optional[List[
supporterMetadataPatreon
]]
entitlements: Optional[List[
ResoniteUserEntitlementShoutOut |
ResoniteUserEntitlementCredits |
Expand Down Expand Up @@ -563,6 +600,11 @@ class ResoniteMessage:
sendTime: str
recipientId: str
messageType: ResoniteMessageType
senderUserSessionId: Optional[str]
isMigrated: bool
readTime: datetime
otherId: str
lastUpdateTime: datetime
content: ResoniteMessageContentText | ResoniteMessageContentSessionInvite | ResoniteMessageContentObject | ResoniteMessageContentSound

@dataclass
Expand Down
18 changes: 18 additions & 0 deletions resonitepy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
ResoniteLink,
ResoniteRecord,
ResoniteUser,
supporterMetadataTypeMapping,
resoniteUserEntitlementTypeMapping,
ResoniteUserEntitlementShoutOut,
ResoniteUserEntitlementCredits,
Expand Down Expand Up @@ -253,6 +254,23 @@ def getUserData(self, user: str = None) -> ResoniteUser:
)
)
response['entitlements'] = entitlements
if '2fa_login' in response:
response['two_fa_login'] = response['2fa_login']
del response['2fa_login']
if 'supporterMetadata' in response:
supporterMetadatas = []
for supporterMetadata in response['supporterMetadata']:
if '$type' in supporterMetadata:
supporterMetadata_type = supporterMetadata['$type']
del supporterMetadata['$type']
supporterMetadatas.append(
to_class(
supporterMetadataTypeMapping[supporterMetadata_type],
supporterMetadata,
DACITE_CONFIG
)
)
response['supporterMetadata'] = supporterMetadatas
return to_class(ResoniteUser, response, DACITE_CONFIG)

def getSession(self, session_id: str) -> ResoniteSession:
Expand Down

0 comments on commit 8e288fa

Please sign in to comment.