-
Notifications
You must be signed in to change notification settings - Fork 5
/
fbsync.js
31 lines (29 loc) · 831 Bytes
/
fbsync.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
const Bluebird = require('bluebird');
const fetch = require('node-fetch');
fetch.Promise = Bluebird;
class FirebaseSync {
constructor(config) {
this.config = config;
}
constructUrl(path) {
return `${this.config.databaseURL}/${path}.json?auth=${this.config.secret}`;
}
put(path, data = {}) {
return fetch(this.constructUrl(path), {
headers: {
'Content-Type': 'application/json'
},
method: 'PUT',
body: JSON.stringify(data)
}).then(body => body.json());
}
get(path) {
return fetch(this.constructUrl(path), {
headers: {
'Content-Type': 'application/json'
},
method: 'GET'
}).then(body => body.json());
}
}
module.exports = FirebaseSync;