twitch

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNeedRefresh = errors.New("need refresh")

ErrNeedRefresh is an error indicating that the access token needs to be refreshed. It must be checked using errors.Is.

Functions

func DeleteSubscription

func DeleteSubscription(ctx context.Context, cl Client, tok *oauth2.Token, id string) error

DeleteSubscription calls the Delete EventSub Subscription API to delete a subscription. Requires an app access token for webhook or conduit subscriptions or a user access token for WebSocket subscriptions.

func Shards

func Shards(ctx context.Context, client Client, tok *oauth2.Token, conduit, status string) iter.Seq2[Shard, error]

Shards calls the Get Conduit Shards API to list a conduit's shards. Requires an app access token.

func SubscribeConduit

func SubscribeConduit(ctx context.Context, client Client, tok *oauth2.Token, conduit, sub, version string, condition map[string]string) (string, error)

SubscribeConduit calls the Create EventSub Subscription API for a conduit. Requires an app access token.

func Subscriptions

func Subscriptions(ctx context.Context, cl Client, tok *oauth2.Token, typ string) iter.Seq2[Subscription, error]

Subscriptions yields all EventSub subscriptions associated with a client of a given type. If typ is the empty string, all subscriptions are yielded. Requires an app access token for webhook or conduit subscriptions or a user access token for WebSocket subscriptions.

Types

type Client

type Client struct {
	// HTTP is the HTTP client for performing requests.
	// If nil, http.DefaultClient is used.
	HTTP *http.Client
	// ID is the application's client ID.
	ID string
}

Client holds the context for requests to the Twitch API.

type Conduit

type Conduit struct {
	ID         string `json:"id"`
	ShardCount int    `json:"shard_count"`
}

Conduit is the EventSub API representation of a conduit.

func Conduits

func Conduits(ctx context.Context, client Client, tok *oauth2.Token) ([]Conduit, error)

Conduits calls the Get Conduits API to list conduits owned by the client. Requires an app access token.

func CreateConduit

func CreateConduit(ctx context.Context, client Client, tok *oauth2.Token, shards int) (Conduit, error)

CreateConduit calls the Create Conduits API create a new conduit. Requires an app access token.

func UpdateConduit

func UpdateConduit(ctx context.Context, client Client, tok *oauth2.Token, conduit string, shards int) (Conduit, error)

UpdateConduit calls the Update Conduits API to resize a conduit. Requires an app access token.

type Shard

type Shard struct {
	ID           int             `json:"id,string"`
	Status       string          `json:"status,omitempty"`
	Transport    *ShardTransport `json:"transport,omitempty"`
	Disconnected string          `json:"disconnected_at,omitempty"`
}

Shard is the EventSub API representation of a conduit shard.

func UpdateShards

func UpdateShards(ctx context.Context, client Client, tok *oauth2.Token, conduit string, updates []ShardUpdate) ([]Shard, error)

UpdateShards calls the Update Conduit Shards API to modify transports of conduit shards. Requires an app access token.

type ShardTransport

type ShardTransport struct {
	Method       string `json:"method"`
	Callback     string `json:"callback,omitempty"`
	Session      string `json:"session_id,omitempty"`
	Connected    string `json:"connected_at,omitempty"`
	Disconnected string `json:"disconnected_at,omitempty"`
}

type ShardUpdate

type ShardUpdate struct {
	ID       int
	Method   string
	Callback string
	Secret   string
	Session  string
}

ShardUpdate describes a change to a shard's transport.

type Stream

type Stream struct {
	ID           string    `json:"id"`
	UserID       string    `json:"user_id"`
	UserLogin    string    `json:"user_login"`
	UserName     string    `json:"user_name"`
	GameID       string    `json:"game_id"`
	GameName     string    `json:"game_name"`
	Type         string    `json:"type"`
	Title        string    `json:"title"`
	Tags         []string  `json:"tags"`
	ViewerCount  int       `json:"viewer_count"`
	StartedAt    time.Time `json:"started_at"`
	Language     string    `json:"language"`
	ThumbnailURL string    `json:"thumbnail_url"`
	IsMature     bool      `json:"is_mature"`
}

