Files
monitor-im-flur/src/api/flatastic.ts

56 lines
1.2 KiB
TypeScript

class Flatastic {
private apikey: string;
constructor(apikey: string) {
this.apikey = apikey;
}
async request(url: string, option: any) {
const headers = {
accept: "application/json, text/plain, */*",
"accept-language":
"de-CH,de;q=0.9,en-US;q=0.8,en-CH;q=0.7,en;q=0.6,ar-JO;q=0.5,ar;q=0.4,de-DE;q=0.3",
// "cache-control": "no-cache",
// "pragma": "no-cache",
// "sec-fetch-dest": "empty",
// "sec-fetch-mode": "cors",
// "sec-fetch-site": "same-site",
"x-api-key": this.apikey,
"x-api-version": "2.0.0",
"x-client-version": "2.3.20",
};
const response = await fetch(url, {
...option,
headers: {
...headers,
...option.headers,
},
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
}
getShoppingList() {
return this.request(
"https://api.flatastic-app.com/index.php/api/shoppinglist",
{},
);
}
getTaskList() {
return this.request(
"https://api.flatastic-app.com/index.php/api/chores",
{},
);
}
getInformation() {
this.request("https://api.flatastic-app.com/index.php/api/wg", {});
}
}
export { Flatastic };
export default Flatastic;