tfl_api_wrapper/
client.rs

1use crate::{
2    line::{
3        ArrivalPredictionsByLines, ArrivalPredictionsByLinesStopPointID, DisruptionByLines,
4        DisruptionByMode, LineStatusBetweenDates, LineStatusByIDs, LineStatusByModes,
5        LineStatusBySeverity, ListDisruptionCategories, ListLinesByID, ListLinesByModes,
6        ListLinesRoutesByModes, ListModes, ListRoutesForLineIDWithSequence, ListServiceTypes,
7        ListSeverityTypes, ListStationsByLines, RouteRequest, RouteRequestById,
8        SearchLineRoutesByQuery, StationTimetableByLine, StationTimetableWithDestinationByLine,
9    },
10    request::*,
11};
12
13// Client for accessing TFL API
14pub struct Client {
15    pub app_key: String,
16    pub req_client: reqwest::Client,
17}
18
19impl Client {
20    // Create a new client for the TFL API
21    pub fn new(app_key: String) -> Self {
22        let req_client = reqwest::Client::new();
23        Self {
24            app_key,
25            req_client,
26        }
27    }
28
29    /// Return API version
30    pub fn api_version(&self) -> VersionRequest<'_> {
31        VersionRequest::new(self)
32    }
33
34    /// Return all the TFL routes
35    pub fn routes(&self) -> RouteRequest<'_> {
36        RouteRequest::new(self)
37    }
38
39    /// Return routes by Line(s)
40    pub fn routes_by_line(&self) -> RouteRequestById<'_> {
41        RouteRequestById::new(self)
42    }
43
44    /// Return disruptions by service mode. For example: Regular, Night
45    pub fn disruptions_by_mode(&self) -> DisruptionByMode<'_> {
46        DisruptionByMode::new(self)
47    }
48
49    /// Return disruptions by specified Line(s)
50    pub fn disruptions_by_line(&self) -> DisruptionByLines<'_> {
51        DisruptionByLines::new(self)
52    }
53
54    /// Return arrival predictions by specified Line(s)
55    pub fn arrival_predictions_by_lines(&self) -> ArrivalPredictionsByLines<'_> {
56        ArrivalPredictionsByLines::new(self)
57    }
58
59    /// Return arrival predictions by lines with stop point ID and optionally specifying direction, destination station id
60    pub fn arrival_predictions_by_lines_with_stoppoint(
61        &self,
62    ) -> ArrivalPredictionsByLinesStopPointID<'_> {
63        ArrivalPredictionsByLinesStopPointID::new(self)
64    }
65
66    /// Get a list of station that serve give lines
67    pub fn list_stations_by_lines(&self) -> ListStationsByLines<'_> {
68        ListStationsByLines::new(self)
69    }
70
71    /// Gets a list of valid disruption categories
72    pub fn list_disruption_categories(&self) -> ListDisruptionCategories<'_> {
73        ListDisruptionCategories::new(self)
74    }
75
76    /// Gets a list of valid modes
77    pub fn list_modes(&self) -> ListModes<'_> {
78        ListModes::new(self)
79    }
80
81    /// Gets a list of valid ServiceTypes to filter on
82    pub fn list_service_types(&self) -> ListServiceTypes<'_> {
83        ListServiceTypes::new(self)
84    }
85
86    /// Gets a list of valid severity codes
87    pub fn list_severity_types(&self) -> ListSeverityTypes<'_> {
88        ListSeverityTypes::new(self)
89    }
90
91    /// Gets all lines and their valid routes for given modes, including the name and id of the originating and terminating stops for each route
92    pub fn list_lines_routes_by_modes(&self) -> ListLinesRoutesByModes<'_> {
93        ListLinesRoutesByModes::new(self)
94    }
95
96    /// Gets all valid routes for given line id, including the sequence of stops on each route.
97    pub fn list_routes_by_line_with_sequence(&self) -> ListRoutesForLineIDWithSequence<'_> {
98        ListRoutesForLineIDWithSequence::new(self)
99    }
100
101    /// Gets lines that match the specified line ids.
102    pub fn list_lines_by_id(&self) -> ListLinesByID<'_> {
103        ListLinesByID::new(self)
104    }
105
106    /// Gets lines that serve the given modes.
107    pub fn list_lines_by_modes(&self) -> ListLinesByModes<'_> {
108        ListLinesByModes::new(self)
109    }
110
111    /// Gets the line status for all lines with a given severity
112    pub fn line_status_by_severity(&self) -> LineStatusBySeverity<'_> {
113        LineStatusBySeverity::new(self)
114    }
115
116    /// Gets the line status for given line ids during the provided dates e.g Minor Delays
117    pub fn line_status_between_dates(&self) -> LineStatusBetweenDates<'_> {
118        LineStatusBetweenDates::new(self)
119    }
120
121    /// Gets the line status of for all lines for the given modes
122    pub fn line_status_by_modes(&self) -> LineStatusByModes<'_> {
123        LineStatusByModes::new(self)
124    }
125
126    /// Gets the line status of for given line ids e.g Minor Delays
127    pub fn line_status_by_ids(&self) -> LineStatusByIDs<'_> {
128        LineStatusByIDs::new(self)
129    }
130
131    /// Gets the timetable for a specified station on the give line
132    pub fn station_timetable_by_line(&self) -> StationTimetableByLine<'_> {
133        StationTimetableByLine::new(self)
134    }
135
136    /// Gets the timetable for a specified station on the give line with specified destination
137    pub fn station_timetable_with_destination_by_line(
138        &self,
139    ) -> StationTimetableWithDestinationByLine<'_> {
140        StationTimetableWithDestinationByLine::new(self)
141    }
142
143    /// Search for lines or routes matching the query string
144    pub fn search_line_routes_by_query(&self) -> SearchLineRoutesByQuery<'_> {
145        SearchLineRoutesByQuery::new(self)
146    }
147}