Public Access
feat(api_handler): return proper objects using transport_helper
many "changes" due to formatter :/
This commit is contained in:
+98
-62
@@ -20,50 +20,66 @@ class ApiHandler {
|
||||
// - [ ] journeyDetails
|
||||
|
||||
//static Future<Map<String, dynamic>> findStations(String locationName) async {
|
||||
static Future<List<String>> findStations(String locationName, {int? maxStations=5}) async {
|
||||
static Future<List<Station>> findStations(
|
||||
String locationName, {
|
||||
int? maxStations = 5,
|
||||
}) async {
|
||||
String urlPath = '/api/fahrinfo/latest/location.name';
|
||||
Uri url = Uri.https(baseUrl, urlPath, {
|
||||
'accessId': accessID,
|
||||
'input': locationName,
|
||||
'maxNo': maxStations.toString(),
|
||||
'type': 'S' // Station/Stops only
|
||||
'type': 'S', // Station/Stops only
|
||||
});
|
||||
//print(url);
|
||||
var jsonResponse = await http.get(url,
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
});
|
||||
final httpPackageJson = json.decode(jsonResponse.body) as Map<String, dynamic>;
|
||||
var jsonResponse = await http.get(
|
||||
url,
|
||||
headers: {'Accept': 'application/json'},
|
||||
);
|
||||
final httpPackageJson =
|
||||
json.decode(jsonResponse.body) as Map<String, dynamic>;
|
||||
//print(httpPackageJson["stopLocationOrCoordLocation"]);
|
||||
final idList = httpPackageJson["stopLocationOrCoordLocation"].map( (x) => x["StopLocation"]["id"]);
|
||||
//print("and now just ids: ");
|
||||
//print(id);
|
||||
return idList;
|
||||
List<Station> stationList = httpPackageJson["stopLocationOrCoordLocation"]
|
||||
.map(
|
||||
(x) => Station.fromJson(x["StopLocation"]),
|
||||
)
|
||||
.toList()
|
||||
.cast<Station>();
|
||||
return stationList;
|
||||
}
|
||||
|
||||
static Future<List<String>> nearbyStations(String latitude, String longitude,
|
||||
{int? maxStations=5}) async {
|
||||
static Future<List<Station>> nearbyStations(
|
||||
String latitude,
|
||||
String longitude, {
|
||||
int? maxStations = 5,
|
||||
}) async {
|
||||
String urlPath = '/api/fahrinfo/latest/location.nearbystops';
|
||||
Uri url = Uri.https(baseUrl, urlPath, {
|
||||
'accessId': accessID,
|
||||
'originCoordLat': latitude,
|
||||
'originCoordLong': longitude,
|
||||
'maxNo': maxStations.toString(),
|
||||
'type': 'S' // Station/Stops only
|
||||
'type': 'S', // Station/Stops only
|
||||
});
|
||||
var jsonResponse = await http.get(url,
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
});
|
||||
final httpPackageJson = json.decode(jsonResponse.body) as Map<String, dynamic>;
|
||||
final idList = httpPackageJson["stopLocationOrCoordLocation"].map( (x) => x["StopLocation"]["id"]);
|
||||
return idList;
|
||||
var jsonResponse = await http.get(
|
||||
url,
|
||||
headers: {'Accept': 'application/json'},
|
||||
);
|
||||
final httpPackageJson =
|
||||
json.decode(jsonResponse.body) as Map<String, dynamic>;
|
||||
final stationList = httpPackageJson["stopLocationOrCoordLocation"].map(
|
||||
(x) => Station.fromJson(x["StopLocation"]),
|
||||
);
|
||||
return stationList;
|
||||
}
|
||||
|
||||
static Future<List<String>> departures(String station,
|
||||
{int? maxDepartures=-1, int? duration=-1}) async {
|
||||
static Future<List<Departure>> departures(
|
||||
String stationId, {
|
||||
int? maxDepartures = -1,
|
||||
int? duration = 0,
|
||||
}) async {
|
||||
String urlPath = '/api/fahrinfo/latest/departureBoard';
|
||||
String stationString = station.replaceAll(' ', '%20'); // reform for URL
|
||||
String stationString = stationId.replaceAll(' ', '%20'); // reform for URL
|
||||
|
||||
Uri url = Uri.https(baseUrl, urlPath, {
|
||||
'accessId': accessID,
|
||||
@@ -71,19 +87,39 @@ class ApiHandler {
|
||||
////'time': /current time //time from which departures will be shown
|
||||
'duration': duration.toString(), //interval time in minutes
|
||||
'maxJourneys': maxDepartures.toString(),
|
||||
'type': 'S' // Station/Stops only
|
||||
//'type': 'S', // Station/Stops only
|
||||
});
|
||||
var jsonResponse = await http.get(url,
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
});
|
||||
final httpPackageJson = json.decode(jsonResponse.body) as Map<String, dynamic>;
|
||||
final idList = httpPackageJson["Departure"].map( (x) => x["ProductAtStop"]["num"]);
|
||||
return idList;
|
||||
var jsonResponse = await http.get(
|
||||
url,
|
||||
headers: {'Accept': 'application/json'},
|
||||
);
|
||||
final httpPackageJson =
|
||||
json.decode(jsonResponse.body) as Map<String, dynamic>;
|
||||
|
||||
// try {
|
||||
List<Departure> departureList = httpPackageJson["Departure"]
|
||||
.map(
|
||||
(x) => Departure.fromJson(x),
|
||||
)
|
||||
.toList()
|
||||
.cast<Departure>();
|
||||
return departureList;
|
||||
// } catch (e) {
|
||||
// // TODO: logging
|
||||
// // empty response
|
||||
// print('Error: $e');
|
||||
// // print(
|
||||
// // 'Response for Station-id "$stationString" contains no field "Departure": $httpPackageJson',
|
||||
// // );
|
||||
// return [];
|
||||
// }
|
||||
}
|
||||
|
||||
static Future<List<String>> departuresAggregate(List<String> stationList,
|
||||
{int? maxDepartures=-1, int? duration=-1}) async {
|
||||
static Future<List<Departure>> departuresAggregate(
|
||||
List<String> stationList, {
|
||||
int? maxDepartures = -1,
|
||||
int? duration = -1,
|
||||
}) async {
|
||||
String urlPath = '/api/fahrinfo/latest/multiDepartureBoard';
|
||||
String stationListString = stationList
|
||||
.reduce((value, element) => value + '|' + element)
|
||||
@@ -95,21 +131,23 @@ class ApiHandler {
|
||||
////'time': /current time //time from which departures will be shown
|
||||
'duration': duration.toString(), //interval time in minutes
|
||||
'maxJourneys': maxDepartures.toString(),
|
||||
'type': 'S' // Station/Stops only
|
||||
'type': 'S', // Station/Stops only
|
||||
});
|
||||
var jsonResponse = await http.get(url,
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
});
|
||||
final httpPackageJson = json.decode(jsonResponse.body) as Map<String, dynamic>;
|
||||
final idList = httpPackageJson["Departure"].map( (x) => x["ProductAtStop"]["num"]);
|
||||
return idList;
|
||||
var jsonResponse = await http.get(
|
||||
url,
|
||||
headers: {'Accept': 'application/json'},
|
||||
);
|
||||
final httpPackageJson =
|
||||
json.decode(jsonResponse.body) as Map<String, dynamic>;
|
||||
List<Departure> departureList = httpPackageJson["Departure"].map(
|
||||
(x) => Departure.fromJson(x),
|
||||
);
|
||||
return departureList;
|
||||
}
|
||||
|
||||
static Future<List<String>> trip(
|
||||
String originId,
|
||||
String destinationId,
|
||||
{
|
||||
String destinationId, {
|
||||
String? via,
|
||||
String? viaID,
|
||||
String? date,
|
||||
@@ -133,31 +171,28 @@ class ApiHandler {
|
||||
////'time': /current time //time from which departures will be shown
|
||||
'time': time.toString(), //interval time in minutes
|
||||
'maxChange': maxChange.toString(),
|
||||
'type': 'S' // Station/Stops only
|
||||
'type': 'S', // Station/Stops only
|
||||
});
|
||||
var jsonResponse = await http.get(url,
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
});
|
||||
final httpPackageJson = json.decode(jsonResponse.body) as Map<String, dynamic>;
|
||||
var jsonResponse = await http.get(
|
||||
url,
|
||||
headers: {'Accept': 'application/json'},
|
||||
);
|
||||
final httpPackageJson =
|
||||
json.decode(jsonResponse.body) as Map<String, dynamic>;
|
||||
final idList = httpPackageJson["Trip"].map(
|
||||
(x) => x["LegList"]["Leg"].map(
|
||||
(y) => y["JourneyDetail"]["ref"])
|
||||
(x) => x["LegList"]["Leg"].map((y) => y["JourneyDetail"]["ref"]),
|
||||
);
|
||||
return idList;
|
||||
|
||||
}
|
||||
|
||||
static Future<List<String>> tripDetail(
|
||||
String id,
|
||||
{
|
||||
String id, {
|
||||
String? date,
|
||||
String? fromId,
|
||||
int? fromIdx,
|
||||
String? toId,
|
||||
int? toIdx
|
||||
int? toIdx,
|
||||
}) async {
|
||||
|
||||
String urlPath = '/api/fahrinfo/latest/journeyDetail';
|
||||
Uri url = Uri.https(baseUrl, urlPath, {
|
||||
'accessId': accessID,
|
||||
@@ -165,11 +200,12 @@ class ApiHandler {
|
||||
'fromId': fromId,
|
||||
'toId': toId,
|
||||
});
|
||||
var jsonResponse = await http.get(url,
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
});
|
||||
final httpPackageJson = json.decode(jsonResponse.body) as Map<String, dynamic>;
|
||||
var jsonResponse = await http.get(
|
||||
url,
|
||||
headers: {'Accept': 'application/json'},
|
||||
);
|
||||
final httpPackageJson =
|
||||
json.decode(jsonResponse.body) as Map<String, dynamic>;
|
||||
final idList = httpPackageJson["Stops"]["Stop"].map((x) => x["id"]);
|
||||
return idList;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user