feat(api): integrate Sitar API configuration and authentication
This commit is contained in:
@@ -145,10 +145,11 @@ class ExchangeRateService:
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def _get_external_api_token(base_url, username, password) -> Optional[str]:
|
||||
def _get_sitar_api_token(base_url, username, password) -> Optional[str]:
|
||||
"""Helper to get authentication token from external API"""
|
||||
try:
|
||||
login_url = f"{base_url}/auth/login"
|
||||
print(base_url)
|
||||
login_url = f"{base_url}/exchange-rate/auth/login"
|
||||
payload = {"username": username, "password": password}
|
||||
headers = {"Content-Type": "application/json"}
|
||||
|
||||
@@ -176,9 +177,9 @@ class ExchangeRateService:
|
||||
Optional[float]: The exchange rate value if found, None otherwise.
|
||||
"""
|
||||
# API Credentials
|
||||
API_BASE_URL = settings.EXTERNAL_API_URL
|
||||
API_USER = settings.EXTERNAL_API_USER
|
||||
API_PASS = settings.EXTERNAL_API_PASSWORD
|
||||
API_BASE_URL = settings.SITAR_API_URL
|
||||
API_USER = settings.SITAR_API_USER
|
||||
API_PASS = settings.SITAR_API_PASSWORD
|
||||
|
||||
if not API_USER or not API_PASS:
|
||||
print("ERROR: External API credentials not properly configured in settings")
|
||||
@@ -188,14 +189,14 @@ class ExchangeRateService:
|
||||
print(f"DEBUG: Fetching External API for date: {date_str}")
|
||||
|
||||
# 1. Get Token
|
||||
token = ExchangeRateService._get_external_api_token(API_BASE_URL, API_USER, API_PASS)
|
||||
token = ExchangeRateService._get_sitar_api_token(API_BASE_URL, API_USER, API_PASS)
|
||||
if not token:
|
||||
print("Failed to obtain external API token")
|
||||
return None
|
||||
|
||||
# 2. Fetch Exchange Rate
|
||||
# The API endpoint is /tipoCambio/{YYYY-MM-DD}
|
||||
tc_endpoint = f"{API_BASE_URL}/tipoCambio/{date_str}"
|
||||
tc_endpoint = f"{API_BASE_URL}/exchange-rate/tipoCambio/{date_str}"
|
||||
|
||||
# Auth header: The API expects just the token string in common usage, but we try standard first
|
||||
# based on user feedback/code: 'Authorization:' . $token
|
||||
|
||||
Reference in New Issue
Block a user