fetchBusPositions static method

Future<List<AdaIncident>> fetchBusPositions(
  1. String apiKey, {
  2. String? stationCode,
})

Implementation

static Future<List<AdaIncident>> fetchBusPositions(
  String apiKey, {
  String? stationCode,
}) async {
  final String host = _buildUrl(
    stationCode: stationCode,
  );

  final response = await http.get(
    Uri.parse(host),
    headers: {"api_key": apiKey},
  );

  Map<String, dynamic> responseArr = readJson(response.body);

  if (responseArr.isEmpty) return [];

  if (responseArr[ApiFields.elevatorIncidents] == null) return [];

  if (responseArr[ApiFields.elevatorIncidents] is List) {
    return ((responseArr[ApiFields.elevatorIncidents] as List?) ?? [])
        .map((adaIncident) => AdaIncident.fromJson(adaIncident))
        .toList();
  }

  return [];
}