-
Notifications
You must be signed in to change notification settings - Fork 15
/
repl-maker.cjs
26 lines (22 loc) · 878 Bytes
/
repl-maker.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const axios = require('axios').default;
module.exports = class SvelteReplRepository {
constructor(auth) {
if (!auth) {
throw new Error('No auth token')
}
axios.defaults.headers.common.cookie = `sid=${auth};`
axios.defaults.headers.post['Content-Type'] = 'application/json';
axios.defaults.headers.put['Content-Type'] = 'application/json';
}
getAll() {
return axios.get('https://svelte.dev/apps.json').then((response) => response.data);
}
create(name, files) {
return axios.post('https://svelte.dev/repl/create.json', JSON.stringify({ name, files }))
.then((response) => response.data);
}
update(id, name, files) {
return axios.put(`https://svelte.dev/repl/${id}.json`, JSON.stringify({ name, files }))
.then((response) => response.data);
}
}