generated from Lidemy/mentor-program-5th
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhw4.js
39 lines (33 loc) · 826 Bytes
/
hw4.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
const https = require('https')
/* eslint-disable quote-props */
const option = {
hostname: 'api.twitch.tv',
path: '/kraken/games/top',
headers: {
'Accept': 'application/vnd.twitchtv.v5+json',
'Client-ID': 'r0me6woz37936skc3tsuviuipkp9mb'
},
method: 'GET'
}
/* eslint-enable quote-props */
const chunks = []
const req = https.request(option, (res) => {
if (res.statusCode === 503) {
console.log('statusCode:', res.statusCode)
console.log('error to retrieve games status')
return
}
res.on('data', (d) => {
chunks.push(d)
})
res.on('end', () => {
const result = JSON.parse(Buffer.concat(chunks))
result.top.forEach((element) => {
console.log(`${element.viewers} ${element.game.name}`)
})
})
})
req.on('error', (error) => {
console.error(error)
})
req.end()