Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alexbaramilis/72b64819ddd1f9802d80093ea4f6c102 to your computer and use it in GitHub Desktop.
Save alexbaramilis/72b64819ddd1f9802d80093ea4f6c102 to your computer and use it in GitHub Desktop.
AirVisual API's nearest_city endpoint response struct with Decodable
struct AirVisualNearestCityResponse: Decodable {
let status: String
let data: AirVisualNearestCityData
}
struct AirVisualNearestCityData: Decodable {
let city: String
let currentConditions: AirVisualCurrentConditions
}
struct AirVisualCurrentConditions: Decodable {
let weather: AirVisualWeather
let pollution: AirVisualPollution
}
struct AirVisualWeather: Decodable {
let timestamp: String // timestamp: ex. "2018-12-04T18:00:00.000Z" (ISO 8601) (Z stands for UTC)
let iconCode: String // weather icon code: ex. "10n"
let temperature: Int // temperature: ex. 6 (Celsius)
let humidity: Int // humidity: 93 (%)
let pressure: Int // atmospheric pressure: ex. 1022 (hPa)
let windSpeed: Float // wind speed: ex. 2.26 (m/s)
let windDirection: Int // wind direction as an angle of 360° (N=0, E=90, S=180, W=270): ex. 145
}
struct AirVisualPollution: Decodable {
let timestamp: String // timestamp: ex. "2018-12-04T18:00:00.000Z" (ISO 8601) (Z stands for UTC)
let aqiUS: Int // AQI value based on US EPA standard: ex. 4
let mainPollutantUS: String // main pollutant for US AQI: ex. "o3"
let aqiChina: Int // AQI value based on China MEP standard: ex. 3
let mainPollutantChina: String // main pollutant for Chinese AQI: ex. "o3"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment