Class TrainClient

java.lang.Object
com.cta4j.client.TrainClient

public final class TrainClient extends Object
A client for interacting with the CTA Train Tracker API.
  • Constructor Details

    • TrainClient

      public TrainClient(String host, String apiKey)
      Constructs a new TrainClient with the specified host and API key.
      Parameters:
      host - the host of the CTA Train Tracker API
      apiKey - the API key for accessing the CTA Train Tracker API
      Throws:
      NullPointerException - if host or API key is null
    • TrainClient

      public TrainClient(String apiKey)
      Constructs a new TrainClient with the default host and the specified API key.
      Parameters:
      apiKey - the API key for accessing the CTA Train Tracker API
      Throws:
      NullPointerException - if API key is null
  • Method Details

    • getStationArrivals

      public List<StationArrival> getStationArrivals(String stationId)
      Retrieves a List of upcoming arrivals for a specific station.
      Parameters:
      stationId - the ID of the station
      Returns:
      a List of upcoming arrivals for the specified station
      Throws:
      NullPointerException - if the specified station ID is null
      Cta4jException - if an error occurs while fetching the data
    • getTrain

      public Optional<Train> getTrain(String run)
      Retrieves information about a specific train by its run number.
      Parameters:
      run - the run number of the train
      Returns:
      an Optional containing the train information if found, or an empty Optional if not found
      Throws:
      NullPointerException - if the specified run number is null
      Cta4jException - if an error occurs while fetching the data