Simplifies interacting with Glimesh's API using TypeScript
This package makes it easier to work with the Glimesh API using TypeScript. Inspired by the popular twitch package, I created an interface for Glimesh.
Disclaimer: This is not an official supported by Glimesh! This is more of a clever workaround to make your life easier.
Get User by ID...
let authProvider = new ClientCredentialsAuthProvider("Your-Client-ID", "Your-Client-Secret");
let client = new ApiClient({ authProvider });
client.users.getUserById(2299)
.then(user => {
console.log(`With id => ID: ${user?.id}, Name: ${user?.username}`);
})
.catch(err => {
console.log(err);
});
Get Category by slug...
let authProvider = new ClientCredentialsAuthProvider("Your-Client-ID", "Your-Client-Secret");
let client = new ApiClient({ authProvider });
client.categories.getCategoryBySlug("tech")
.then(category => {
console.log(`With slug => ID: ${category?.id}, Name: ${category?.name}`);
})
.catch(err => {
console.log(err);
});
Get Channel by username...
let authProvider = new ClientCredentialsAuthProvider("Your-Client-ID", "Your-Client-Secret");
let client = new ApiClient({ authProvider });
client.channels.getChannelByName("D4ddyLiLd4rk")
.then(channel => {
console.log(`With id => ID: ${channel?.id}, Streamer: ${channel?.streamer?.username}`);
})
.catch(err => {
console.log(err);
});
Make sure you're running Node v12 and TypeScript 4.2 or higher...
$ node -v
v12.18.4
$ npm install -g typescript tsd
$ tsc -v
Version 4.2.2
Install the glimesh package and the typings definitions for Node.js...
$ npm install glimesh
$ tsd install node
Write some code...
import { RefreshableAuthProvider, StaticAuthProvider, ApiClient, AuthProviderTokens, AuthScopes } from "glimesh";
//let authProvider = new ClientCredentialsAuthProvider("Your_Client_ID", "Your_Client_Secret");
let authProvider = new RefreshableAuthProvider(
new StaticAuthProvider("Your_Client_ID",
"Your_Access_Token",
[AuthScopes.Public, AuthScopes.Email, AuthScopes.Chat, AuthScopes.Streamkey],
AuthProviderTokens.App), {
clientSecret: "Your_Client_Secret",
refreshToken: "Your_Refresh_Token",
onRefresh: ({ accessToken, refreshToken, expiryDate }) => {
}
});
let client = new ApiClient({ authProvider });
Save the above to a file (index.ts), build and run it!
$ tsc index.ts typings/node/node.d.ts --target es6 --module commonjs
$ node index.js
<!doctype html><html ...
To use the sample with your own account, do the following steps:
-
Head over to Glimesh: https://glimesh.tv/
-
Go to Settings
-
Go to Applications
-
Create a new Application or use an existing
-
Copy your Client ID and Secret. DISCLAIMER: Do not share these with anyone!
Special Thanks to the Devs of the Twitch Package for their inspirational code over on GitHub.