-
Notifications
You must be signed in to change notification settings - Fork 2
/
stopPoint.ts
187 lines (170 loc) · 7.75 KB
/
stopPoint.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import TfLAPI from './tfl';
import TfL from './interfaces/tfl';
// import * as IStopPoint from './interfaces/stopPoint';
export default class StopPoint extends TfLAPI {
constructor(config: string) {
super(config);
}
/**
* Gets the list of available StopPoint additional information categories
*/
getCategories(): Promise<Array<any>> {
return this.sendRequest(`/StopPoint/Meta/Categories`, {});
}
/**
* Gets the list of available StopPoint types
*/
getTypes(): Promise<Array<string>> {
return this.sendRequest(`/StopPoint/Meta/StopTypes`, {});
}
/**
* Gets the list of available StopPoint modes
*/
getModes(): Promise<Array<any>> {
return this.sendRequest(`/StopPoint/Meta/Modes`, {});
}
/**
* Gets a list of StopPoints corresponding to the given list of stop ids
* @param ids A list of stop point ids (station naptan code e.g. 940GZZLUASL).
* @param includeCrowdingData Include the crowding data (static). To Filter further use: /StopPoint/{ids}/Crowding/{line}
*/
getByIDs(ids: Array<string>, includeCrowdingData: boolean): Promise<Array<TfL['StopPoint']>> {
return this.sendRequest(`/StopPoint/${TfLAPI.arrayToCSV(ids)}`, { includeCrowdingData });
}
/**
* Gets all stop points of a given type
* @param types A list of valid stop types can be obtained from the StopPoint/meta/stoptypes endpoint
*/
getAllByStopType(types: Array<string>): Promise<Array<TfL['StopPoint']>> {
return this.sendRequest(`/StopPoint/Type/${TfLAPI.arrayToCSV(types)}`, {});
}
/**
* Gets the service types for a given Stop Point
* @param id
* @param lineIds
* @param modes
*/
getServiceTypesByID(id: string, lineIds?: Array<string>, modes?: Array<string>): Promise<Array<TfL['LineServiceType']>> {
return this.sendRequest(`/StopPoint/ServiceTypes`, { id, lineIds, modes });
}
/**
* Search StopPoints by their common name. Will not return a valid NaPTAN for HUB
* @param name Name of station
* @param modes Eg. tfl, dlr
*/
search(name: string, modes: string): Promise<TfL['SearchResponse']> {
return this.sendRequest(`/StopPoint/Search/${name}`, { modes });
}
/**
* Get all service arrivals
* @param id A StopPoint id (station naptan code e.g. 940GZZLUAS)
*/
getStationArrivals(id: string): Promise<Array<TfL['Prediction']>> {
return this.sendRequest(`/StopPoint/${id}/Arrivals`, {});
}
/**
*
* @param id A StopPoint id (station naptan code e.g. 940GZZLUAS)
* @param lineIds List of line ids e.g. tfl-rail, london-overground, thameslink
*/
// getArrivalDepartures(id: string, lineIds: Array<string>) {
// return this.sendRequest(`/StopPoint/${id}/ArrivalsDepartures`, { lineIds }, 'GET');
// }
/**
* Gets all disruptions for the specified StopPointId, plus disruptions for any child Naptan records it may have
* @param ids A list of StopPoint ids (station naptan code e.g. 940GZZLUAS)
* @param getFamily Specify true to return disruptions for entire family, or false to return disruptions for just this stop point. Defaults to false.
* @param includeRouteBlockedStops
* @param flattenResponse Specify true to associate all disruptions with parent stop point. (Only applicable when getFamily is true)
*/
getDisruptionsByID(ids: Array<string>, getFamily: boolean, includeRouteBlockedStops: boolean, flattenResponse: boolean): Promise<Array<TfL['DisruptedPoint']>> {
return this.sendRequest(
`/StopPoint/${TfLAPI.arrayToCSV(ids)}/Disruption`,
{
getFamily,
includeRouteBlockedStops,
flattenResponse
},
'GET'
);
}
/**
* Gets a distinct list of disrupted stop points for the given modes
* @param modes An array of modes e.g. ['tube', 'dlr']
* @param includeRouteBlockedStops
*/
getDisruptionsByMode(modes: Array<string>, includeRouteBlockedStops: boolean): Promise<Array<TfL['DisruptedPoint']>> {
return this.sendRequest(`/StopPoint/Mode/${TfLAPI.arrayToCSV(modes)}/Disruption`, { includeRouteBlockedStops });
}
/**
* Gets Stop points that are reachable from a station/line combination
* @param id A StopPoint id (station naptan code e.g. 940GZZLUAS)
* @param lineID Line id of the line to filter by (e.g. victoria)
* @param serviceTypes List of service types to filter on. Supported values: Regular, Night. Defaulted to 'Regular'.
*/
getReachableStationsByID(id: string, lineID: string, serviceTypes: Array<string> = ['Regular']): Promise<Array<TfL['Identifier']>> {
return this.sendRequest(`/StopPoint/${id}/CanReachOnLine/${lineID}`, { serviceTypes: TfLAPI.arrayToCSV(serviceTypes) });
}
/**
* Get the route sections for all the lines that service the given stop point id
* @param id A StopPoint id (station naptan code e.g. 940GZZLUAS)
* @param serviceTypes List of service types to filter on. Supported values: Regular, Night. Defaulted to 'Regular'.
*/
getRouteSectionByID(id: string, serviceTypes: Array<string> = ['Regular']): Promise<Array<TfL['StopPointRouteSection']>> {
return this.sendRequest(`/StopPoint/${id}/ `, { serviceTypes: TfLAPI.arrayToCSV(serviceTypes) });
}
/**
* Gets a list of StopPoints within {radius} by the specified criteria
* @param stopTypes a list of stopTypes that should be returned.
* @param radius The radius of the bounding circle in metres (default : 200)
* @param useStopPointHierarchy Re-arrange the output into a parent/child hierarchy.
* @param modes The list of modes to search (e.g. tube, dlr)
* @param categories an optional list of comma separated property categories to return in the StopPoint's property bag. If null or empty, all categories of property are returned. Pass the keyword "none" to return no properties.
* @param returnLines True to return the lines that each stop point serves as a nested resource.
* @param latitude
* @param longitude
*/
getInRadius(
stopTypes: Array<string>,
radius: number = 200,
useStopPointHierarchy: boolean,
modes: Array<string>,
categories: Array<string>,
returnLines: boolean,
latitude: number,
longitude: number
): Promise<TfL['StopPointsResponse']> {
return this.sendRequest(`/StopPoint`, {
stopTypes: TfLAPI.arrayToCSV(stopTypes),
radius,
useStopPointHierarchy,
modes: TfLAPI.arrayToCSV(modes),
categories: TfLAPI.arrayToCSV(categories),
returnLines,
lat: latitude,
lon: longitude
});
}
/**
* Gets a StopPoint for a given sms code.
* @param smsID A 5-digit Countdown Bus Stop Code e.g. 73241, 50435, 56334.
* @param output If set to "web", a 302 redirect to relevant website bus stop page is returned. All other values are ignored.
*/
getBySMSCode(smsID: number, output?: string): Promise<TfL['StopPoint']> {
return this.sendRequest(`/StopPoint/Sms/${smsID}`, { output });
}
/**
* Gets a list of taxi ranks corresponding to the given stop point id
* @param id A StopPoint id (station naptan code e.g. 940GZZLUAS)
*/
getTaxiRanksByID(id: string): Promise<Array<TfL['Place']>> {
return this.sendRequest(`/StopPoint/${id}/TaxiRanks`, {});
}
/**
* Get car parks corresponding to the given stop point id
* @param id A StopPoint id (station naptan code e.g. 940GZZLUAS)
*/
getCarParksByID(id: string): Promise<Array<TfL['Place']>> {
return this.sendRequest(`/StopPoint/${id}/CarParks`, {});
}
}