gundyr

package module
v0.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2021 License: BSD-3-Clause, GPL-3.0, ISC Imports: 3 Imported by: 0

README

gundyr

GoDoc Go Report Card

Gundyr provides an easy to use interface to the Helix Twitch API and Twitch PubSub.

It handles both app access as well as user access tokens. All tokens used are automatically refreshed.

This is a work in progress and not all Helix or PubSub endpoints are supported yet.

Install

$ go get github.com/kelr/gundyr

Docs

Documentation can be found at godoc. Examples can be found in the examples directory.

Usage

Helix - Getting a User ID
cfg := &gundyr.HelixConfig{
	ClientID:     clientID, 
	ClientSecret: clientSecret,
}

c, err := gundyr.NewHelix(cfg)
if err != nil {
	log.Fatal(err)
}

userID, err := c.UserToID("kyrotobi")
if err != nil {
	log.Fatal(err)
}
log.Println(userID)
Helix - Using User Access Tokens

If an OAuth2 token is not provided to HelixConfig, authentication will attempt to use the OAuth2 Client Credentials flow to obtain a App Access token.

// See examples/auth_token.go on creating/retrieving tokens.
cfg := &gundyr.HelixConfig{
	ClientID:     clientID,
	ClientSecret: clientSecret,
	Scopes:       []string{"user:read:email"},
	RedirectURI:  redirectURI,
	Token:        token,
}

c, err := gundyr.NewHelix(cfg)
if err != nil {
	log.Fatal(err)
}

email, err := c.GetUserEmail("your-username")
if err != nil {
	log.Fatal(err)
}
log.Println(email)
PubSub - Subscribing to Channel Point Redemptions
func handleChannelPoints(event *pubsub.ChannelPointsEvent) {
	fmt.Println(event.Redemption.Reward.Title)
}

func main() {
	scopes := []string{"channel:read:redemptions"}

	// Setup OAuth2 configuration
	config, err := auth.NewUserAuth(clientID, clientSecret, redirectURI, &scopes)
	if err != nil {
		log.Fatal(err)
	}

	// See examples/auth_token.go for an example on creating a new token.
	token, err := auth.RetrieveTokenFile(config, tokenFile)
	if err != nil {
		log.Fatal(err)
	}

	// Create a PubSub client and listen to the topics.
	client := pubsub.NewClient(userID, token)
	client.ListenChannelPoints(handleChannelPoints)
	client.Connect()
	select {}
}

Contributions

Any and all contributions or bug fixes are appreciated.

Documentation

Overview

Package gundyr provides an interface to access the Helix Twitch API and Twich PubSub.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Helix

type Helix struct {
	// contains filtered or unexported fields
}

Helix is a wrapper over a HelixClient. See https://godoc.org/github.com/kelr/gundyr/helix for the underlying HelixClient.

func NewHelix

func NewHelix(cfg *HelixConfig) (*Helix, error)

NewHelix returns returns a client credentials Helix API client wrapper

func (*Helix) GetAllClips added in v0.2.3

func (c *Helix) GetAllClips(broadcasterID string, after string) ([]helix.GetClipsData, error)

func (*Helix) GetAllVideos added in v0.2.7

func (c *Helix) GetAllVideos(broadcasterID string) ([]helix.GetVideosData, error)

func (*Helix) GetFollowers

func (c *Helix) GetFollowers(userID string) ([]string, error)

GetFollowers returns userIDs for all the users following the provided userID. "Who is following userID?"

func (*Helix) GetUserEmail

func (c *Helix) GetUserEmail(username string) (string, error)

GetUserEmail returns the e-mail address of the user by username. The user access token must have scope user:read:email for the username provided.

func (*Helix) IDToUser

func (c *Helix) IDToUser(userID string) (string, error)

IDToUser converts a user ID string to a username string.

func (*Helix) IDsToUser

func (c *Helix) IDsToUser(userIDs []string) ([]string, error)

IDsToUser converts multiple user ID strings to multiple username strings. Will accept a maximum of 100 IDs. Requests for more than 100 IDs should call this function in chunks.

func (*Helix) UserToID

func (c *Helix) UserToID(username string) (string, error)

UserToID converts a username string to a user ID string.

func (*Helix) ViewCount

func (c *Helix) ViewCount(userID string) (int, error)

ViewCount returns the lifetime viewcount of a user by ID.

type HelixConfig

type HelixConfig struct {
	ClientID     string
	ClientSecret string
	Scopes       []string
	RedirectURI  string
	Token        *oauth2.Token
}

HelixConfig represents configuration options available to a Client.

Directories

Path Synopsis
Package auth provides a wrapper over the oauth2 library with additional helper functions.
Package auth provides a wrapper over the oauth2 library with additional helper functions.
Example to show how to generate a new OAuth2 token using the 3-legged flow.
Example to show how to generate a new OAuth2 token using the 3-legged flow.
Package helix provides a HTTP client to communicate with the Twitch Helix API endpoints.
Package helix provides a HTTP client to communicate with the Twitch Helix API endpoints.
Package pubsub provides a client used to subscribe to updates from the Twitch PubSub endpoints.
Package pubsub provides a client used to subscribe to updates from the Twitch PubSub endpoints.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL