feat: add Request_API dispatcher and internal API URLs
Replaces urllib http_client with proper Request_API class in general/request_api.py using the requests library. Adds API_BACKOFFICE, API_COMUNICACIONES, API_DOCUMENTACION settings pointing to Docker service names. Adds requests==2.32.3 to requirements. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -175,6 +175,11 @@ LOGGING = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# --- URLs de APIs internas (via red Docker saas_network) ---
|
||||||
|
API_BACKOFFICE = os.getenv('API_BACKOFFICE', 'http://api_backoffice:8001')
|
||||||
|
API_COMUNICACIONES = os.getenv('API_COMUNICACIONES', 'http://api_comunicaciones:8002')
|
||||||
|
API_DOCUMENTACION = os.getenv('API_DOCUMENTACION', 'http://api_documentacion:8003')
|
||||||
|
|
||||||
# --- CONFIGURACIONES PERSONALIZADAS DE LA APP ---
|
# --- CONFIGURACIONES PERSONALIZADAS DE LA APP ---
|
||||||
|
|
||||||
# Leemos la variable del .env (cargado previamente con load_dotenv)
|
# Leemos la variable del .env (cargado previamente con load_dotenv)
|
||||||
|
|||||||
55
app/general/request_api.py
Normal file
55
app/general/request_api.py
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import json
|
||||||
|
import requests
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
|
class Request_API:
|
||||||
|
"""Dispatcher de llamadas HTTP internas hacia las APIs especializadas."""
|
||||||
|
|
||||||
|
def _post(self, base_url, url_path, data):
|
||||||
|
url = base_url.rstrip('/') + '/' + url_path.lstrip('/')
|
||||||
|
headers = {'Content-Type': 'application/json'}
|
||||||
|
response = requests.post(url, data=json.dumps(data), headers=headers, timeout=30)
|
||||||
|
return response.json(), response.status_code
|
||||||
|
|
||||||
|
# --- api_backoffice ---
|
||||||
|
|
||||||
|
def backoffice_get_parameterized(self, data):
|
||||||
|
return self._post(settings.API_BACKOFFICE, 'api/general/get_parameterized/', data)
|
||||||
|
|
||||||
|
def backoffice_set_parameterized(self, data):
|
||||||
|
return self._post(settings.API_BACKOFFICE, 'api/general/set_parameterized/', data)
|
||||||
|
|
||||||
|
def backoffice_get_BBDD(self, data):
|
||||||
|
return self._post(settings.API_BACKOFFICE, 'api/general/get_BBDD/', data)
|
||||||
|
|
||||||
|
def backoffice_set_BBDD(self, data):
|
||||||
|
return self._post(settings.API_BACKOFFICE, 'api/general/set_BBDD/', data)
|
||||||
|
|
||||||
|
# --- api_comunicaciones ---
|
||||||
|
|
||||||
|
def comunicaciones_get_parameterized(self, data):
|
||||||
|
return self._post(settings.API_COMUNICACIONES, 'api/general/get_parameterized/', data)
|
||||||
|
|
||||||
|
def comunicaciones_set_parameterized(self, data):
|
||||||
|
return self._post(settings.API_COMUNICACIONES, 'api/general/set_parameterized/', data)
|
||||||
|
|
||||||
|
def comunicaciones_enviar_email(self, data):
|
||||||
|
return self._post(settings.API_COMUNICACIONES, 'api/email/enviar/', data)
|
||||||
|
|
||||||
|
def comunicaciones_enviar_sms(self, data):
|
||||||
|
return self._post(settings.API_COMUNICACIONES, 'api/sms/enviar/', data)
|
||||||
|
|
||||||
|
# --- api_documentacion ---
|
||||||
|
|
||||||
|
def documentacion_get_parameterized(self, data):
|
||||||
|
return self._post(settings.API_DOCUMENTACION, 'api/general/get_parameterized/', data)
|
||||||
|
|
||||||
|
def documentacion_set_parameterized(self, data):
|
||||||
|
return self._post(settings.API_DOCUMENTACION, 'api/general/set_parameterized/', data)
|
||||||
|
|
||||||
|
def documentacion_generar_pdf(self, data):
|
||||||
|
return self._post(settings.API_DOCUMENTACION, 'api/generation/pdf/', data)
|
||||||
|
|
||||||
|
def documentacion_guardar(self, data):
|
||||||
|
return self._post(settings.API_DOCUMENTACION, 'api/storage/guardar/', data)
|
||||||
@@ -4,4 +4,5 @@ gunicorn==21.2.0
|
|||||||
python-dotenv==1.0.1
|
python-dotenv==1.0.1
|
||||||
djangorestframework
|
djangorestframework
|
||||||
django-cors-headers
|
django-cors-headers
|
||||||
djangorestframework-simplejwt
|
djangorestframework-simplejwt
|
||||||
|
requests==2.32.3
|
||||||
@@ -4,4 +4,5 @@ gunicorn==21.2.0
|
|||||||
python-dotenv==1.0.1
|
python-dotenv==1.0.1
|
||||||
djangorestframework
|
djangorestframework
|
||||||
django-cors-headers
|
django-cors-headers
|
||||||
djangorestframework-simplejwt
|
djangorestframework-simplejwt
|
||||||
|
requests==2.32.3
|
||||||
Reference in New Issue
Block a user