1.0.7 • Published 6 years ago

twitch-helix v1.0.7

Weekly downloads
46
License
MIT
Repository
github
Last release
6 years ago

twitch-helix

Little helper class for the new Twitch API described in current Twitch API docs. Transpiled and minified with Babel.

npm Stats

Travis Build Status Dependency Status MIT License

Feel free to contribute by creating issues and pull requests.

Installation

Yarn (recommended)

yarn add twitch-helix

npm

npm install --save twitch-helix

Library Usage

Example

Import the default class from this package and feed its constructor with a client ID and a client secret. You can generate those in your Twitch Developers Dashboard. Try it out on RunKit!

import TwitchHelix from "twitch-helix"
// Or: const TwitchHelix = require("twitch-helix")

const twitchApi = new TwitchHelix({
    clientId: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    clientSecret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
})

twitchApi.getTwitchUserByName("nightbot").then(twitchUser => {
    console.log(twitchUser.display_name) // Prints "Nightbot"
})

Construction

TwitchHelix is a class and you need to create an instance with:

const twitchApi = new TwitchHelix(options)

The options parameter is an object and can have following fields:

FieldInfoDefault value
clientIdClient ID of your Twitch app:no_entry_sign: (required)
clientSecretClient secret of your Twitch app:no_entry_sign: (required)
prematureExpirationTimeTime in ms for the access token to expire before it is meant to (Not implemented yet)10000
autoAuthorizeWill call automatically call authorize() when neededtrue
smartRetryWill retry Twitch API requests up to 10 times if the server response is invalidtrue

Implemented queries

Some of the common queries are wrapped into neat functions. Those are:

PromiseNameParametersReturn ValueFurther info
YesgetTwitchUserByIdstring idTwitch user info object
YesgetTwitchUserByNamestring usernameTwitch user info object
YesgetTwitchUsersByNameArray usernamesArray of Twitch user info objects
YesgetStreamInfoByIdstring idTwitch stream object if user is currently streaming or null otherwise
YesgetStreamInfoByUsernamestring usernameTwitch stream object if user is currently streaming or null otherwise
YesgetFollowDatestring streamerId, string followerIdDate if follower follows streamer or null otherwise

Custom queries

You may need custom queries for retrieving data that is not wrapped into a function yet. Feel free to do so. Some API endpoints are still not implemented by Twitch in Helix API, so you can also use Kraken v5 API.

const helixQueryData = await twitchApi.sendHelixRequest("users?login=nightbot&login=moobot")
const krakenQueryData = await twitchApi.sendApiRequest("users?login=nightbot,moobot", {api: "kraken"})

Events

You can listen to some events.

twitchApi.on(eventName, eventHandler)
Event nameParametersDescription
log-infomessageEmitted on INFO log messages
log-warnmessageEmitted on WARN log messages
log-errormessageEmitted on ERROR log messages

Command Line Usage

Here is an example:

node_modules/.bin/twitch-helix --client-id xxx --client-secret xxx "users?login=nightbot"

This will print: Command Line Output

Use the --kraken flag to query data from a Kraken endpoint instead of a Helix endpoint.

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago