//native
/**
* Returns air quality data for a single point (geographic name or GPS)
* ## Air quality forecast for a single location
### Location specification
The location of the weather data is the only parameter that is required and must be specified.
*/
export async function main(
auth: RT.Meteosource,
place_id?: string | undefined,
lat?: string | undefined,
lon?: string | undefined,
timezone?: string | undefined,
key?: string | undefined
) {
const url = new URL(`https://www.meteosource.com/api/v1/${auth.tier}/air_quality`)
for (const [k, v] of [
['place_id', place_id],
['lat', lat],
['lon', lon],
['timezone', timezone],
['key', key]
]) {
if (v !== undefined && v !== '') {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
'X-API-Key': auth.apiKey
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 235 days ago