getAirportWeather method
- AirportCodesByEnum codeType,
- String code, {
- DateTime? fromLocal,
- DateTime? toLocal,
Weather / forecast at the airport TIER 2
What is the current weather at the airport? and What the the weather forecast for the airport? Please note: this endpoint is designed to give a brief simplified weather overview for the airport on-demand. This miscellaneous endpoint is currently not designed to provide extensive weather information and is in no way replacement for specialized weather APIs. Returns: Collection of a single or multiple weather records for the airport, if airport is found and weather information could be retrieved.
Parameters:
-
AirportCodesByEnum codeType (required): Type of code to search airport by (
iataoricao) -
String code (required): If
codeTypeis: *icao, then this field must be a 4-character ICAO-code of the origin airport (e.g.: EHAM, KLAX, UUEE, etc.); *iata, then this field must be a 3-character IATA-code of the origin airport (e.g.: AMS, SFO, LAX, etc.). Full, stripped and any case formats are acceptable. -
DateTime fromLocal: Beginning of the search range (local time, format: YYYY-MM-DDTHH:mm). Must be in range from current time up to 48 hours in future. Default - current time.
-
DateTime toLocal: End of the search range (local time, format: YYYY-MM-DDTHH:mm). Must be equal to or more than beginning of the search range specified in
fromLocal, up to 48 hours in future. Default equal tofromLocal.
Implementation
Future<List<WeatherStateContract>?> getAirportWeather(
AirportCodesByEnum codeType,
String code, {
DateTime? fromLocal,
DateTime? toLocal,
}) async {
final response = await getAirportWeatherWithHttpInfo(
codeType,
code,
fromLocal: fromLocal,
toLocal: toLocal,
);
if (response.statusCode >= HttpStatus.badRequest) {
throw ApiException(response.statusCode, await _decodeBodyBytes(response));
}
// When a remote server returns no body with a status of 204, we shall not decode it.
// At the time of writing this, `dart:convert` will throw an "Unexpected end of input"
// FormatException when trying to decode an empty string.
if (response.body.isNotEmpty &&
response.statusCode != HttpStatus.noContent) {
final responseBody = await _decodeBodyBytes(response);
return (await apiClient.deserializeAsync(
responseBody, 'List<WeatherStateContract>') as List)
.cast<WeatherStateContract>()
.toList(growable: false);
}
return null;
}