get branch
This commit is contained in:
parent
070148cabe
commit
a43d42904d
4 changed files with 29 additions and 12 deletions
22
apiclient.py
22
apiclient.py
|
|
@ -41,13 +41,14 @@ class APIClient(BaseModel):
|
||||||
if authenticate:
|
if authenticate:
|
||||||
token = self._access_token
|
token = self._access_token
|
||||||
headers["Authorization"] = f"Bearer {token}"
|
headers["Authorization"] = f"Bearer {token}"
|
||||||
|
|
||||||
print({
|
if self.debug:
|
||||||
"method": method.upper(),
|
print({
|
||||||
"url": url,
|
"method": method.upper(),
|
||||||
"headers": headers,
|
"url": url,
|
||||||
"payload": data
|
"headers": headers,
|
||||||
})
|
"payload": data
|
||||||
|
})
|
||||||
try:
|
try:
|
||||||
response = requests.request(method.upper(), url, json=data, headers=headers, timeout=20)
|
response = requests.request(method.upper(), url, json=data, headers=headers, timeout=20)
|
||||||
return_json = response.json()
|
return_json = response.json()
|
||||||
|
|
@ -75,14 +76,13 @@ class APIClient(BaseModel):
|
||||||
if 'tokenData' not in token_data:
|
if 'tokenData' not in token_data:
|
||||||
raise ValueError(f"Unexpected response structure: {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.
|
# Access token and its timeout timestamp.
|
||||||
self._access_token = token_data["tokenData"]["accessToken"]
|
self._access_token = token_data["tokenData"]["accessToken"]
|
||||||
self._access_token_timeout = token_data["tokenData"]["accessTimeOut"]
|
self._access_token_timeout = token_data["tokenData"]["accessTimeOut"]
|
||||||
|
|
||||||
if self.debug:
|
|
||||||
print(f"Debug: Current access token: {self._access_token}")
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"access_token": self._access_token,
|
"access_token": self._access_token,
|
||||||
"access_token_timeout": self._access_token_timeout
|
"access_token_timeout": self._access_token_timeout
|
||||||
|
|
|
||||||
2
jobs/branch/__init__.py
Normal file
2
jobs/branch/__init__.py
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
from .get import get
|
||||||
|
from .get import get
|
||||||
12
jobs/branch/get.py
Normal file
12
jobs/branch/get.py
Normal 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
|
||||||
|
|
@ -30,4 +30,7 @@ if not API.is_token_valid():
|
||||||
json.dump(tokendata, f, indent=4)
|
json.dump(tokendata, f, indent=4)
|
||||||
|
|
||||||
profile = API.run_job('userprofile.get', "simon-little")
|
profile = API.run_job('userprofile.get', "simon-little")
|
||||||
print(profile)
|
print(profile)
|
||||||
|
print("-----------------------------")
|
||||||
|
branch = API.run_job('branch.get', "music")
|
||||||
|
print(branch)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue