feat: integración completa con API TNS v2
- api_client: agrega get_tns_token() — login en /v2/Acceso/Login y retorna JWT - json_generator: campos en camelCase según swagger v2; agrega nomRegTri y email placeholder cuando el paciente no tiene correo - terceros/transaccion routes: obtienen token TNS antes de cada envío, usan endpoints /v2/tablas/Tercero/Crear y /v2/rda/RdaPaciente/Insertar - config: agrega tns_empresa, tns_usuario, tns_password Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
774ce7d728
commit
6d5a85c55f
@@ -1,8 +1,26 @@
|
||||
import httpx
|
||||
import json
|
||||
from typing import Optional
|
||||
|
||||
|
||||
TNS_BASE = "https://api.tns.co"
|
||||
|
||||
|
||||
async def get_tns_token(empresa: str, usuario: str, password: str) -> tuple:
|
||||
"""Hace login en TNS v2 y devuelve (token, error_msg)."""
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=30) as client:
|
||||
resp = await client.post(
|
||||
f"{TNS_BASE}/v2/Acceso/Login",
|
||||
json={"codigoEmpresa": empresa, "nombreUsuario": usuario, "contrasenia": password},
|
||||
)
|
||||
body = resp.json()
|
||||
if resp.is_success and body.get("status"):
|
||||
return body["data"], None
|
||||
return None, body.get("message") or f"HTTP {resp.status_code}"
|
||||
except Exception as e:
|
||||
return None, str(e)
|
||||
|
||||
|
||||
async def send_json(
|
||||
url: str,
|
||||
json_data: dict,
|
||||
|
||||
Reference in New Issue
Block a user