Klasse CurrencyClient
java.lang.Object
com.currencycalc.currencycalculatorjavafx.CurrencyClient
Handles communication with the FreeCurrencyAPI to retrieve real-time exchange rates.
This class manages the initialization and usage of the API key, as well as making HTTP requests to the API.
- Version:
- 1.0.0
- Autor:
- Tim Platzer
-
Feldübersicht
Felder -
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungConstructs a newCurrencyClient
instance and initializes the API key. -
Methodenübersicht
-
Felddetails
-
BASE_URL
The base URL for the FreeCurrencyAPI, including a placeholder for the API key.- Siehe auch:
-
apiKey
The API key used to authenticate requests to the FreeCurrencyAPI.
-
-
Konstruktordetails
-
CurrencyClient
public CurrencyClient()Constructs a newCurrencyClient
instance and initializes the API key. If the API key is not found, the user is prompted to enter a new one.
-
-
Methodendetails
-
fetchCurrencyData
Fetches the latest currency exchange data from the FreeCurrencyAPI.- Gibt zurück:
- A
CurrencyData
object containing the exchange rates. - Löst aus:
IOException
- If an I/O error occurs during the HTTP request.InterruptedException
- If the request is interrupted.
-
makeRequest
Makes an HTTP GET request to the FreeCurrencyAPI and retrieves the response.- Gibt zurück:
- The raw JSON response from the API as a string.
- Löst aus:
IOException
- If an I/O error occurs during the request.InterruptedException
- If the request is interrupted.
-
initializeApiKey
Initializes the API key. Attempts to load the API key from storage. If the key is not found, prompts the user to enter a new one.- Gibt zurück:
- The initialized API key.
- Löst aus:
RuntimeException
- If no API key is provided or saving the key fails.
-
getApiKey
Retrieves the current API key.- Gibt zurück:
- The API key as a string.
-
setApiKey
Sets the API key.- Parameter:
apiKey
- The API key to set.
-