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

@ -41,13 +41,14 @@ class APIClient(BaseModel):
if authenticate:
token = self._access_token
headers["Authorization"] = f"Bearer {token}"
print({
"method": method.upper(),
"url": url,
"headers": headers,
"payload": data
})
if self.debug:
print({
"method": method.upper(),
"url": url,
"headers": headers,
"payload": data
})
try:
response = requests.request(method.upper(), url, json=data, headers=headers, timeout=20)
return_json = response.json()
@ -75,14 +76,13 @@ class APIClient(BaseModel):
if 'tokenData' not in token_data:
raise ValueError(f"Unexpected response structure: {token_data}")
print(f"Token data received: {token_data}") # Debug statement to check token data structure
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

@ -30,4 +30,7 @@ if not API.is_token_valid():
json.dump(tokendata, f, indent=4)
profile = API.run_job('userprofile.get', "simon-little")
print(profile)
print(profile)
print("-----------------------------")
branch = API.run_job('branch.get', "music")
print(branch)