2021-10-17 18:18:25 +05:30
|
|
|
// import fetch from "node-fetch";
|
|
|
|
|
|
|
|
|
|
export async function getStats(username: string, credentials: string){
|
|
|
|
|
const url = "https://habitica.com/export/userdata.json"
|
2021-10-23 18:06:04 +05:30
|
|
|
const response = await fetch(url, {
|
2021-10-17 18:18:25 +05:30
|
|
|
method: 'GET',
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
2021-10-30 21:10:09 +05:30
|
|
|
"x-client": "278e719e-5f9c-43b1-9dba-8b73343dc062-HabiticaSync",
|
2021-10-17 18:18:25 +05:30
|
|
|
"x-api-user": username,
|
|
|
|
|
"x-api-key": credentials,
|
|
|
|
|
},
|
|
|
|
|
})
|
2021-10-23 18:06:04 +05:30
|
|
|
return (await response)
|
2021-10-17 18:18:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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",
|
2021-10-30 21:10:09 +05:30
|
|
|
"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){
|
2021-10-30 21:10:09 +05:30
|
|
|
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",
|
2021-10-17 18:18:25 +05:30
|
|
|
"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-25 16:49:05 +08:00
|
|
|
const url = "https://habitica.com/api/v4/tasks/user"
|
2021-11-22 23:05:12 +08:00
|
|
|
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-28 22:47:54 +08:00
|
|
|
}
|
|
|
|
|
|
2021-11-29 23:20:09 +08:00
|
|
|
export async function updateTask(username: string, credentials: string, id: string, type: string, title: string, notes: string, coin: string) {
|
2021-11-28 22:47:54 +08:00
|
|
|
const url = "https://habitica.com/api/v4/tasks/".concat(id)
|
|
|
|
|
const response = fetch(url, {
|
|
|
|
|
method: 'PUT',
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
"x-client": "278e719e-5f9c-43b1-9dba-8b73343dc062-HabiticaSync",
|
|
|
|
|
"x-api-user": username,
|
|
|
|
|
"x-api-key": credentials,
|
|
|
|
|
},
|
2021-11-29 23:20:09 +08:00
|
|
|
body: type === 'reward' ? JSON.stringify({id: id,type: type, text: title,notes: notes, coin: coin}):JSON.stringify({id: id,type: type, text: title,notes: notes})
|
2021-11-28 22:47:54 +08:00
|
|
|
})
|
|
|
|
|
return(response)
|
2021-11-22 23:05:12 +08:00
|
|
|
}
|