//native
/**
* Returns weather data for a single point (geographic name or GPS)
* ## Current weather and forecast for 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,
sections?: string | undefined,
timezone?: string | undefined,
language?: 'cs' | 'en' | 'de' | 'es' | 'fr' | 'pl' | 'pt' | undefined,
units?: 'auto' | 'metric' | 'us' | 'uk' | 'ca' | undefined,
key?: string | undefined
) {
const url = new URL(`https://www.meteosource.com/api/v1/${auth.tier}/point`)
for (const [k, v] of [
['place_id', place_id],
['lat', lat],
['lon', lon],
['sections', sections],
['timezone', timezone],
['language', language],
['units', units],
['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