Stream is the response type from https://dev.twitch.tv/docs/api/reference/#get-streams.

func UserStreams

func UserStreams(ctx context.Context, client Client, tok *oauth2.Token, streams []Stream) ([]Stream, error)

UserStreams gets stream information for a list of up to 100 users. For each stream in the given list, if the user ID is provided, then the query is made by user ID, and otherwise it is made by user login. (NOTE: the ID field is not used as input; only UserID.) Logins used to search are normalized to lower case. The result reuses the memory in streams, but may be of different length and in any order.

If a given stream has both an ID and a login, the ID is used and the login is replaced with the result from the API. If a stream has neither, it is ignored.

type Subscription

type Subscription struct {
	ID        string                `json:"id"`
	Status    string                `json:"status"`
	Type      string                `json:"type"`
	Version   string                `json:"version"`
	Condition SubscriptionCondition `json:"condition"`
	Created   string                `json:"created_at"`
	Transport SubscriptionTransport `json:"transport"`
	Cost      int                   `json:"cost"`
}

type SubscriptionCondition

type SubscriptionCondition struct {
	// Broadcaster is the broadcaster user ID for the condition.
	Broadcaster string `json:"broadcaster_user_id,omitempty"`
	// User is the user ID for the condition.
	User string `json:"user_id,omitempty"`
	// Extra holds any additional fields in the condition.
	Extra jsontext.Value `json:",unknown"`
}

type SubscriptionTransport

type SubscriptionTransport struct {
	Method       string `json:"method"`
	Callback     string `json:"callback,omitempty"`
	Session      string `json:"session,omitempty"`
	Connected    string `json:"connected_at,omitempty"`
	Disconnected string `json:"disconnected_at,omitempty"`
	Conduit      string `json:"conduit_id,omitempty"`
}

type User

type User struct {
	ID              string `json:"id"`
	Login           string `json:"login"`
	DisplayName     string `json:"display_name"`
	Type            string `json:"type"`
	BroadcasterType string `json:"broadcaster_type"`
	Description     string `json:"description"`
	ProfileImageURL string `json:"profile_image_url"`
	OfflineImageURL string `json:"offline_image_url"`
	ViewCount       int    `json:"view_count"`
	Email           string `json:"email"`
	CreatedAt       string `json:"created_at"`
}

User is the response type from https://dev.twitch.tv/docs/api/reference/#get-users.

func Users

func Users(ctx context.Context, client Client, tok *oauth2.Token, users []User) ([]User, error)

Users gets user information for a list of up to 100 users. For each user in the given list, if the ID is provided, then the query is made by ID, and otherwise it is made by login. Logins used to search are normalized to lower case. The result reuses the memory in users, but may be of different length.

If a given user has both an ID and a login, the ID is used and the login is replaced with the result from the API. If a user has neither, it is ignored.

type Validation

type Validation struct {
	ClientID  string   `json:"client_id"`
	Login     string   `json:"login"`
	Scopes    []string `json:"scopes"`
	UserID    string   `json:"user_id"`
	ExpiresIn int      `json:"expires_in"`

	Message string `json:"message"`
	Status  int    `json:"status"`
}

Validation describes an access token's validation status.

func Validate

func Validate(ctx context.Context, client *http.Client, tok *oauth2.Token) (*Validation, error)

Validate checks the status of an access token. If the API response indicates that the access token is invalid, the returned error wraps ErrNeedRefresh. The returned Validation may be non-nil even if the error is also non-nil.

Directories

Path Synopsis
Package eventsub implements low-level EventSub WebSocket operations.
Package eventsub implements low-level EventSub WebSocket operations.

Jump to

Keyboard shortcuts

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