feat: implement backend API clients for multi-marketplace integration and frontend service layer
This commit is contained in:
44
backend/test_avito_api.py
Normal file
44
backend/test_avito_api.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import os
|
||||
import sys
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Add parent dir to path so we can import backend packages
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from backend.avito_api import AvitoAPI
|
||||
from backend.avito_api.exceptions import AvitoAPIError, AvitoAuthError
|
||||
|
||||
def test_avito_api():
|
||||
# Load environment variables
|
||||
env_path = os.path.join(os.path.dirname(__file__), '.env')
|
||||
load_dotenv(env_path)
|
||||
|
||||
# Check if keys are loaded
|
||||
client_id = os.getenv('AVITO_CLIENT_ID')
|
||||
client_secret = os.getenv('AVITO_CLIENT_SECRET')
|
||||
|
||||
if not client_id or not client_secret:
|
||||
print("Error: AVITO_CLIENT_ID and AVITO_CLIENT_SECRET must be in backend/.env")
|
||||
return
|
||||
|
||||
print(f"Initializing AvitoAPI (Authenticating...)")
|
||||
|
||||
try:
|
||||
api = AvitoAPI()
|
||||
print("Success! Successfully authenticated and received access token.")
|
||||
print(f"Token snippet: {api.client.access_token[:10]}...")
|
||||
|
||||
# For full testing we would need user_id (Avito user id)
|
||||
# print("\n--- Testing Messenger API ---")
|
||||
# chats_response = api.messenger.get_chats(user_id="12345", limit=5)
|
||||
# print("Success! Response keys:", chats_response.keys())
|
||||
|
||||
except AvitoAuthError as e:
|
||||
print(f"Authentication Failed: {e}")
|
||||
except AvitoAPIError as e:
|
||||
print(f"API Error: {e}")
|
||||
except Exception as e:
|
||||
print(f"Unexpected Error: {e}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_avito_api()
|
||||
Reference in New Issue
Block a user