crm-backend/apps/reports/services/data_sources.py

41 lines
1.1 KiB
Python

from urllib.parse import urljoin
import requests
from django.conf import settings
from apps.reports.services.oauth import OAuth2ClientCredentials
class ReportDataSources:
"""
Keep downstream calls for report generation in one place.
The concrete service endpoints are intentionally placeholders until the
exact internal service URLs and response shapes are known.
"""
def __init__(self, oauth_client=None):
self.oauth_client = oauth_client or OAuth2ClientCredentials()
def fetch_users(self, filters):
return []
def fetch_user_metrics(self, user_ids, filters):
return {}
def fetch_tickets(self, filters):
return []
def fetch_ticket_metrics(self, ticket_ids, filters):
return {}
def get_json(self, base_url, path, params=None):
url = urljoin(f"{base_url.rstrip('/')}/", path.lstrip("/"))
response = requests.get(
url,
params=params,
headers=self.oauth_client.authorization_header(),
timeout=settings.SERVICE_REQUEST_TIMEOUT,
)
response.raise_for_status()
return response.json()