Skip to content

Commit

Permalink
New endpoints & documentation pass 1
Browse files Browse the repository at this point in the history
  • Loading branch information
ManicJamie committed Apr 30, 2024
1 parent 1bd6456 commit 8234bea
Show file tree
Hide file tree
Showing 7 changed files with 377 additions and 65 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Note that this uses the API in the same way as https://speedrun.com. The v2 API

As such, authorisation requires your username & password (and 2FA token). ***This means logging in requires a massive leap of trust***, and so I encourage you to [inspect the auth module](src/speedruncompy/auth.py), and if you're very concerned consider either changing your SRC password or manually get an authed PHPSESSID with your own requests, then use `auth.loginSESSID`.

## Omissions
Admin-only endpoints will not be added due to lack of testability and usability. These include:
- GetAdminStatusSummary
- GetTicketQueueCounts
- GetTicketStatusCounts

## Goals
Future versions will aim to assist further in development;
- Complete datatype coverage & testing to detect regressions & SRC-side additions
Expand Down
2 changes: 1 addition & 1 deletion src/speedruncompy/datatypes/_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def enforce_types(self):
_log.warning(f"{type(self)}.{fieldname} enum {true_type} does not contain value {raw}!")
else:
self[fieldname] = true_type(raw)
elif get_origin(true_type) is list:
elif get_origin(true_type) is list and type(raw) is list:
list_type = get_args(true_type)[0]
if is_compliant_type(list_type): # Coerce list types
self[fieldname] = [list_type(r) if not isinstance(self[fieldname], list_type) else r for r in raw]
Expand Down
26 changes: 23 additions & 3 deletions src/speedruncompy/datatypes/defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ class Player(Datatype):
isSupporter: OptField[bool]
"""OptField even on full `player`"""

def _is_user(self): return not self.id.startswith("u")
def _is_user(self): return not self.id.startswith("u-")
_is_registered = property(fget=_is_user)
"""Checks if a player has an account or is a text label"""

Expand All @@ -354,7 +354,7 @@ class User(Datatype):
colorAnimate: OptField[int]
areaId: str
isSupporter: OptField[bool] # TODO: ?
avatarDecoration: OptField[dict[str, bool]] # {enabled: bool}, add type for this later
avatarDecoration: OptField[dict[str, bool]] # {enabled: bool}, TODO add type for this later
iconType: IconType
onlineDate: int
signupDate: int
Expand Down Expand Up @@ -508,6 +508,16 @@ class ChallengePrizeConfig(Datatype):
currency: str
prizes: list[ChallengePrize]

class GlobalChallengeRanking(Datatype):
"""Sitewide rank based on all challenges entered."""
userId: str
rank: int
totalEarnings: int
firstPlaces: int
secondPlaces: int
thirdPlaces: int
challengesEntered: int

class Challenge(Datatype):

id: str
Expand Down Expand Up @@ -809,6 +819,15 @@ class Ticket(Datatype):
metadata: str
"""This is a json object that may be dependent on type"""

class TicketNote(Datatype):
id: str
ticketId: str
readerId: str
dateSubmitted: int
note: str
isMessage: bool
isRead: bool

class UserBlock(Datatype):
blockerId: str
blockeeId: str
Expand Down Expand Up @@ -874,9 +893,10 @@ class SupporterSubscription(Datatype):
trialEndsAt: int
"""Default 0, undocumented but assume timestamp otherwise"""
cancelAtPeriodEnd: bool
canceledAt: int # assume timestamp
canceledAt: int # TODO assume timestamp

class Title(Datatype):
"""User reward for completing a Challenge."""
id: str
title: str
comment: str
Expand Down
Loading

0 comments on commit 8234bea

Please sign in to comment.