From a43d42904d39c57a910952ec7f36e12d2a7b3790 Mon Sep 17 00:00:00 2001 From: simonwt Date: Mon, 30 Mar 2026 21:48:48 +0100 Subject: [PATCH] get branch --- apiclient.py | 22 +++++++++++----------- jobs/branch/__init__.py | 2 ++ jobs/branch/get.py | 12 ++++++++++++ testing.py | 5 ++++- 4 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 jobs/branch/__init__.py create mode 100644 jobs/branch/get.py diff --git a/apiclient.py b/apiclient.py index 5901b20..1208ef0 100644 --- a/apiclient.py +++ b/apiclient.py @@ -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 diff --git a/jobs/branch/__init__.py b/jobs/branch/__init__.py new file mode 100644 index 0000000..73717f8 --- /dev/null +++ b/jobs/branch/__init__.py @@ -0,0 +1,2 @@ +from .get import get +from .get import get \ No newline at end of file diff --git a/jobs/branch/get.py b/jobs/branch/get.py new file mode 100644 index 0000000..b8695a8 --- /dev/null +++ b/jobs/branch/get.py @@ -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 \ No newline at end of file diff --git a/testing.py b/testing.py index b0f288e..b426a73 100644 --- a/testing.py +++ b/testing.py @@ -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) \ No newline at end of file +print(profile) +print("-----------------------------") +branch = API.run_job('branch.get', "music") +print(branch) \ No newline at end of file