Browse Source

implement more marvin api

master
Yorick van Pelt 8 months ago
parent
commit
82de5ef468
Signed by: yorick
GPG Key ID: D8D3CC6D951384DE
  1. 46
      Marvin.js
  2. 2
      index.js

46
Marvin.js

@ -17,6 +17,7 @@ class Marvin {
password: c.syncPassword,
pathname: "/" + c.syncDatabase
})
this.credentials = credentials
this.remote = new PouchDB(u.href)
this.db = new PouchDB("marvin")
this.synced = new Promise((resolve, reject) => {
@ -29,6 +30,51 @@ class Marvin {
})
this.root = new Taskset(this, 'root', {})
}
async api(url, data=null) {
const response = await fetch("https://serv.amazingmarvin.com/api/" + url, {
method: data ? "POST" : "GET",
body: data ? JSON.stringify(data) : null,
headers: {
"X-API-Token": this.credentials.apiToken,
'Content-Type': 'application/json',
"Accept": "application/json"
// todo: full access token
}
})
if (response.ok) {
if (response.headers.get('content-type').startsWith("application/json")) {
return response.json()
}
return response.text()
}
else throw [response.status, await response.text()]
}
async test() {
// todo: throw?
return (await this.api("test", {})) == "OK"
}
trackedItem() {
// todo: wrap in Task?
return this.api("trackedItem")
}
todayItems() {
return this.api("todayItems")
}
dueItems() {
return this.api("dueItems")
}
categories() {
return this.api("categories")
}
labels() {
return this.api("labels")
}
me() {
return this.api("me")
}
trackInfo(taskIds) {
return this.api("tracks", { taskIds })
}
}
function chunk(xs, n) {

2
index.js

@ -1,7 +1,7 @@
const Beeminder = require('./Beeminder.js')
const Marvin = require('./Marvin.js')
const fs = require('fs')
const BEEMINDER_TOKEN = fs.readFileSync("./beeminder-token", 'utf8').strip()
const BEEMINDER_TOKEN = fs.readFileSync("./beeminder-token", 'utf8').trim()
const {DateTime, Interval, Duration} = require('luxon')
function sleep(n) {

Loading…
Cancel
Save