-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch.js
40 lines (32 loc) · 1.06 KB
/
fetch.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
const request = require('request-promise-native');
class UberflipSource {
constructor(grant_type, client_id, client_secret) {
this._grant_type = grant_type;
this._client_id = client_id;
this._client_secret = client_secret;
this.baseURL = 'https://v2.api.uberflip.com';
}
async getAccessToken() {
const url = `${this.baseURL}/authorize?grant_type=${this._grant_type}&client_id=${this._client_id}&client_secret=${this._client_secret}`;
const data = await request.post(url);
return JSON.parse(data)
}
async getStreams(access_token) {
const url = `${this.baseURL}/streams/`;
const data = await request.get(url, {
headers: { Authorization: `Bearer ${access_token}` }
});
return JSON.parse(data)
}
async getStreamItems(access_token, id) {
const url = `${this.baseURL}/streams/${id}/items`;
console.log('getStreamItems id', id)
const data = await request.get(url, {
headers: { Authorization: `Bearer ${access_token}` }
});
return JSON.parse(data)
}
}
module.exports = {
UberflipSource
};