Class UraClient

java.lang.Object
de.stklcode.pubtrans.ura.UraClient
All Implemented Interfaces:
Serializable

public class UraClient extends Object implements Serializable
Client for URA based public transport API.

This client features builder pattern style query functionality to obtain Trip and Stop information.

Author:
Stefan Kalscheuer
See Also:
  • Constructor Details

    • UraClient

      public UraClient(String baseURL)
      Constructor with base URL and default API paths.
      Parameters:
      baseURL - The base URL (with protocol, without trailing slash).
    • UraClient

      public UraClient(String baseURL, String instantURL, String streamURL)
      Constructor with base URL and custom API paths.
      Parameters:
      baseURL - The base URL (including protocol).
      instantURL - The path for instant requests.
      streamURL - The path for stream requests.
  • Method Details

    • forStops

      public final UraClient.Query forStops(String... stops)
      Builder pattern to request given stop IDs.
      Parameters:
      stops - Stop IDs
      Returns:
      the request
    • forStopsByName

      public final UraClient.Query forStopsByName(String... stopNames)
      Builder pattern to request given stop names.
      Parameters:
      stopNames - Stop Point Names
      Returns:
      the request
    • forLines

      public final UraClient.Query forLines(String... lines)
      Builder pattern to request given line IDs.
      Parameters:
      lines - Line IDs.
      Returns:
      The request.
    • forLinesByName

      public final UraClient.Query forLinesByName(String... lineNames)
      Builder pattern to request given line names.
      Parameters:
      lineNames - Line names.
      Returns:
      The request.
    • forDirection

      public final UraClient.Query forDirection(Integer direction)
      Builder pattern to request given direction.
      Parameters:
      direction - The direction ID.
      Returns:
      The request.
    • forDestinationNames

      public final UraClient.Query forDestinationNames(String... destinationNames)
      Builder pattern to request given destination names.
      Parameters:
      destinationNames - Destination names.
      Returns:
      The request.
      Since:
      1.1.0
    • towards

      public final UraClient.Query towards(String... towards)
      Builder pattern to request given direction defined by stop point name.
      Parameters:
      towards - Towards stop point names.
      Returns:
      The request.
      Since:
      1.1.0
    • forPosition

      public final UraClient.Query forPosition(Double latitude, Double longitude, Integer radius)
      Builder pattern to request given destination names.
      Parameters:
      latitude - Latitude (WGS84).
      longitude - Longitude (WGS84).
      radius - Search radius (meters).
      Returns:
      The request.
      Since:
      1.1.0
    • getTrips

      public List<Trip> getTrips()
      Get list of trips. If forStops() and/or forLines() has been called, those will be used as filter.
      Returns:
      List of trips.
    • getTrips

      public List<Trip> getTrips(Integer limit)
      Get list of trips with limit. If forStops() and/or forLines() has been called, those will be used as filter.
      Parameters:
      limit - Maximum number of results.
      Returns:
      List of trips.
    • getTrips

      public List<Trip> getTrips(UraClient.Query query)
      Get list of trips. If forStops() and/or forLines() has been called, those will be used as filter.
      Parameters:
      query - The query.
      Returns:
      List of trips.
    • getTrips

      public List<Trip> getTrips(UraClient.Query query, Integer limit)
      Get list of trips for given stopIDs and lineIDs with result limit.
      Parameters:
      query - The query.
      limit - Maximum number of results.
      Returns:
      List of trips.
    • getTripsStream

      public AsyncUraTripReader getTripsStream(UraClient.Query query, Consumer<Trip> consumer) throws IOException
      Get trips for given stopIDs and lineIDs using stream API and pass each result to given consumer.
      Parameters:
      query - The query.
      consumer - Consumer(s) for single trips.
      Returns:
      Trip reader.
      Throws:
      IOException - Error reading response.
      Since:
      1.2.0
      See Also:
    • getTripsStream

      public AsyncUraTripReader getTripsStream(UraClient.Query query, List<Consumer<Trip>> consumers) throws IOException
      Get trips for given stopIDs and lineIDs using stream API and pass each result to given consumers.
      Parameters:
      query - The query.
      consumers - Consumer(s) for single trips.
      Returns:
      Trip reader.
      Throws:
      IOException - Error retrieving stream response.
      Since:
      1.2.0
    • getStops

      public List<Stop> getStops()
      Get list of stops without filters.
      Returns:
      The list of stops.
    • getStops

      public List<Stop> getStops(UraClient.Query query)
      List available stopIDs. If forStops() and/or forLines() has been called, those will be used as filter.
      Parameters:
      query - The query.
      Returns:
      The list.
    • getMessages

      public List<Message> getMessages()
      Get list of messages.
      Returns:
      List of messages.
      Since:
      1.3
    • getMessages

      public List<Message> getMessages(UraClient.Query query)
      Get list of messages. If forStops() has been called, those will be used as filter.
      Parameters:
      query - The query.
      Returns:
      List of trips.
      Since:
      1.3
    • getMessages

      public List<Message> getMessages(UraClient.Query query, Integer limit)
      Get list of messages for given stopIDs with result limit.
      Parameters:
      query - The query.
      limit - Maximum number of results.
      Returns:
      List of trips.
      Since:
      1.3