-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpublic_api.js
61 lines (57 loc) · 1.85 KB
/
public_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
var sheep = {
user: {},
dontSleep: function(obj) {
user = obj;
},
post: function(dbName, colName, data) {
const url = user.url + user.id + '/' + dbName + '/' + colName;
const httpReq = new XMLHttpRequest();
httpReq.open('POST', url, true);
httpReq.setRequestHeader('Content-Type', 'application/json');
httpReq.setRequestHeader('Authorization', user.authKey);
httpReq.onreadystatechange = function() {
if (httpReq.readyState === XMLHttpRequest.DONE) {
if (httpReq.status === 200) console.log('POST success!');
else console.log('Mucha problema!!');
}
}
httpReq.send(JSON.stringify(data));
},
get: function(dbName, colName, cb) {
const url = user.url + user.id + '/' + dbName + '/' + colName;
const httpReq = new XMLHttpRequest();
httpReq.open('GET', url, true);
httpReq.setRequestHeader('Authorization', user.authKey);
httpReq.onreadystatechange = function() {
if (httpReq.readyState === XMLHttpRequest.DONE) {
if (httpReq.status === 200) cb(null, httpReq.responseText);
else cb('Mucha problemas!!', null);
}
}
httpReq.send();
},
put: function(dbName, colName, query, data) {
let key = Object.keys(query)[0];
let value = query[key];
axios({
method: 'POST',
url: user.url + user.id + '/' + dbName + '/' + colName + '/?' + key + '=' + value,
data: data,
headers: {
authorization: user.authKey
}
}).then(() => console.log('success'));
},
delete: function(dbName, colName, query) {
let key = Object.keys(query)[0];
let value = query[key];
axios({
method: 'DELETE',
url: user.url + user.id + '/' + dbName + '/' + colName + '/?' + key + '=' + value,
data: data,
headers: {
authorization: user.authKey
}
}).then(() => console.log('success'));
}
}