java.lang.Object
de.stklcode.pubtrans.ura.UraClient
- All Implemented Interfaces:
java.io.Serializable
public class UraClient
extends java.lang.Object
implements java.io.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:
- Serialized Form
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classUraClient.QueryRequest meta object. -
Constructor Summary
Constructors Constructor Description UraClient(UraClientConfiguration config)Constructor fromUraClientConfiguration.UraClient(java.lang.String baseURL)Constructor with base URL and default API paths.UraClient(java.lang.String baseURL, java.lang.String instantPath, java.lang.String streamPath)Constructor with base URL and custom API paths. -
Method Summary
Modifier and Type Method Description UraClient.QueryforDestinationNames(java.lang.String... destinationNames)Builder pattern to request given destination names.UraClient.QueryforDirection(java.lang.Integer direction)Builder pattern to request given direction.UraClient.QueryforLines(java.lang.String... lines)Builder pattern to request given line IDs.UraClient.QueryforLinesByName(java.lang.String... lineNames)Builder pattern to request given line names.UraClient.QueryforPosition(java.lang.Double latitude, java.lang.Double longitude, java.lang.Integer radius)Builder pattern to request given destination names.UraClient.QueryforStops(java.lang.String... stops)Builder pattern to request given stop IDs.UraClient.QueryforStopsByName(java.lang.String... stopNames)Builder pattern to request given stop names.java.util.List<Message>getMessages()Get list of messages.java.util.List<Message>getMessages(UraClient.Query query)Get list of messages.java.util.List<Message>getMessages(UraClient.Query query, java.lang.Integer limit)Get list of messages for given stopIDs with result limit.java.util.List<Stop>getStops()Get list of stops without filters.java.util.List<Stop>getStops(UraClient.Query query)List available stopIDs.java.util.List<Trip>getTrips()Get list of trips.java.util.List<Trip>getTrips(UraClient.Query query)Get list of trips.java.util.List<Trip>getTrips(UraClient.Query query, java.lang.Integer limit)Get list of trips for given stopIDs and lineIDs with result limit.java.util.List<Trip>getTrips(java.lang.Integer limit)Get list of trips with limit.AsyncUraTripReadergetTripsStream(UraClient.Query query, java.util.function.Consumer<Trip> consumer)Get trips for given stopIDs and lineIDs using stream API and pass each result to given consumer.AsyncUraTripReadergetTripsStream(UraClient.Query query, java.util.List<java.util.function.Consumer<Trip>> consumers)Get trips for given stopIDs and lineIDs using stream API and pass each result to given consumers.UraClient.Querytowards(java.lang.String... towards)Builder pattern to request given direction defined by stop point name.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
UraClient
Constructor fromUraClientConfiguration.- Parameters:
config- The configuration.- Since:
- 2.0
-
UraClient
public UraClient(java.lang.String baseURL)Constructor with base URL and default API paths.- Parameters:
baseURL- The base URL (with protocol, without trailing slash).
-
UraClient
public UraClient(java.lang.String baseURL, java.lang.String instantPath, java.lang.String streamPath)Constructor with base URL and custom API paths.- Parameters:
baseURL- The base URL (including protocol).instantPath- The path for instant requests.streamPath- The path for stream requests.
-
-
Method Details
-
forStops
Builder pattern to request given stop IDs.- Parameters:
stops- Stop IDs- Returns:
- the request
-
forStopsByName
Builder pattern to request given stop names.- Parameters:
stopNames- Stop Point Names- Returns:
- the request
-
forLines
Builder pattern to request given line IDs.- Parameters:
lines- Line IDs.- Returns:
- The request.
-
forLinesByName
Builder pattern to request given line names.- Parameters:
lineNames- Line names.- Returns:
- The request.
-
forDirection
Builder pattern to request given direction.- Parameters:
direction- The direction ID.- Returns:
- The request.
-
forDestinationNames
Builder pattern to request given destination names.- Parameters:
destinationNames- Destination names.- Returns:
- The request.
- Since:
- 1.1.0
-
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(java.lang.Double latitude, java.lang.Double longitude, java.lang.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
Get list of trips. If forStops() and/or forLines() has been called, those will be used as filter.- Returns:
- List of trips.
- Throws:
UraClientException- Error with API communication.- Since:
- 1.0, 2.0 Throws
UraClientException.
-
getTrips
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.
- Throws:
UraClientException- Error with API communication.- Since:
- 1.0, 2.0 Throws
UraClientException.
-
getTrips
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.
- Throws:
UraClientException- Error with API communication.UraClientException- Error with API communication.- Since:
- 1.0, 2.0 Throws
UraClientException.
-
getTrips
public java.util.List<Trip> getTrips(UraClient.Query query, java.lang.Integer limit) throws UraClientExceptionGet list of trips for given stopIDs and lineIDs with result limit.- Parameters:
query- The query.limit- Maximum number of results.- Returns:
- List of trips.
- Throws:
UraClientException- Error with API communication.- Since:
- 1.0, 2.0 Throws
UraClientException.
-
getTripsStream
public AsyncUraTripReader getTripsStream(UraClient.Query query, java.util.function.Consumer<Trip> consumer) throws UraClientConfigurationExceptionGet 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:
UraClientConfigurationException- Error reading response.- Since:
- 1.2
- See Also:
getTripsStream(Query, List)
-
getTripsStream
public AsyncUraTripReader getTripsStream(UraClient.Query query, java.util.List<java.util.function.Consumer<Trip>> consumers) throws UraClientConfigurationExceptionGet 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:
UraClientConfigurationException- Error retrieving stream response.- Since:
- 1.2, 2.0 Throws
UraClientConfigurationException.
-
getStops
Get list of stops without filters.- Returns:
- The list of stops.
- Throws:
UraClientException- Error with API communication.- Since:
- 1.0, 2.0 Throws
UraClientException.
-
getStops
List available stopIDs. If forStops() and/or forLines() has been called, those will be used as filter.- Parameters:
query- The query.- Returns:
- The list.
- Throws:
UraClientException- Error with API communication.- Since:
- 1.0, 2.0 Throws
UraClientException.
-
getMessages
Get list of messages.- Returns:
- List of messages.
- Throws:
UraClientException- Error with API communication.- Since:
- 1.3, 2.0 Throw
UraClientException.
-
getMessages
Get list of messages. If forStops() has been called, those will be used as filter.- Parameters:
query- The query.- Returns:
- List of trips.
- Throws:
UraClientException- Error with API communication.- Since:
- 1.3, 2.0 Throw
UraClientException.
-
getMessages
public java.util.List<Message> getMessages(UraClient.Query query, java.lang.Integer limit) throws UraClientExceptionGet list of messages for given stopIDs with result limit.- Parameters:
query- The query.limit- Maximum number of results.- Returns:
- List of trips.
- Throws:
UraClientException- Error with API communication.- Since:
- 1.3, 2.0 Throw
UraClientException.
-