diff --git a/lib/config.py b/lib/config.py index 42f0880..d242aef 100644 --- a/lib/config.py +++ b/lib/config.py @@ -12,6 +12,16 @@ class Config: # 노션 API NOTION_API_SECRET = os.getenv('NOTION_API_SECRET') + NOTION_API_BASE = "https://api.notion.com/v1" + NOTION_VERSION = "2022-06-28" + + @classmethod + def get_notion_headers(cls): + return { + "Authorization": f"Bearer {cls.NOTION_API_SECRET}", + "Notion-Version": cls.NOTION_VERSION, + "Content-Type": "application/json" + } # 웹훅 서명 검증용 비밀키 (옵션) NOTION_WEBHOOK_SECRET = os.getenv('NOTION_WEBHOOK_SECRET', None) @@ -58,6 +68,6 @@ class Config: raise EnvironmentError(err_msg) else: print("필수 항목 검증 완료") - + # 초기 검증 실행 Config.validate() diff --git a/lib/notion_api.py b/lib/notion_api.py index adbcbf5..f85ef5c 100644 --- a/lib/notion_api.py +++ b/lib/notion_api.py @@ -13,8 +13,8 @@ from lib.config import Config from lib.common import EVENT_TYPE_LABELS def get_page_details(page_id: str) -> Optional[Dict]: - url = f"{NOTION_API_BASE}/pages/{page_id}" - response = requests.get(url, headers=HEADERS) + url = f"{Config.NOTION_API_BASE}/pages/{page_id}" + response = requests.get(url, headers=Config.HEADERS) if response.status_code == 200: return response.json() @@ -147,17 +147,17 @@ def fetch_entity_detail(entity_type: str, entity_id: str) -> Optional[Dict]: """ url = None if entity_type == "page": - url = f"{NOTION_API_BASE}/pages/{entity_id}" + url = f"{Config.NOTION_API_BASE}/pages/{entity_id}" elif entity_type == "database": - url = f"{NOTION_API_BASE}/databases/{entity_id}" + url = f"{Config.NOTION_API_BASE}/databases/{entity_id}" elif entity_type == "block": - url = f"{NOTION_API_BASE}/blocks/{entity_id}/children" + url = f"{Config.NOTION_API_BASE}/blocks/{entity_id}/children" else: logging.warning(f"알 수 없는 entity_type: {entity_type}") return None try: - response = requests.get(url, headers=HEADERS, timeout=5) + response = requests.get(url, headers=Config.HEADERS, timeout=5) response.raise_for_status() return response.json() except Exception as e: