-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (33 loc) · 921 Bytes
/
index.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
const axios = require("axios");
class JSONBlobClient {
constructor(blobID) {
this.blobID = blobID;
this.api = axios.create({
baseURL: "https://jsonblob.com"
});
}
setID(blobID) {
this.blobID = blobID;
}
async createBlob(data, setID = true) {
const request = await this.api.post(`/api/jsonBlob/`, data);
const re = /https:\/\/jsonblob.com\/api\/jsonBlob\/(.+)/
const [,blobID] = request.headers.location.match(re);
if(setID) {
this.blobID = blobID;
}
return blobID;
}
async getBlob(blobID) {
const request = await this.api.get(`/api/jsonBlob/${blobID || this.blobID}`);
return request.data;
}
async updateBlob(data, blobID) {
const request = await this.api.put(`/api/jsonBlob/${blobID || this.blobID}`, data);
return request.data;
}
async deleteBlob(blobID) {
await this.api.delete(`/api/jsonBlob/${blobID || this.blobID}`);
}
}
module.exports = JSONBlobClient;