chore(connectors): implement category_exists for Boards API
This commit is contained in:
@@ -38,8 +38,27 @@ class BoardsAPI(BaseConnector):
|
|||||||
else:
|
else:
|
||||||
return self._get_posts(f"{self.base_url}/discussions", post_limit)
|
return self._get_posts(f"{self.base_url}/discussions", post_limit)
|
||||||
|
|
||||||
def category_exists(self, category):
|
def category_exists(self, category: str) -> bool:
|
||||||
|
if not category:
|
||||||
|
return False
|
||||||
|
|
||||||
|
url = f"{self.base_url}/categories/{category}"
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = requests.head(url, headers=HEADERS, allow_redirects=True)
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
return True
|
return True
|
||||||
|
if response.status_code == 404:
|
||||||
|
return False
|
||||||
|
|
||||||
|
# fallback if HEAD not supported
|
||||||
|
response = requests.get(url, headers=HEADERS)
|
||||||
|
return response.status_code == 200
|
||||||
|
|
||||||
|
except requests.RequestException as e:
|
||||||
|
logger.error(f"Error checking category '{category}': {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
## Private
|
## Private
|
||||||
def _get_posts(self, url, limit) -> list[Post]:
|
def _get_posts(self, url, limit) -> list[Post]:
|
||||||
|
|||||||
Reference in New Issue
Block a user