-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathrun.js
35 lines (33 loc) · 979 Bytes
/
run.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
// Load configuation
import * as dotenv from 'dotenv';
dotenv.config()
import { twitch } from './twitch.js';
new twitch();
// exmaple call
setTimeout(() => {
// it should return the rate limit as 799/800
fetch(
"https://api.twitch.tv/helix/users?login=barrycarlyon",
{
method: "GET",
headers: {
"Client-ID": process.env.client_id,
"Authorization": "Bearer " + process.env.access_token
}
}
)
.then(r => r.json().then(data => ({ status: r.status, headers: r.headers, body: data })))
.then(resp => {
if (resp.status != 200) {
console.log('Failed with', resp.status, resp.body);
return;
}
console.log(resp.body, resp.headers.get('ratelimit-remaining'), '/', resp.headers.get('ratelimit-limit'));
})
.catch(err => {
console.error(err);
})
.finally(() => {
process.exit();
});
}, 5000);