icehawk v1.0.9
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.
// example
{
monstercat: {
channel: { ... },
stream: { ... },
status: 'online'
}
}
Installation
npm install --save icehawk
Usage
// app.js
const Icehawk = require('icehawk')
// 24/7 music streamers
const streamers = [
'monstercat',
'nocopyrightsounds'
]
Icehawk.twitch(streamers)
.then(data => {
// see how the data is structured
console.dir(data)
// iterate over each streamer and get their data
streamers.forEach(streamer => {
// data contains named objects matching streamer's name
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
// webpack.config.js
module.exports = {
entry: './app.js',
output: {
path: __dirname,
filename: 'bundle.js'
}
}
<!-- index.html -->
<!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.