java.lang.Object
com.currencycalc.currencycalculatorjavafx.CurrencyClient

public class CurrencyClient extends Object
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
  • Felddetails

    • BASE_URL

      private final String BASE_URL
      The base URL for the FreeCurrencyAPI, including a placeholder for the API key.
      Siehe auch:
    • apiKey

      private String apiKey
      The API key used to authenticate requests to the FreeCurrencyAPI.
  • Konstruktordetails

    • CurrencyClient

      public CurrencyClient()
      Constructs a new CurrencyClient instance and initializes the API key. If the API key is not found, the user is prompted to enter a new one.
  • Methodendetails

    • fetchCurrencyData

      public CurrencyData fetchCurrencyData() throws IOException, InterruptedException
      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

      private String makeRequest() throws IOException, InterruptedException
      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

      private String 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

      public String getApiKey()
      Retrieves the current API key.
      Gibt zurück:
      The API key as a string.
    • setApiKey

      public void setApiKey(String apiKey)
      Sets the API key.
      Parameter:
      apiKey - The API key to set.