UNPKG

twitch-toolkit

Version:

A set of tools to integrate with Twitch API, Twitch Chat and Twitch WebHooks.

1,829 lines (549 loc) β€’ 27.4 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>TwitchApi - Documentation</title> <script src="scripts/prettify/prettify.js"></script> <script src="scripts/prettify/lang-css.js"></script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css"> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger" class="navicon-button x"> <div class="navicon"></div> </label> <label for="nav-trigger" class="overlay"></label> <nav> <li class="nav-link nav-home-link"><a href="index.html">Home</a></li><li class="nav-heading">Classes</li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="TwitchApi.html">TwitchApi</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getAccessToken">getAccessToken</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getGames">getGames</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getStreams">getStreams</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getStreamsMetadata">getStreamsMetadata</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getUsers">getUsers</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getUsersFollows">getUsersFollows</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getVideos">getVideos</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#isLive">isLive</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#updateUser">updateUser</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#validateAccessToken">validateAccessToken</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="TwitchChatEmitter.html">TwitchChatEmitter</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchChatEmitter.html#connect">connect</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="TwitchWebhook.html">TwitchWebhook</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebhook.html#destroy">destroy</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebhook.html#handleRequest">handleRequest</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebhook.html#subscribe">subscribe</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebhook.html#topicStreamUpDownSubscribe">topicStreamUpDownSubscribe</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebhook.html#topicUserFollowsSubscribe">topicUserFollowsSubscribe</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebhook.html#unsubscribe">unsubscribe</a></span></li><li class="nav-heading">Events</li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="TwitchChatEmitter.html#event:Chat:chat_parsed">Chat:chat_parsed</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="TwitchWebhook.html#event:Webhook:stream_up_down">Webhook:stream_up_down</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="TwitchWebhook.html#event:Webhook:user_follows">Webhook:user_follows</a></span></li> </nav> <div id="main"> <h1 class="page-title">TwitchApi</h1> <section> <header> <h2> TwitchApi </h2> </header> <article> <div class="container-overview"> <div class="section-method"> <h4 class="name" id="TwitchApi"><span class="type-signature"></span>new TwitchApi<span class="signature">(config)</span><span class="type-signature"></span></h4> <div class="description"> <p>Twitch API</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchApi.js.html">twitchApi.js</a>, <a href="twitchApi.js.html#line14">line 14</a> </li></ul></dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>config</code></td> <td class="type"> <span class="param-type"><code>object</code></span> </td> <td class="description last"> <p>The configuration object to access the API.</p> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>clientId</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The client id to be used to access the API.</p> </td> </tr> <tr> <td class="name"><code>clientSecret</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The secret to be used to access the API that requires login. If this is not provided, the restricted methods will thrown an error.</p> </td> </tr> <tr> <td class="name"><code>logger</code></td> <td class="type"> <span class="param-type"><code>object</code></span> </td> <td class="description last"> <p>The logger object.</p> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </div> </div> <h3 class="subsection-title">Methods</h3> <div class="section-method"> <h4 class="name" id="getAccessToken"><span class="type-signature"></span>getAccessToken<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> <p>Authenticate the current user and get the access token to be used in the private calls.</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchApi.js.html">twitchApi.js</a>, <a href="twitchApi.js.html#line194">line 194</a> </li></ul></dd> </dl> <div class="section-returns"> <h5>Returns:</h5> <div class="param-desc"> <p>The access token.</p> </div> </div> </div> <div class="section-method"> <h4 class="name" id="getGames"><span class="type-signature"></span>getGames<span class="signature">(options)</span><span class="type-signature"> &rarr; {Promise.&lt;Array.&lt;Object>>}</span></h4> <div class="description"> <p>Gets a Twitch game information by game ID or name. For a query to be valid, name and/or id must be specified. This method requires no authentication.</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchApi.js.html">twitchApi.js</a>, <a href="twitchApi.js.html#line63">line 63</a> </li></ul></dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type"><code>object</code></span> </td> <td class="description last"> <p>The parameters to the api call. The parameter object is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-games</p> </td> </tr> </tbody> </table> <div class="section-returns"> <h5>Returns:</h5> <dl class="param-type"> <dt> Type: </dt> <dd> <span class="param-type"><code>Promise.&lt;Array.&lt;Object>></code></span> </dd> </dl> <div class="param-desc"> <p>The data object in the API response. The response is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-games</p> </div> </div> </div> <div class="section-method"> <h4 class="name" id="getStreams"><span class="type-signature"></span>getStreams<span class="signature">(options)</span><span class="type-signature"> &rarr; {Promise.&lt;Array.&lt;Object>>}</span></h4> <div class="description"> <p>Gets information about active streams. Streams are returned sorted by number of current viewers, in descending order. Across multiple pages of results, there may be duplicate or missing streams, as viewers join and leave streams. This method requires no authentication.</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchApi.js.html">twitchApi.js</a>, <a href="twitchApi.js.html#line82">line 82</a> </li></ul></dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type"><code>object</code></span> </td> <td class="description last"> <p>The parameters to the api call. The parameter object is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-streams</p> </td> </tr> </tbody> </table> <div class="section-returns"> <h5>Returns:</h5> <dl class="param-type"> <dt> Type: </dt> <dd> <span class="param-type"><code>Promise.&lt;Array.&lt;Object>></code></span> </dd> </dl> <div class="param-desc"> <p>The data object in the API response. The response is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-streams</p> </div> </div> </div> <div class="section-method"> <h4 class="name" id="getStreamsMetadata"><span class="type-signature"></span>getStreamsMetadata<span class="signature">(options)</span><span class="type-signature"> &rarr; {Promise.&lt;Array.&lt;Object>>}</span></h4> <div class="description"> <p>Gets metadata information about active streams playing Overwatch or Hearthstone. Streams are sorted by number of current viewers, in descending order. Across multiple pages of results, there may be duplicate or missing streams, as viewers join and leave streams.</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchApi.js.html">twitchApi.js</a>, <a href="twitchApi.js.html#line100">line 100</a> </li></ul></dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type"><code>object</code></span> </td> <td class="description last"> <p>The parameters to the api call. The parameter object is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-streams-metadata</p> </td> </tr> </tbody> </table> <div class="section-returns"> <h5>Returns:</h5> <dl class="param-type"> <dt> Type: </dt> <dd> <span class="param-type"><code>Promise.&lt;Array.&lt;Object>></code></span> </dd> </dl> <div class="param-desc"> <p>The data object in the API response. The response is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-streams-metadata</p> </div> </div> </div> <div class="section-method"> <h4 class="name" id="getUsers"><span class="type-signature"></span>getUsers<span class="signature">(options)</span><span class="type-signature"> &rarr; {Promise.&lt;Array.&lt;Object>>}</span></h4> <div class="description"> <p>Gets information about one or more specified Twitch users. Users are identified by optional user IDs and/or login name. If neither a user ID nor a login name is specified, the user is looked up by Bearer token.</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchApi.js.html">twitchApi.js</a>, <a href="twitchApi.js.html#line121">line 121</a> </li></ul></dd> <dt class="tag-todo">To Do:</dt> <dd class="tag-todo"> <ul> <li>add optional scope</li> </ul> </dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type"><code>object</code></span> </td> <td class="description last"> <p>The parameters to the api call. The parameter object is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-users</p> </td> </tr> </tbody> </table> <div class="section-returns"> <h5>Returns:</h5> <dl class="param-type"> <dt> Type: </dt> <dd> <span class="param-type"><code>Promise.&lt;Array.&lt;Object>></code></span> </dd> </dl> <div class="param-desc"> <p>The data object in the API response. The response is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-users</p> </div> </div> </div> <div class="section-method"> <h4 class="name" id="getUsersFollows"><span class="type-signature"></span>getUsersFollows<span class="signature">(options)</span><span class="type-signature"> &rarr; {Promise.&lt;Array.&lt;Object>>}</span></h4> <div class="description"> <p>Gets information on follow relationships between two Twitch users. Information returned is sorted in order, most recent follow first. This can return information like &quot;who is lirik following,&quot; &quot;who is following lirik,” or β€œis user X following user Y.” This method requires no authentication.</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchApi.js.html">twitchApi.js</a>, <a href="twitchApi.js.html#line140">line 140</a> </li></ul></dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type"><code>object</code></span> </td> <td class="description last"> <p>The parameters to the api call. The parameter object is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-users-follows</p> </td> </tr> </tbody> </table> <div class="section-returns"> <h5>Returns:</h5> <dl class="param-type"> <dt> Type: </dt> <dd> <span class="param-type"><code>Promise.&lt;Array.&lt;Object>></code></span> </dd> </dl> <div class="param-desc"> <p>The data object in the API response. The response is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-users-follows</p> </div> </div> </div> <div class="section-method"> <h4 class="name" id="getVideos"><span class="type-signature"></span>getVideos<span class="signature">(options)</span><span class="type-signature"> &rarr; {Promise.&lt;Array.&lt;Object>>}</span></h4> <div class="description"> <p>Gets video information by video ID (one or more), user ID (one only), or game ID (one only). This method requires no authentication.</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchApi.js.html">twitchApi.js</a>, <a href="twitchApi.js.html#line159">line 159</a> </li></ul></dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type"><code>object</code></span> </td> <td class="description last"> <p>The parameters to the api call. The parameter object is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-videos</p> </td> </tr> </tbody> </table> <div class="section-returns"> <h5>Returns:</h5> <dl class="param-type"> <dt> Type: </dt> <dd> <span class="param-type"><code>Promise.&lt;Array.&lt;Object>></code></span> </dd> </dl> <div class="param-desc"> <p>The data object in the API response. The response is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-videos</p> </div> </div> </div> <div class="section-method"> <h4 class="name" id="isLive"><span class="type-signature"></span>isLive<span class="signature">()</span><span class="type-signature"> &rarr; {bool}</span></h4> <div class="description"> <p>Check if the stream is live.</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchApi.js.html">twitchApi.js</a>, <a href="twitchApi.js.html#line24">line 24</a> </li></ul></dd> </dl> <div class="section-returns"> <h5>Returns:</h5> <dl class="param-type"> <dt> Type: </dt> <dd> <span class="param-type"><code>bool</code></span> </dd> </dl> <div class="param-desc"> <p>True if the stream is live and false otherwise.</p> </div> </div> </div> <div class="section-method"> <h4 class="name" id="updateUser"><span class="type-signature"></span>updateUser<span class="signature">(description)</span><span class="type-signature"> &rarr; {Promise.&lt;Array.&lt;Object>>}</span></h4> <div class="description"> <p>Updates the description of the authenticated user. This method requires authentication.</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchApi.js.html">twitchApi.js</a>, <a href="twitchApi.js.html#line178">line 178</a> </li></ul></dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>description</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The description to be added to the channel.</p> </td> </tr> </tbody> </table> <div class="section-returns"> <h5>Returns:</h5> <dl class="param-type"> <dt> Type: </dt> <dd> <span class="param-type"><code>Promise.&lt;Array.&lt;Object>></code></span> </dd> </dl> <div class="param-desc"> <p>The data object in the API response. The response is defined in the Twitch documentation: https://dev.twitch.tv/docs/api/reference#get-videos</p> </div> </div> </div> <div class="section-method"> <h4 class="name" id="validateAccessToken"><span class="type-signature"></span>validateAccessToken<span class="signature">(token)</span><span class="type-signature"> &rarr; {Promise.&lt;Array.&lt;Object>>}</span></h4> <div class="description"> <p>Validate the access token to make sure it is still valid.</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchApi.js.html">twitchApi.js</a>, <a href="twitchApi.js.html#line40">line 40</a> </li></ul></dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>token</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The token to be validated</p> </td> </tr> </tbody> </table> <div class="section-returns"> <h5>Returns:</h5> <dl class="param-type"> <dt> Type: </dt> <dd> <span class="param-type"><code>Promise.&lt;Array.&lt;Object>></code></span> </dd> </dl> <div class="param-desc"> <p>The data object in the API response. The response is defined in the Twitch documentation: https://dev.twitch.tv/docs/authentication/#validating-requests</p> </div> </div> </div> </article> </section> </div> <br class="clear"> <footer> Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Fri Aug 17 2018 18:58:48 GMT-0300 (E. South America Standard Time) using the Minami theme. </footer> <script>prettyPrint();</script> <script src="scripts/linenumber.js"></script> </body> </html>