diff --git a/app.py b/app.py index a21b187..7d4fec4 100644 --- a/app.py +++ b/app.py @@ -1,7 +1,9 @@ -import os - +from dotenv import load_dotenv from flask import Flask +from dto.requests import GameStartRequest +from services.julius_baer_api_client import JuliusBaerApiClient + app = Flask(__name__) @@ -11,4 +13,9 @@ def hello_world(): # put application's code here if __name__ == '__main__': + jb_client = JuliusBaerApiClient() + game_start_request = GameStartRequest("Welch") + res = jb_client.start_game(game_start_request) + print(res) + app.run() diff --git a/config.py b/config.py index 35ab4f7..9e8a61a 100644 --- a/config.py +++ b/config.py @@ -1,19 +1,8 @@ -from flask.cli import load_dotenv +import os +from dotenv import load_dotenv -class Config: - """ - Configuration manager for the Julius Baer API client. - - Reads configuration from a YAML file and overrides values - with environment variables when available. - """ - - def __init__(self): - """ - Initialize the configuration manager. - - Args: - config_file_path: Path to the YAML configuration file. Defaults to "config.yaml". - """ - load_dotenv() \ No newline at end of file +load_dotenv() +API_URI = str(os.getenv("API_URI") or "") +API_KEY = str(os.getenv("API_KEY") or "") +API_TEAM = str(os.getenv("API_TEAM") or "") \ No newline at end of file diff --git a/services/julius_baer_api_client.py b/services/julius_baer_api_client.py index 2717105..264f2c8 100644 --- a/services/julius_baer_api_client.py +++ b/services/julius_baer_api_client.py @@ -1,27 +1,22 @@ -import requests -import uuid -from typing import Dict, Any, Optional +from typing import Dict, Any +import requests + +import config from dto.requests import GameStartRequest, GameDecisionRequest -class GameApiClient: +class JuliusBaerApiClient: """ - Client for interacting with the Game API service. + Client for interacting with the Julius Baer API service. Provides methods to start a game and make game decisions. """ def __init__(self): - """ - Initialize the Game API client. - - Args: - base_url: Base URL for the API service. Defaults to "http://localhost:5000". - """ - # TODO: import base_url from config self.base_url = base_url.rstrip('/') - self.session_id = None - self.client_id = None + self.api_uri = config.API_URI + self.api_key = config.API_KEY + self.api_team = config.API_TEAM def start_game(self, game_start_request: GameStartRequest) -> Dict[str, Any]: """ @@ -33,10 +28,15 @@ class GameApiClient: Returns: Dict containing the game start response with session_id, player_id, etc. """ - url = f"{self.base_url}/game/start" + url = f"{self.api_uri}/game/start" payload = {"player_name": game_start_request.player_name} - response = requests.post(url, json=payload) + headers = { + "x-api-key": self.api_key, + "Content-Type": "application/json" + } + + response = requests.post(url, json=payload, headers=headers) response.raise_for_status() # Raise exception for HTTP errors data = response.json() @@ -71,7 +71,8 @@ class GameApiClient: client_id = game_decision_request.client_id or self.client_id if not session_id or not client_id: - raise ValueError("Session ID and Client ID are required. Either provide them explicitly or call start_game first.") + raise ValueError( + "Session ID and Client ID are required. Either provide them explicitly or call start_game first.") url = f"{self.base_url}/game/decision" payload = {