Twitch API Helper
The goal of Icehawk is to simplify calls to the
Twitch.tv API. The public repo for
this project can be found at GitLab.
Two API calls are needed to know if a stream is online and for gathering channel
information. This module allows you to use a .twitch()
method - passing in an
array of twitch user names - and returns all the data you would get had you made
API calls to the streams
and channels
endpoints.
Additionally, the returned data object contains named, streamer objects for
easy access to a streamer's data.
{
monstercat: {
channel: { ... },
stream: { ... },
status: 'online'
}
}
Installation
npm install --save icehawk
Usage
const Icehawk = require('icehawk')
const streamers = [
'monstercat',
'nocopyrightsounds'
]
Icehawk.twitch(streamers)
.then(data => {
console.dir(data)
streamers.forEach(streamer => {
const { channel, stream, status } = data[streamer]
})
})
I recommend setting up webpack to create a
bundle.js
file as the entry point into your app.
Simple Webpack Setup
npm install -g webpack webpack-dev-server
In the project's root folder, create webpack.config.js
and index.html
module.exports = {
entry: './app.js',
output: {
path: __dirname,
filename: 'bundle.js'
}
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>Open the developer's console and reload this page to see the output.</p>
<script src="bundle.js"></script>
</body>
</html>
At the prompt in a terminal of the project's root folder, type
$ webpack-dev-server --inline
This will start a local web server at http://localhost:8080
that will auto
reload the page when app.js
is saved with changes.