This repository has been archived by the owner on Dec 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlea-api.js
77 lines (70 loc) · 1.93 KB
/
lea-api.js
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Generated by CoffeeScript 1.10.0
(function() {
var DEFAULT_SERVER, fetch, toQueryString;
fetch = require('node-fetch');
DEFAULT_SERVER = "https://leanote.com";
toQueryString = function(data) {
var items;
items = Object.keys(data).map(function(v) {
var value;
value = data[v];
if (typeof value === 'string') {
value = encodeURIComponent(value);
}
return v + "=" + value;
});
return items.join('&');
};
module.exports = function(token, server) {
if (server == null) {
server = DEFAULT_SERVER;
}
return {
addNote: function(title, notebook, content) {
return fetch(server + "/api/note/addNote?token=" + token, {
method: 'POST',
body: toQueryString({
NotebookId: notebook,
Title: title,
IsMarkdown: true,
Content: content
}),
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
}).then(function(res) {
return res.json();
});
},
getNotebooks: function() {
return fetch(server + "/api/notebook/getNotebooks?token=" + token).then(function(res) {
return res.json();
}).then(function(notebooks) {
return notebooks.map(function(notebook) {
return {
id: notebook['NotebookId'],
name: notebook['Title']
};
});
});
}
};
};
module.exports.login = function(email, pwd, server) {
if (server == null) {
server = DEFAULT_SERVER;
}
return fetch(server + "/api/auth/login?email=" + email + "&pwd=" + pwd).then(function(res) {
if (!res.ok) {
throw res.statusText;
}
return res.json();
}).then(function(data) {
if (!data['Ok']) {
throw data['Msg'];
}
return data.Token;
});
};
}).call(this);
//# sourceMappingURL=lea-api.js.map