2026-01-20 22:26:39 -03:00
|
|
|
import httpx
|
|
|
|
|
from typing import Dict
|
|
|
|
|
|
|
|
|
|
class Blocks:
|
|
|
|
|
|
|
|
|
|
"Reference: https://developers.notion.com/reference/retrieve-a-block"
|
|
|
|
|
|
|
|
|
|
def __init__(self, headers : Dict[str, str]):
|
|
|
|
|
self._headers = headers
|
|
|
|
|
|
2026-01-23 22:33:22 -03:00
|
|
|
async def get(self, block_id : str):
|
2026-01-20 22:26:39 -03:00
|
|
|
|
2026-01-23 22:33:22 -03:00
|
|
|
"Busca detalhes de um bloco"
|
2026-01-20 22:26:39 -03:00
|
|
|
|
|
|
|
|
async with httpx.AsyncClient(timeout=httpx.Timeout(30.0)) as client:
|
|
|
|
|
|
|
|
|
|
response = await client.get(
|
2026-01-23 22:33:22 -03:00
|
|
|
f'https://api.notion.com/v1/blocks/{block_id}',
|
|
|
|
|
headers = self._headers
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return response.json()
|
|
|
|
|
|
|
|
|
|
async def get_children(self, block_id : str):
|
|
|
|
|
|
|
|
|
|
"Busca pelos blocos de um bloco ou página"
|
|
|
|
|
|
|
|
|
|
async with httpx.AsyncClient(timeout=httpx.Timeout(30.0)) as client:
|
|
|
|
|
|
|
|
|
|
response = await client.get(
|
|
|
|
|
f'https://api.notion.com/v1/blocks/{block_id}/children',
|
2026-01-20 22:26:39 -03:00
|
|
|
headers = self._headers
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return response.json()
|
|
|
|
|
|
|
|
|
|
__all__ = ["Blocks"]
|