-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use authorisation header, if provided, with St Jude scoreboard
- Loading branch information
Showing
3 changed files
with
17 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
import logging | ||
from typing import Literal | ||
from typing import Literal, Optional | ||
|
||
import aiohttp | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class StJudeScoreboardClient: | ||
def __init__(self): | ||
def __init__(self, token: Optional[str]): | ||
super().__init__() | ||
self._url = "https://stjude-scoreboard.snailedit.org/api/co-founders" | ||
self._token = token | ||
|
||
async def update_score(self, co_founder: Literal["myke", "stephen"], score: int): | ||
async with aiohttp.ClientSession() as session: | ||
url = f"{self._url}/{co_founder}" | ||
await session.put(url, json={"score": score}, raise_for_status=True) | ||
headers = ( | ||
{"Authorization": f"Bearer {self._token}"} | ||
if self._token is not None | ||
else None | ||
) | ||
await session.put( | ||
url, json={"score": score}, headers=headers, raise_for_status=True | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters