//native
type Tomorrow = {
apiKey: string;
};
/**
* Weather Recent History
*
*/
export async function main(
auth: Tomorrow,
location: string | undefined,
timesteps: string | undefined,
units: string | undefined,
accept_encoding?: string,
) {
const url = new URL(`https://api.tomorrow.io/v4/weather/history/recent`);
for (const [k, v] of [
["location", location],
["timesteps", timesteps],
["units", units],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
...(accept_encoding ? { "accept-encoding": accept_encoding } : {}),
ApiKey: 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