habitica-sync/src/view/habiticaAPI.ts

86 lines
2.9 KiB
TypeScript
Raw Normal View History

// import fetch from "node-fetch";
export async function getStats(username: string, credentials: string){
const url = "https://habitica.com/export/userdata.json"
const response = await fetch(url, {
method: 'GET',
headers: {
"Content-Type": "application/json",
"x-client": "278e719e-5f9c-43b1-9dba-8b73343dc062-HabiticaSync",
"x-api-user": username,
"x-api-key": credentials,
},
})
return (await response)
}
export async function scoreTask(username: string, credentials: string, taskID: string, direction: string) {
const url = "https://habitica.com/api/v3/tasks/".concat(taskID).concat("/score/").concat(direction)
const response = fetch(url, {
method: 'POST',
headers: {
"Content-Type": "application/json",
"x-client": "278e719e-5f9c-43b1-9dba-8b73343dc062-HabiticaSync",
"x-api-user": username,
"x-api-key": credentials,
}
})
return(response)
}
2021-10-30 22:34:41 +05:30
export async function makeCronReq(username: string, credentials: string){
const url = "https://habitica.com/api/v3/cron";
const response = fetch(url, {
method: 'POST',
headers: {
"Content-Type": "application/json",
"x-client": "278e719e-5f9c-43b1-9dba-8b73343dc062-HabiticaSync",
"x-api-user": username,
"x-api-key": credentials,
}
})
return(response)
2021-11-18 14:16:20 +08:00
}
export async function costReward(username: string, credentials: string, taskID: string, direction: string) {
const url = "https://habitica.com/api/v4/tasks/".concat(taskID).concat("/score/").concat(direction)
const response = fetch(url, {
method: 'POST',
headers: {
"Content-Type": "application/json",
"x-client": "278e719e-5f9c-43b1-9dba-8b73343dc062-HabiticaSync",
"x-api-user": username,
"x-api-key": credentials,
}
})
return(response)
}
2021-11-22 23:05:12 +08:00
2021-11-23 20:11:19 +08:00
export async function addTask(username: string, credentials: string, title: string, type: string) {
2021-11-22 23:05:12 +08:00
const url = "https://habitica.com/api/v4/tasks/user".concat(title)
const response = fetch(url, {
method: 'POST',
headers: {
"Content-Type": "application/json",
"x-client": "278e719e-5f9c-43b1-9dba-8b73343dc062-HabiticaSync",
"x-api-user": username,
"x-api-key": credentials,
},
2021-11-23 20:11:19 +08:00
body: JSON.stringify({type: type, text: title})
2021-11-22 23:05:12 +08:00
})
return(response)
2021-11-23 23:00:47 +08:00
}
export async function deleteTask(username: string, credentials: string, id: string) {
const url = "https://habitica.com/api/v4/tasks/".concat(id)
const response = fetch(url, {
method: 'DELETE',
headers: {
"Content-Type": "application/json",
"x-client": "278e719e-5f9c-43b1-9dba-8b73343dc062-HabiticaSync",
"x-api-user": username,
"x-api-key": credentials,
}
})
return(response)
2021-11-22 23:05:12 +08:00
}