Finaliza ajustes para iniciar Repositorio Git do SDK de Integração do Notion separado do meu projeto original
--- - Cria singleton de `client` com func `configure` para inicializar e `get_instance` para buscar instância do client; - Ajusta clients para buscar headers vindo do pai `client` e fixa versão legacy no client de databases; - Adiciona inicialização de `client` no init do projeto com api_token e api_version informados pelo usuário; - Altera `NotionConfig` para inserir `database_id` no lugar de `database_name`; - Altera sistema para receber `database_id` no lugar de `database_name`; - Altera tipo de `properties` em `schemas.responses.pages.Page` de `Union[Dict[str, Any]], TDB` para `Union[Any, TDB]` para resolver reclamações de type hint; - Adiciona param `generic_response` no init de `client` e nos clients e databases e pages para pular uso de mapping ao usar `.generic`; - Adiciona param `raw_response` para pular parser e mappings e retornar resposta original da api; - Finaliza `types` com subpastas para importações mas com init mãe vazio para evitar dependência circular e permitir uso de `notion.types.` pelo usuário; - Remove importações do projeto original não relacionadas com o SDK; - Adiciona param `timezone` na func `start_date` em `orm.common.SetProperty` que antes vinha do env, para posteriormente puxar da init da integração; - Monta `LICENSE`, `README.md` e `pyproject.toml` base simples para commit inicial do projeto permitindo build de pacote; ---
This commit is contained in:
Executable
+106
@@ -0,0 +1,106 @@
|
||||
from typing import Any, Optional
|
||||
from pydantic import validate_call
|
||||
from ..extrators.Properties import PropertyExtractor
|
||||
|
||||
class _PageProperty(PropertyExtractor):
|
||||
|
||||
"Getter específico para propriedades individuais do Notion. Permite buscar uma propriedade específica por nome e tipo."
|
||||
|
||||
def _get_properties_dict(self, response: dict) -> dict:
|
||||
"Extrai o dicionário de properties do response"
|
||||
nt_dict = response.get('properties')
|
||||
if nt_dict is None:
|
||||
nt_dict = response.get('result')
|
||||
if nt_dict is None:
|
||||
raise KeyError("Response inserido é inválido")
|
||||
return nt_dict
|
||||
|
||||
def _get_property_data(self, response: dict, name: str, expected_type: str) -> dict:
|
||||
|
||||
"""
|
||||
Busca e valida uma propriedade específica.
|
||||
|
||||
Args:
|
||||
response: Response completo do Notion
|
||||
name: Nome da propriedade
|
||||
expected_type: Tipo esperado da propriedade
|
||||
|
||||
Returns:
|
||||
Dados da propriedade
|
||||
|
||||
Raises:
|
||||
KeyError: Se propriedade não existe
|
||||
ValueError: Se tipo não corresponde
|
||||
"""
|
||||
|
||||
properties = self._get_properties_dict(response)
|
||||
|
||||
prop = properties.get(name)
|
||||
if not prop:
|
||||
raise KeyError(f"Propriedade '{name}' não foi encontrada")
|
||||
|
||||
actual_type = prop.get('type')
|
||||
if actual_type != expected_type:
|
||||
raise ValueError(
|
||||
f"Propriedade '{name}' não é do tipo '{expected_type}' "
|
||||
f"(tipo atual: '{actual_type}')"
|
||||
)
|
||||
|
||||
return prop
|
||||
|
||||
# ==================== CLASSES INTERNAS ====================
|
||||
|
||||
@validate_call
|
||||
def id(self, response: dict) -> str:
|
||||
prop = response.get('id')
|
||||
if not prop:
|
||||
raise KeyError("ID da página não foi encontrada")
|
||||
return prop
|
||||
|
||||
@validate_call
|
||||
def title(self, response: dict, name: str) -> Optional[str]:
|
||||
prop = self._get_property_data(response, name, "title")
|
||||
return self._title(prop)
|
||||
|
||||
@validate_call
|
||||
def text(self, response: dict, name: str) -> Optional[dict]:
|
||||
prop = self._get_property_data(response, name, "rich_text")
|
||||
return self._rich_text(prop)
|
||||
|
||||
@validate_call
|
||||
def number(self, response: dict, name: str) -> Optional[float]:
|
||||
prop = self._get_property_data(response, name, "number")
|
||||
return self._number(prop)
|
||||
|
||||
@validate_call
|
||||
def select(self, response: dict, name: str) -> Optional[dict]:
|
||||
prop = self._get_property_data(response, name, "select")
|
||||
return self._select(prop)
|
||||
|
||||
@validate_call
|
||||
def checkbox(self, response: dict, name: str) -> bool:
|
||||
prop = self._get_property_data(response, name, "checkbox")
|
||||
return self._checkbox(prop)
|
||||
|
||||
@validate_call
|
||||
def date(self, response: dict, name: str) -> Optional[dict]:
|
||||
prop = self._get_property_data(response, name, "date")
|
||||
return self._date(prop)
|
||||
|
||||
@validate_call
|
||||
def relation(self, response: dict, name: str) -> Optional[list]:
|
||||
prop = self._get_property_data(response, name, "relation")
|
||||
return self._relation(prop)
|
||||
|
||||
@validate_call
|
||||
def rollup(self, response: dict, name: str) -> Any:
|
||||
prop = self._get_property_data(response, name, "rollup")
|
||||
return self._rollup(prop)
|
||||
|
||||
@validate_call
|
||||
def formula(self, response: dict, name: str) -> Any:
|
||||
prop = self._get_property_data(response, name, "formula")
|
||||
return self._formula(prop)
|
||||
|
||||
PageProperty = _PageProperty()
|
||||
__all__ = ['_PageProperty']
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
from .PageProperty import PageProperty as _PageProperty
|
||||
|
||||
class _Acessors:
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.PageProperty = _PageProperty
|
||||
|
||||
Acessors = _Acessors
|
||||
__all__ = ["Acessors"]
|
||||
Reference in New Issue
Block a user