Reading Buses APIV2.1.0
A C#, .net Standard Library for the Reading Buses Open Data API (http://rtl2.ods-live.co.uk/cms/apiservice), available to use in your C# console, WPF, UWP or Win Form Applications.
ReadingBusesAPI.VehiclePositions.GpsController Class Reference

Helps get live and historical GPS data on vehicles by accessing the "Live Vehicle Positions" API. More...

Public Member Functions

async Task< ArchivedPositions[]> GetArchivedVehiclePositions (DateTime dateStartTime, TimeSpan? timeSpan)
Gets historic/archived GPS data for buses on a specific date, filtered either by vehicle ID, or all buses without a time period or both. GPS data is not stored for as long as other forms of data you may fail to get data older than a few months. More...
async Task< ArchivedPositions[]> GetArchivedVehiclePositions (DateTime dateStartTime, TimeSpan? timeSpan, string vehicle)
Gets historic/archived GPS data for buses on a specific date, filtered either by vehicle ID, or all buses without a time period or both. GPS data is not stored for as long as other forms of data you may fail to get data older than a few months. More...
async Task< LivePosition[]> GetLiveVehiclePositions ()
Gets live GPS data for all buses currently operating. More...
async Task< LivePosition > GetLiveVehiclePosition (string vehicle)
Gets live GPS data for a single buses matching Vehicle ID number. More...
async Task< bool > IsVehicle (string vehicle)
Checks if the Vehicle ID Number is currently in service right now. More...

Package Functions

GpsController ()
Creates a GPS Controller, you should not need to make your own GPS controller, you can get an instance of one via the main 'ReadingBuses' object. More...

Static Private Member Functions

static bool IsCacheValid ()
GPS data only updates every 30 seconds, so on average you will need to wait 15s for new data. This is used to check how long it was since last requesting GPS data. If it was recently there is no point making another request to the API as you will get the same data and take longer. More...

Private Attributes

LivePosition[] _livePositionCache
Holds the cache data for live GPS of vehicles. More...

Static Private Attributes

static DateTime _lastRetrieval
The last time a GPS request was made. This is used to prevent unnecessary API calls. More...

Detailed Description

Helps get live and historical GPS data on vehicles by accessing the "Live Vehicle Positions" API.

Constructor & Destructor Documentation

GpsController()

ReadingBusesAPI.VehiclePositions.GpsController.GpsController ( )
package

Creates a GPS Controller, you should not need to make your own GPS controller, you can get an instance of one via the main 'ReadingBuses' object.

Member Function Documentation

GetArchivedVehiclePositions() [1/2]

async Task<ArchivedPositions[]> ReadingBusesAPI.VehiclePositions.GpsController.GetArchivedVehiclePositions ( DateTime dateStartTime,
TimeSpan? timeSpan
)

Gets historic/archived GPS data for buses on a specific date, filtered either by vehicle ID, or all buses without a time period or both. GPS data is not stored for as long as other forms of data you may fail to get data older than a few months.

Parameters
dateStartTime Vehicle ID Number eg 414
timeSpan (optional) How long a period do you want data for, you can not get multiple days worth of data. If you ask this your result will be automatically truncated to only the start date to midnight.
Returns
An array of GPS locations at a previous date.
Exceptions
ReadingBusesApiExceptionMalformedQuery Thrown if, you have not choose a date in the past, or the date is too far in the past and so no data exists. Thrown if you have not filtered by either 'timeSpan' or 'vehicle' ID or both. Thrown if the API key is invalid or expired.
ReadingBusesApiExceptionBadQuery Thrown if the API responds with an error message.
ReadingBusesApiExceptionCritical Thrown if the API fails, but provides no reason.

See GpsController.GetLiveVehiclePositions() to get live data instead.

GetArchivedVehiclePositions() [2/2]

async Task<ArchivedPositions[]> ReadingBusesAPI.VehiclePositions.GpsController.GetArchivedVehiclePositions ( DateTime dateStartTime,
TimeSpan? timeSpan,
string vehicle
)

Gets historic/archived GPS data for buses on a specific date, filtered either by vehicle ID, or all buses without a time period or both. GPS data is not stored for as long as other forms of data you may fail to get data older than a few months.

Parameters
dateStartTime Vehicle ID Number eg 414
timeSpan (optional) How long a period do you want data for, you can not get multiple days worth of data. If you ask this your result will be automatically truncated to only the start date to midnight.
vehicle (optional) Vehicle ID Number eg 414
Returns
An array of GPS locations at a previous date.
Exceptions
ReadingBusesApiExceptionMalformedQuery Thrown if, you have not choose a date in the past, or the date is too far in the past and so no data exists. Thrown if you have not filtered by either 'timeSpan' or 'vehicle' ID or both. Thrown if the API key is invalid or expired.
ReadingBusesApiExceptionBadQuery Thrown if the API responds with an error message.
ReadingBusesApiExceptionCritical Thrown if the API fails, but provides no reason.

See GpsController.GetLiveVehiclePositions() to get live data instead.

GetLiveVehiclePosition()

async Task<LivePosition> ReadingBusesAPI.VehiclePositions.GpsController.GetLiveVehiclePosition ( string vehicle )

Gets live GPS data for a single buses matching Vehicle ID number.

Parameters
vehicle Vehicle ID Number eg 414
Returns
The GPS point of Vehicle matching your ID provided.
Exceptions
ReadingBusesApiExceptionBadQuery Thrown if a vehicle of the ID does not exist or is not currently active. You can check by using the 'IsVehicle' function.

GetLiveVehiclePositions()

async Task<LivePosition[]> ReadingBusesAPI.VehiclePositions.GpsController.GetLiveVehiclePositions ( )

Gets live GPS data for all buses currently operating.

Returns
An array of GPS locations for all buses operating by Reading Buses currently
Exceptions
ReadingBusesApiExceptionBadQuery Thrown if the API key is invalid or expired.
ReadingBusesApiExceptionCritical Thrown if the API fails, but provides no reason.

IsCacheValid()

static bool ReadingBusesAPI.VehiclePositions.GpsController.IsCacheValid ( )
static private

GPS data only updates every 30 seconds, so on average you will need to wait 15s for new data. This is used to check how long it was since last requesting GPS data. If it was recently there is no point making another request to the API as you will get the same data and take longer.

Returns
Returns if it has been less than 15 seconds from last asking for GPS data.

IsVehicle()

async Task<bool> ReadingBusesAPI.VehiclePositions.GpsController.IsVehicle ( string vehicle )

Checks if the Vehicle ID Number is currently in service right now.

Parameters
vehicle Vehicle ID Number eg 414
Returns
True or False for if the buses GPS can be found or not currently.

Member Data Documentation

_lastRetrieval

DateTime ReadingBusesAPI.VehiclePositions.GpsController._lastRetrieval
static private

The last time a GPS request was made. This is used to prevent unnecessary API calls.

_livePositionCache

LivePosition [] ReadingBusesAPI.VehiclePositions.GpsController._livePositionCache
private

Holds the cache data for live GPS of vehicles.


The documentation for this class was generated from the following file: