get branch

This commit is contained in:
simonwt 2026-03-30 21:48:48 +01:00
parent 070148cabe
commit a43d42904d
4 changed files with 29 additions and 12 deletions

View file

@ -42,6 +42,7 @@ class APIClient(BaseModel):
token = self._access_token
headers["Authorization"] = f"Bearer {token}"
if self.debug:
print({
"method": method.upper(),
"url": url,
@ -75,14 +76,13 @@ class APIClient(BaseModel):
if 'tokenData' not in token_data:
raise ValueError(f"Unexpected response structure: {token_data}")
if self.debug:
print(f"Token data received: {token_data}") # Debug statement to check token data structure
# Access token and its timeout timestamp.
self._access_token = token_data["tokenData"]["accessToken"]
self._access_token_timeout = token_data["tokenData"]["accessTimeOut"]
if self.debug:
print(f"Debug: Current access token: {self._access_token}")
return {
"access_token": self._access_token,
"access_token_timeout": self._access_token_timeout

2
jobs/branch/__init__.py Normal file
View file

@ -0,0 +1,2 @@
from .get import get
from .get import get

12
jobs/branch/get.py Normal file
View file

@ -0,0 +1,12 @@
def get(API, branch_slug: str,) -> dict:
"""
Fetches the branch/subwiki data from the API.
Args:
branch_slug (str): Slug of the user whose branch/subwiki to fetch.
Returns:
dict: The branch/subwiki data.
"""
print(f"Fetching branch/subwiki for user slug: {branch_slug}")
branch_data = API.make_request("GET", "content", f"subwiki/{branch_slug}", authenticate=True)
return branch_data

View file

@ -31,3 +31,6 @@ if not API.is_token_valid():
profile = API.run_job('userprofile.get', "simon-little")
print(profile)
print("-----------------------------")
branch = API.run_job('branch.get', "music")
print(branch)