ctfy.sdk.resources.series
client.series — a recurring contest's home and its ladder.
1"""``client.series`` — a recurring contest's home and its ladder.""" 2 3from __future__ import annotations 4 5from ctfy.sdk._helpers import _raise_for_status 6from ctfy.sdk.base import BaseHttpClient 7from ctfy.server.models.series import SeriesHome, SeriesLadder, SeriesLadderHistory 8 9 10class SeriesResource: 11 """The player-facing half of a series: its ladder and one player's history. 12 13 Deliberately separate from ``client.admin.series``, which configures 14 the schedule. These two reads are public for a public weekly and 15 need no privilege at all, so putting them behind the admin resource 16 would make the ladder unreadable by the people it rates. 17 """ 18 19 def __init__(self, http: BaseHttpClient) -> None: 20 self._http = http 21 22 def get(self, series_id: str) -> SeriesHome: 23 """The series' home: its schedule, the sittings you may see, the next one. 24 25 404 for a series that does not exist *and* for one whose sittings 26 and ladder are both hidden from you — the two read the same. 27 """ 28 resp = self._http.request("GET", f"/series/{series_id}") 29 _raise_for_status(resp) 30 return SeriesHome.model_validate(resp.json()) 31 32 def ladder(self, series_id: str) -> SeriesLadder: 33 """The whole ladder, best first, ties sharing a rank.""" 34 resp = self._http.request("GET", f"/series/{series_id}/ladder") 35 _raise_for_status(resp) 36 return SeriesLadder.model_validate(resp.json()) 37 38 def ladder_history(self, series_id: str, user_id: str) -> SeriesLadderHistory: 39 """Every occurrence that moved this player's rating, newest first. 40 41 404 when the player has never been rated on this series — an 42 empty history would read as "played and never moved". 43 """ 44 resp = self._http.request("GET", f"/series/{series_id}/ladder/{user_id}") 45 _raise_for_status(resp) 46 return SeriesLadderHistory.model_validate(resp.json())
11class SeriesResource: 12 """The player-facing half of a series: its ladder and one player's history. 13 14 Deliberately separate from ``client.admin.series``, which configures 15 the schedule. These two reads are public for a public weekly and 16 need no privilege at all, so putting them behind the admin resource 17 would make the ladder unreadable by the people it rates. 18 """ 19 20 def __init__(self, http: BaseHttpClient) -> None: 21 self._http = http 22 23 def get(self, series_id: str) -> SeriesHome: 24 """The series' home: its schedule, the sittings you may see, the next one. 25 26 404 for a series that does not exist *and* for one whose sittings 27 and ladder are both hidden from you — the two read the same. 28 """ 29 resp = self._http.request("GET", f"/series/{series_id}") 30 _raise_for_status(resp) 31 return SeriesHome.model_validate(resp.json()) 32 33 def ladder(self, series_id: str) -> SeriesLadder: 34 """The whole ladder, best first, ties sharing a rank.""" 35 resp = self._http.request("GET", f"/series/{series_id}/ladder") 36 _raise_for_status(resp) 37 return SeriesLadder.model_validate(resp.json()) 38 39 def ladder_history(self, series_id: str, user_id: str) -> SeriesLadderHistory: 40 """Every occurrence that moved this player's rating, newest first. 41 42 404 when the player has never been rated on this series — an 43 empty history would read as "played and never moved". 44 """ 45 resp = self._http.request("GET", f"/series/{series_id}/ladder/{user_id}") 46 _raise_for_status(resp) 47 return SeriesLadderHistory.model_validate(resp.json())
The player-facing half of a series: its ladder and one player's history.
Deliberately separate from client.admin.series, which configures
the schedule. These two reads are public for a public weekly and
need no privilege at all, so putting them behind the admin resource
would make the ladder unreadable by the people it rates.
23 def get(self, series_id: str) -> SeriesHome: 24 """The series' home: its schedule, the sittings you may see, the next one. 25 26 404 for a series that does not exist *and* for one whose sittings 27 and ladder are both hidden from you — the two read the same. 28 """ 29 resp = self._http.request("GET", f"/series/{series_id}") 30 _raise_for_status(resp) 31 return SeriesHome.model_validate(resp.json())
The series' home: its schedule, the sittings you may see, the next one.
404 for a series that does not exist and for one whose sittings and ladder are both hidden from you — the two read the same.
33 def ladder(self, series_id: str) -> SeriesLadder: 34 """The whole ladder, best first, ties sharing a rank.""" 35 resp = self._http.request("GET", f"/series/{series_id}/ladder") 36 _raise_for_status(resp) 37 return SeriesLadder.model_validate(resp.json())
The whole ladder, best first, ties sharing a rank.
39 def ladder_history(self, series_id: str, user_id: str) -> SeriesLadderHistory: 40 """Every occurrence that moved this player's rating, newest first. 41 42 404 when the player has never been rated on this series — an 43 empty history would read as "played and never moved". 44 """ 45 resp = self._http.request("GET", f"/series/{series_id}/ladder/{user_id}") 46 _raise_for_status(resp) 47 return SeriesLadderHistory.model_validate(resp.json())
Every occurrence that moved this player's rating, newest first.
404 when the player has never been rated on this series — an empty history would read as "played and never moved".