//native
type Tomorrow = {
apiKey: string;
};
/**
* Retrieve Events (Basic)
*
*/
export async function main(
auth: Tomorrow,
location: string | undefined,
insights: string | undefined,
buffer: string | undefined,
Accept_Encoding?: string,
) {
const url = new URL(`https://api.tomorrow.io/v4/events`);
for (const [k, v] of [
["location", location],
["insights", insights],
["buffer", buffer],
]) {
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