helix

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2020 License: MIT Imports: 12 Imported by: 0

README

helix

A Twitch Helix API client written in Go (Golang).

Build Status Coverage Status

Package Status

This project is a work in progress. Twitch has not finished all available endpoints/features for the Helix API, but as these get released they are likely to be implemented in this package.

Documentation & Examples

All documentation and usage examples for this package can be found in the docs directory. If you are looking for the Twitch API docs, see the Twitch Developer website.

Supported Endpoints & Features

Authentication:

  • Generate Authorization URL ("code" or "token" authorization)
  • Get App Access Tokens (OAuth Client Credentials Flow)
  • Get User Access Tokens (OAuth Authorization Code Flow)
  • Refresh User Access Tokens
  • Revoke User Access Tokens
  • Validate Access Token

API Endpoint:

  • Get Bits Leaderboard
  • Get Clip
  • Create Clip
  • Create Entitlement Grants Upload URL
  • Get Games
  • Get Top Games
  • Get Extension Analytics
  • Get Game Analytics
  • Get Streams
  • Get Streams Metadata
  • Create Stream Marker
  • Get Stream Markers
  • Get Users
  • Get Users Follows
  • Update User
  • Get Videos
  • Get Webhook Subscriptions

Quick Usage Example

This is a quick example of how to get users. Note that you don't need to provide both a list of ids and logins, one or the other will suffice.

client, err := helix.NewClient(&helix.Options{
    ClientID: "your-client-id",
})
if err != nil {
    // handle error
}

resp, err := client.GetUsers(&helix.UsersParams{
    IDs:    []string{"26301881", "18074328"},
    Logins: []string{"summit1g", "lirik"},
})
if err != nil {
    // handle error
}

fmt.Printf("Status code: %d\n", resp.StatusCode)
fmt.Printf("Rate limit: %d\n", resp.GetRateLimit())
fmt.Printf("Rate limit remaining: %d\n", resp.GetRateLimitRemaining())
fmt.Printf("Rate limit reset: %d\n\n", resp.GetRateLimitReset())

for _, user := range resp.Data.Users {
    fmt.Printf("ID: %s Name: %s\n", user.ID, user.DisplayName)
}

Output:

Status code: 200
Rate limit: 30
Rate limit remaining: 29
Rate limit reset: 1517695315

ID: 26301881 Name: sodapoppin
ID: 18074328 Name: destiny
ID: 26490481 Name: summit1g
ID: 23161357 Name: lirik

Contributions

PRs are very much welcome. Where possible, please write tests for any code that is introduced by your PRs.

License

This package is distributed under the terms of the MIT License.

Documentation

Index

Constants

View Source
const (
	// DefaultAPIBaseURL is the base URL for composing API requests.
	DefaultAPIBaseURL = "https://api.twitch.tv/helix"

	// AuthBaseURL is the base URL for composing authentication requests.
	AuthBaseURL = "https://id.twitch.tv/oauth2"
)

Variables

View Source
var (
	UserFollowsRegexp        = regexp.MustCompile("helix/users/follows\\?first=1(&from_id=(?P<from_id>\\d+))?(&to_id=(?P<to_id>\\d+))?>")
	StreamChangedRegexp      = regexp.MustCompile("helix/streams\\?user_id=(?P<user_id>\\d+)>")
	UserChangedRegexp        = regexp.MustCompile("helix/users\\?id=(?P<id>\\d+)>")
	GameAnalyticsRegexp      = regexp.MustCompile("helix/analytics\\?game_id=(?P<game_id>\\w+)>")
	ExtensionAnalyticsRegexp = regexp.MustCompile("helix/analytics\\?extension_id=(?P<extension_id>\\w+)>")
)

Regular expressions used for parsing webhook link headers

Functions

func GetWebhookTopicValuesFromRequest added in v0.4.2

func GetWebhookTopicValuesFromRequest(req *http.Request, topic WebhookTopic) map[string]string

GetWebhookTopicValuesFromRequest inspects the "Link" request header to determine if it matches against any recognised webhooks topics and returns the unique values specified in the header.

For example, say we receive a "User Follows" webhook event from Twitch. Its "Link" header value look likes the following:

<https://api.twitch.tv/helix/webhooks/hub>; rel="hub", <https://api.twitch.tv/helix/users/follows?first=1&from_id=111116&to_id=22222>; rel="self"

From which GetWebhookTopicValuesFromRequest will return a map with the values of from_id and to_id:

map[from_id:111116 to_id:22222]

This is particularly useful for webhooks events that do not have a distinguishable JSON payload, such as the "Stream Changed" down event.

Additionally, if topic is not known you can pass -1 as its value and

Types

type AccessCredentials added in v0.7.0

type AccessCredentials struct {
	AccessToken  string   `json:"access_token"`
	RefreshToken string   `json:"refresh_token"`
	ExpiresIn    int      `json:"expires_in"`
	Scopes       []string `json:"scope"`
}

AccessCredentials ...

type AppAccessTokenResponse

type AppAccessTokenResponse struct {
	ResponseCommon
	Data AccessCredentials
}

AppAccessTokenResponse ...

type AuthorizationURLParams added in v0.7.0

type AuthorizationURLParams struct {
	ResponseType string   // (Required) Options: "code" or "token"
	Scopes       []string // (Required)
	State        string   // (Optional)
	ForceVerify  bool     // (Optional)
}

AuthorizationURLParams ...

type Ban added in v0.5.5

type Ban struct {
	UserID    string `json:"user_id"`
	UserName  string `json:"user_name"`
	ExpiresAt Time   `json:"expires_at"`
}

Ban ... ExpiresAt must be parsed manually since an empty string means perma ban

type BannedUsersParams added in v0.5.5

type BannedUsersParams struct {
	BroadcasterID string `query:"broadcaster_id"`
	UserID        string `query:"user_id"`
	After         string `query:"after"`
	Before        string `query:"before"`
}

BannedUsersResponse BroadcasterID must match the auth tokens user_id

type BannedUsersResponse added in v0.5.5

type BannedUsersResponse struct {
	ResponseCommon
	Data ManyBans
}

BannedUsersResponse ...

type BitsLeaderboardParams

type BitsLeaderboardParams struct {
	Count     int       `query:"count,10"`   // Maximum 100
	Period    string    `query:"period,all"` // "all" (default), "day", "week", "month" and "year"
	StartedAt time.Time `query:"started_at"`
	UserID    string    `query:"user_id"`
}

BitsLeaderboardParams ...

type BitsLeaderboardResponse

type BitsLeaderboardResponse struct {
	ResponseCommon
	Data ManyUserBitTotals
}

BitsLeaderboardResponse ...

type Channel added in v0.6.0

type Channel struct {
	ID           string   `json:"id"`
	GameID       string   `json:"game_id"`
	DisplayName  string   `json:"display_name"`
	Language     string   `json:"broadcaster_language"`
	Title        string   `json:"title"`
	ThumbnailURL string   `json:"thumbnail_url"`
	IsLive       bool     `json:"is_live"`
	StartedAt    Time     `json:"started_at"`
	TagIDs       []string `json:"tag_ids"`
}

Channel describes a channel from SearchChannel

type Client

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

Client ...

func NewClient

func NewClient(options *Options) (*Client, error)

NewClient returns a new Twicth Helix API client. It returns an if clientID is an empty string. It is concurrecy safe.

func (*Client) CreateClip

func (c *Client) CreateClip(params *CreateClipParams) (*CreateClipResponse, error)

CreateClip creates a clip programmatically. This returns both an ID and an edit URL for the new clip. Clip creation takes time. We recommend that you query Get Clip, with the clip ID that is returned here. If Get Clip returns a valid clip, your clip creation was successful. If, after 15 seconds, you still have not gotten back a valid clip from Get Clip, assume that the clip was not created and retry Create Clip.

Required scope: clips:edit

func (*Client) CreateEntitlementsUploadURL

func (c *Client) CreateEntitlementsUploadURL(manifestID, entitlementType string) (*EntitlementsUploadResponse, error)

CreateEntitlementsUploadURL return a URL where you can upload a manifest file and notify users that they have an entitlement. Entitlements are digital items that users are entitled to use. Twitch entitlements are granted to users gratis or as part of a purchase on Twitch.

func (*Client) CreateStreamMarker added in v0.4.2

func (c *Client) CreateStreamMarker(params *CreateStreamMarkerParams) (*CreateStreamMarkerResponse, error)

CreateStreamMarker creates a stream marker for a live stream at the current time. The user has to be the stream owner or an editor. Stream markers cannot be created in some cases, see: https://dev.twitch.tv/docs/api/reference/#create-stream-marker

Required Scope: user:edit:broadcast

func (*Client) GetAppAccessToken

func (c *Client) GetAppAccessToken(scopes []string) (*AppAccessTokenResponse, error)

GetAppAccessToken ...

func (*Client) GetAuthorizationURL

func (c *Client) GetAuthorizationURL(params *AuthorizationURLParams) string

GetAuthorizationURL ...

func (*Client) GetBannedUsers added in v0.5.5

func (c *Client) GetBannedUsers(params *BannedUsersParams) (*BannedUsersResponse, error)

GetBannedUsers returns all banned and timed-out users in a channel.

Required scope: moderation:read

func (*Client) GetBitsLeaderboard

func (c *Client) GetBitsLeaderboard(params *BitsLeaderboardParams) (*BitsLeaderboardResponse, error)

GetBitsLeaderboard gets a ranked list of Bits leaderboard information for an authorized broadcaster.

Required Scope: bits:read

func (*Client) GetClips

func (c *Client) GetClips(params *ClipsParams) (*ClipsResponse, error)

GetClips returns information about a specified clip.

func (*Client) GetExtensionAnalytics added in v0.4.0

func (c *Client) GetExtensionAnalytics(params *ExtensionAnalyticsParams) (*ExtensionAnalyticsResponse, error)

GetExtensionAnalytics returns a URL to the downloadable CSV file containing analytics data. Valid for 5 minutes.

func (*Client) GetGameAnalytics

func (c *Client) GetGameAnalytics(params *GameAnalyticsParams) (*GameAnalyticsResponse, error)

GetGameAnalytics returns a URL to the downloadable CSV file containing analytics data for the specified game. Valid for 5 minutes.

func (*Client) GetGames

func (c *Client) GetGames(params *GamesParams) (*GamesResponse, error)

GetGames ...

func (*Client) GetStreamMarkers added in v0.4.1

func (c *Client) GetStreamMarkers(params *StreamMarkersParams) (*StreamMarkersResponse, error)

GetStreamMarkers gets stream markers of a VOD or of the current live stream of an user being recorded as VOD.

Required Scope: user:read:broadcast

func (*Client) GetStreams

func (c *Client) GetStreams(params *StreamsParams) (*StreamsResponse, error)

GetStreams returns a list of live channels based on the search parameters. To query offline channels, use SearchChannels.

func (*Client) GetStreamsMetadata

func (c *Client) GetStreamsMetadata(params *StreamsMetadataParams) (*StreamsMetadataResponse, error)

GetStreamsMetadata ...

func (*Client) GetSubscriptions added in v0.5.3

func (c *Client) GetSubscriptions(params *SubscriptionsParams) (*SubscriptionsResponse, error)

GetSubscriptions gets subscriptions about one Twitch broadcaster. Broadcasters can only request their own subscriptions.

Required scope: channel:read:subscriptions

func (*Client) GetTopGames

func (c *Client) GetTopGames(params *TopGamesParams) (*TopGamesResponse, error)

GetTopGames ...

func (*Client) GetUserAccessToken

func (c *Client) GetUserAccessToken(code string) (*UserAccessTokenResponse, error)

GetUserAccessToken ...

func (*Client) GetUserActiveExtensions added in v0.5.6

func (c *Client) GetUserActiveExtensions(params *UserActiveExtensionsParams) (*UserActiveExtensionsResponse, error)

GetUserActiveExtensions Gets information about active extensions installed by a specified user, identified by a user ID or Bearer token.

Optional scope: user:read:broadcast or user:edit:broadcast

func (*Client) GetUserExtensions added in v0.5.6

func (c *Client) GetUserExtensions() (*UserExtensionsResponse, error)

GetUserExtensions gets a list of all extensions (both active and inactive) for a specified user, identified by a Bearer token

Required scope: user:read:broadcast

func (*Client) GetUsers

func (c *Client) GetUsers(params *UsersParams) (*UsersResponse, error)

GetUsers 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.

Optional scope: user:read:email

func (*Client) GetUsersFollows

func (c *Client) GetUsersFollows(params *UsersFollowsParams) (*UsersFollowsResponse, error)

GetUsersFollows gets information on follow relationships between two Twitch users. Information returned is sorted in order, most recent follow first. This can return information like “who is lirik following,” “who is following lirik,” or “is user X following user Y.”

func (*Client) GetVideos

func (c *Client) GetVideos(params *VideosParams) (*VideosResponse, error)

GetVideos gets video information by video ID (one or more), user ID (one only), or game ID (one only).

func (*Client) GetWebhookSubscriptions added in v0.3.1

func (c *Client) GetWebhookSubscriptions(params *WebhookSubscriptionsParams) (*WebhookSubscriptionsResponse, error)

GetWebhookSubscriptions gets webhook subscriptions, in order of expiration. Requires an app access token.

func (*Client) PostWebhookSubscription added in v0.4.2

func (c *Client) PostWebhookSubscription(payload *WebhookSubscriptionPayload) (*WebhookSubscriptionResponse, error)

PostWebhookSubscription ...

func (*Client) RefreshUserAccessToken

func (c *Client) RefreshUserAccessToken(refreshToken string) (*RefreshTokenResponse, error)

RefreshUserAccessToken submits a request to have the longevity of an access token extended. Twitch OAuth2 access tokens have expirations. Token-expiration periods vary in length. You should build your applications in such a way that they are resilient to token authentication failures.

func (*Client) RevokeUserAccessToken

func (c *Client) RevokeUserAccessToken(accessToken string) (*RevokeAccessTokenResponse, error)

RevokeUserAccessToken submits a request to Twitch to have an access token revoked.

Both successful requests and requests with bad tokens return 200 OK with no body. Requests with bad tokens return the same response, as there is no meaningful action a client can take after sending a bad token.

func (*Client) SearchChannels added in v0.6.0

func (c *Client) SearchChannels(params *SearchChannelsParams) (*SearchChannelsResponse, error)

SearchChannels searches for Twitch channels based on the given search parameters. Unlike GetStreams, this can also return offline channels.

func (*Client) SetAppAccessToken

func (c *Client) SetAppAccessToken(accessToken string)

SetAppAccessToken ...

func (*Client) SetRedirectURI

func (c *Client) SetRedirectURI(uri string)

SetRedirectURI ...

func (*Client) SetUserAccessToken

func (c *Client) SetUserAccessToken(accessToken string)

SetUserAccessToken ...

func (*Client) SetUserAgent

func (c *Client) SetUserAgent(userAgent string)

SetUserAgent ...

func (*Client) UpdateUser

func (c *Client) UpdateUser(params *UpdateUserParams) (*UsersResponse, error)

UpdateUser updates the description of a user specified by a Bearer token.

Required scope: user:edit

func (*Client) UpdateUserExtensions added in v0.5.7

func (c *Client) UpdateUserExtensions(payload *UpdateUserExtensionsPayload) (*UserActiveExtensionsResponse, error)

UpdateUserExtensions Updates the activation state, extension ID, and/or version number of installed extensions for a specified user, identified by a Bearer token. If you try to activate a given extension under multiple extension types, the last write wins (and there is no guarantee of write order).

Required scope: user:edit:broadcast

func (*Client) ValidateToken added in v0.5.9

func (c *Client) ValidateToken(accessToken string) (bool, *ValidateTokenResponse, error)

ValidateToken - Validate access token

type Clip

type Clip struct {
	ID              string `json:"id"`
	URL             string `json:"url"`
	EmbedURL        string `json:"embed_url"`
	BroadcasterID   string `json:"broadcaster_id"`
	BroadcasterName string `json:"broadcaster_name"`
	CreatorID       string `json:"creator_id"`
	CreatorName     string `json:"creator_name"`
	VideoID         string `json:"video_id"`
	GameID          string `json:"game_id"`
	Language        string `json:"language"`
	Title           string `json:"title"`
	ViewCount       int    `json:"view_count"`
	CreatedAt       string `json:"created_at"`
	ThumbnailURL    string `json:"thumbnail_url"`
}

Clip ...

type ClipEditURL

type ClipEditURL struct {
	ID      string `json:"id"`
	EditURL string `json:"edit_url"`
}

ClipEditURL ...

type ClipsParams

type ClipsParams struct {
	// One of the below
	BroadcasterID string   `query:"broadcaster_id"`
	GameID        string   `query:"game_id"`
	IDs           []string `query:"id"` // Limit 100

	// Optional
	First     int    `query:"first,20"` // Maximum 100
	After     string `query:"after"`
	Before    string `query:"before"`
	StartedAt Time   `query:"started_at"`
	EndedAt   Time   `query:"ended_at"`
}

ClipsParams ...

type ClipsResponse

type ClipsResponse struct {
	ResponseCommon
	Data ManyClips
}

ClipsResponse ...

type CreateClipParams added in v0.5.0

type CreateClipParams struct {
	BroadcasterID string `query:"broadcaster_id"`

	// Optional
	HasDelay bool `query:"has_delay,false"`
}

CreateClipParams ...

type CreateClipResponse

type CreateClipResponse struct {
	ResponseCommon
	Data ManyClipEditURLs
}

CreateClipResponse ...

func (*CreateClipResponse) GetClipsCreationRateLimit added in v0.3.0

func (ccr *CreateClipResponse) GetClipsCreationRateLimit() int

GetClipsCreationRateLimit returns the "Ratelimit-Helixclipscreation-Limit" header as an int.

func (*CreateClipResponse) GetClipsCreationRateLimitRemaining added in v0.3.0

func (ccr *CreateClipResponse) GetClipsCreationRateLimitRemaining() int

GetClipsCreationRateLimitRemaining returns the "Ratelimit-Helixclipscreation-Remaining" header as an int.

type CreateStreamMarker added in v0.4.2

type CreateStreamMarker struct {
	ID              string `json:"id"`
	CreatedAt       Time   `json:"created_at"`
	Description     string `json:"description"`
	PositionSeconds int    `json:"position_seconds"`
}

CreateStreamMarker ...

type CreateStreamMarkerParams added in v0.4.2

type CreateStreamMarkerParams struct {
	UserID string `query:"user_id"`

	// Optional
	Description string `query:"description"`
}

CreateStreamMarkerParams ...

type CreateStreamMarkerResponse added in v0.4.2

type CreateStreamMarkerResponse struct {
	ResponseCommon
	Data ManyCreateStreamMarkers
}

CreateStreamMarkerResponse ...

type DateRange added in v0.4.0

type DateRange struct {
	StartedAt Time `json:"started_at"`
	EndedAt   Time `json:"ended_at"`
}

DateRange is a generic struct used by various responses.

type EntitlementsUploadResponse

type EntitlementsUploadResponse struct {
	ResponseCommon
	Data ManyEntitlementsUploadURLs
}

EntitlementsUploadResponse ...

type EntitlementsUploadURL

type EntitlementsUploadURL struct {
	URL string `json:"url"`
}

EntitlementsUploadURL ...

type ExtensionAnalytic added in v0.4.0

type ExtensionAnalytic struct {
	ExtensionID string    `json:"extension_id"`
	URL         string    `json:"URL"`
	Type        string    `json:"type"`
	DateRange   DateRange `json:"date_range"`
}

ExtensionAnalytic ...

type ExtensionAnalyticsParams added in v0.4.0

type ExtensionAnalyticsParams struct {
	ExtensionID string `query:"extension_id"`
	First       int    `query:"first,20"`
	After       string `query:"after"`
	StartedAt   Time   `query:"started_at"`
	EndedAt     Time   `query:"ended_at"`
	Type        string `query:"type"`
}

ExtensionAnalyticsParams ...

type ExtensionAnalyticsResponse added in v0.4.0

type ExtensionAnalyticsResponse struct {
	ResponseCommon
	Data ManyExtensionAnalytics
}

ExtensionAnalyticsResponse ...

type Game

type Game struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	BoxArtURL string `json:"box_art_url"`
}

Game ...

type GameAnalytic

type GameAnalytic struct {
	GameID    string    `json:"game_id"`
	URL       string    `json:"URL"`
	Type      string    `json:"type"`
	DateRange DateRange `json:"date_range"`
}

GameAnalytic ...

type GameAnalyticsParams added in v0.4.0

type GameAnalyticsParams struct {
	GameID    string `query:"game_id"`
	First     int    `query:"first,20"`
	After     string `query:"after"`
	StartedAt Time   `query:"started_at"`
	EndedAt   Time   `query:"ended_at"`
	Type      string `query:"type"`
}

GameAnalyticsParams ...

type GameAnalyticsResponse

type GameAnalyticsResponse struct {
	ResponseCommon
	Data ManyGameAnalytics
}

GameAnalyticsResponse ...

type GamesParams

type GamesParams struct {
	IDs   []string `query:"id"`   // Limit 100
	Names []string `query:"name"` // Limit 100
}

GamesParams ...

type GamesResponse

type GamesResponse struct {
	ResponseCommon
	Data ManyGames
}

GamesResponse ...

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient ...

type HearthstoneHero

type HearthstoneHero struct {
	Class string `json:"class"`
	Name  string `json:"name"`
	Type  string `json:"type"`
}

HearthstoneHero ...

type HearthstoneMetadata

type HearthstoneMetadata struct {
	Broadcaster HearthstonePlayerData `json:"broadcaster"`
	Opponent    HearthstonePlayerData `json:"opponent"`
}

HearthstoneMetadata ...

type HearthstonePlayerData

type HearthstonePlayerData struct {
	Hero HearthstoneHero `json:"hero"`
}

HearthstonePlayerData ...

type ManyBans added in v0.5.5

type ManyBans struct {
	Bans       []Ban      `json:"data"`
	Pagination Pagination `json:"pagination"`
}

ManyBans ...

type ManyClipEditURLs

type ManyClipEditURLs struct {
	ClipEditURLs []ClipEditURL `json:"data"`
}

ManyClipEditURLs ...

type ManyClips

type ManyClips struct {
	Clips      []Clip     `json:"data"`
	Pagination Pagination `json:"pagination"`
}

ManyClips ...

type ManyCreateStreamMarkers added in v0.4.2

type ManyCreateStreamMarkers struct {
	CreateStreamMarkers []CreateStreamMarker `json:"data"`
}

ManyCreateStreamMarkers ...

type ManyEntitlementsUploadURLs

type ManyEntitlementsUploadURLs struct {
	URLs []EntitlementsUploadURL `json:"data"`
}

ManyEntitlementsUploadURLs ...

type ManyExtensionAnalytics added in v0.4.0

type ManyExtensionAnalytics struct {
	ExtensionAnalytics []ExtensionAnalytic `json:"data"`
	Pagination         Pagination          `json:"pagination"`
}

ManyExtensionAnalytics ...

type ManyFollows

type ManyFollows struct {
	Total      int          `json:"total"`
	Follows    []UserFollow `json:"data"`
	Pagination Pagination   `json:"pagination"`
}

ManyFollows ...

type ManyGameAnalytics

type ManyGameAnalytics struct {
	GameAnalytics []GameAnalytic `json:"data"`
	Pagination    Pagination     `json:"pagination"`
}

ManyGameAnalytics ...

type ManyGames

type ManyGames struct {
	Games []Game `json:"data"`
}

ManyGames ...

type ManyGamesWithPagination

type ManyGamesWithPagination struct {
	ManyGames
	Pagination Pagination `json:"pagination"`
}

ManyGamesWithPagination ...

type ManySearchChannels added in v0.6.0

type ManySearchChannels struct {
	Channels   []Channel  `json:"data"`
	Pagination Pagination `json:"pagination"`
}

ManySearchChannels is the response data from SearchChannels

type ManyStreamMarkers added in v0.4.1

type ManyStreamMarkers struct {
	StreamMarkers []StreamMarker `json:"data"`
	Pagination    Pagination     `json:"pagination"`
}

ManyStreamMarkers ...

type ManyStreams

type ManyStreams struct {
	Streams    []Stream   `json:"data"`
	Pagination Pagination `json:"pagination"`
}

ManyStreams ...

type ManyStreamsMetadata

type ManyStreamsMetadata struct {
	Streams    []StreamMetadata `json:"data"`
	Pagination Pagination       `json:"pagination"`
}

ManyStreamsMetadata ...

type ManySubscriptions added in v0.5.3

type ManySubscriptions struct {
	Subscriptions []Subscription `json:"data"`
	Pagination    Pagination     `json:"pagination"`
}

ManySubscriptions ...

type ManyUserBitTotals

type ManyUserBitTotals struct {
	Total         int            `json:"total"`
	DateRange     DateRange      `json:"date_range"`
	UserBitTotals []UserBitTotal `json:"data"`
}

ManyUserBitTotals ...

type ManyUserExtensions added in v0.5.6

type ManyUserExtensions struct {
	UserExtensions []UserExtension `json:"data"`
}

ManyUserExtensions ...

type ManyUsers

type ManyUsers struct {
	Users []User `json:"data"`
}

ManyUsers ...

type ManyVideos

type ManyVideos struct {
	Videos     []Video    `json:"data"`
	Pagination Pagination `json:"pagination"`
}

ManyVideos ...

type ManyWebhookSubscriptions added in v0.3.1

type ManyWebhookSubscriptions struct {
	Total                int                   `json:"total"`
	WebhookSubscriptions []WebhookSubscription `json:"data"`
	Pagination           Pagination            `json:"pagination"`
}

ManyWebhookSubscriptions ...

type Marker added in v0.4.1

type Marker struct {
	ID              string `json:"id"`
	CreatedAt       Time   `json:"created_at"`
	Description     string `json:"description"`
	PositionSeconds int    `json:"position_seconds"`
	URL             string `json:"URL"`
}

Marker ...

type Options

type Options struct {
	ClientID        string
	ClientSecret    string
	AppAccessToken  string
	UserAccessToken string
	UserAgent       string
	RedirectURI     string
	HTTPClient      HTTPClient
	RateLimitFunc   RateLimitFunc
	APIBaseURL      string
}

Options ...

type OverwatchBroadcaster

type OverwatchBroadcaster struct {
	Hero OverwatchHero `json:"hero"`
}

OverwatchBroadcaster ...

type OverwatchHero

type OverwatchHero struct {
	Ability string `json:"ability"`
	Name    string `json:"name"`
	Role    string `json:"role"`
}

OverwatchHero ...

type OverwatchMetadata

type OverwatchMetadata struct {
	Broadcaster OverwatchBroadcaster `json:"broadcaster"`
}

OverwatchMetadata ...

type Pagination

type Pagination struct {
	Cursor string `json:"cursor"`
}

Pagination ...

type RateLimitFunc

type RateLimitFunc func(*Response) error

RateLimitFunc ...

type RefreshTokenResponse

type RefreshTokenResponse struct {
	ResponseCommon
	Data AccessCredentials
}

RefreshTokenResponse ...

type Response

type Response struct {
	ResponseCommon
	Data interface{}
}

Response ...

func (*Response) HydrateResponseCommon added in v0.5.7

func (r *Response) HydrateResponseCommon(rc *ResponseCommon)

HydrateResponseCommon copies the content of the source response's ResponseCommon to the supplied ResponseCommon argument

type ResponseCommon

type ResponseCommon struct {
	StatusCode   int
	Header       http.Header
	Error        string `json:"error"`
	ErrorStatus  int    `json:"status"`
	ErrorMessage string `json:"message"`
}

ResponseCommon ...

func (*ResponseCommon) GetRateLimit added in v0.3.0

func (rc *ResponseCommon) GetRateLimit() int

GetRateLimit returns the "RateLimit-Limit" header as an int.

func (*ResponseCommon) GetRateLimitRemaining added in v0.3.0

func (rc *ResponseCommon) GetRateLimitRemaining() int

GetRateLimitRemaining returns the "RateLimit-Remaining" header as an int.

func (*ResponseCommon) GetRateLimitReset added in v0.3.0

func (rc *ResponseCommon) GetRateLimitReset() int

GetRateLimitReset returns the "RateLimit-Reset" header as an int.

type RevokeAccessTokenResponse

type RevokeAccessTokenResponse struct {
	ResponseCommon
}

RevokeAccessTokenResponse ...

type SearchChannelsParams added in v0.6.0

type SearchChannelsParams struct {
	Channel  string `query:"query"`
	After    string `query:"after"`
	First    int    `query:"first,20"` // Limit 100
	LiveOnly bool   `query:"live_only"`
}

SearchChannelsParams is parameters for SearchChannels

type SearchChannelsResponse added in v0.6.0

type SearchChannelsResponse struct {
	ResponseCommon
	Data ManySearchChannels
}

SearchChannelsResponse is the response from SearchChannels

type Stream

type Stream struct {
	ID           string    `json:"id"`
	UserID       string    `json:"user_id"`
	UserName     string    `json:"user_name"`
	GameID       string    `json:"game_id"`
	TagIDs       []string  `json:"tag_ids"`
	Type         string    `json:"type"`
	Title        string    `json:"title"`
	ViewerCount  int       `json:"viewer_count"`
	StartedAt    time.Time `json:"started_at"`
	Language     string    `json:"language"`
	ThumbnailURL string    `json:"thumbnail_url"`
}

Stream ...

type StreamMarker added in v0.4.1

type StreamMarker struct {
	UserID   string        `json:"user_id"`
	UserName string        `json:"user_name"`
	Videos   []VideoMarker `json:"videos"`
}

StreamMarker ...

type StreamMarkersParams added in v0.4.1

type StreamMarkersParams struct {
	UserID  string `query:"user_id"`
	VideoID string `query:"video_id"`

	// Optional
	After  string `query:"after"`
	Before string `query:"before"`
	First  int    `query:"first,20"` // Limit 100
}

StreamMarkersParams requires _either_ UserID or VideoID set

UserID: fetches stream markers of the current livestream of the given user (VOD recording must be enabled). VideoID: fetches streams markers of the VOD.

type StreamMarkersResponse added in v0.4.1

type StreamMarkersResponse struct {
	ResponseCommon
	Data ManyStreamMarkers
}

StreamMarkersResponse ...

type StreamMetadata

type StreamMetadata struct {
	UserID      string              `json:"user_id"`
	UserName    string              `json:"user_name"`
	GameID      string              `json:"game_id"`
	Hearthstone HearthstoneMetadata `json:"hearthstone"`
	Overwatch   OverwatchMetadata   `json:"overwatch"`
}

StreamMetadata ...

type StreamsMetadataParams

type StreamsMetadataParams StreamsParams

StreamsMetadataParams ...

type StreamsMetadataResponse

type StreamsMetadataResponse struct {
	ResponseCommon
	Data ManyStreamsMetadata
}

StreamsMetadataResponse ...

func (*StreamsMetadataResponse) GetStreamsMetadataRateLimit added in v0.3.0

func (sr *StreamsMetadataResponse) GetStreamsMetadataRateLimit() int

GetStreamsMetadataRateLimit returns the "Ratelimit-Helixstreamsmetadata-Limit" header as an int.

func (*StreamsMetadataResponse) GetStreamsMetadataRateLimitRemaining added in v0.3.0

func (sr *StreamsMetadataResponse) GetStreamsMetadataRateLimitRemaining() int

GetStreamsMetadataRateLimitRemaining returns the "Ratelimit-Helixstreamsmetadata-Remaining" header as an int.

type StreamsParams

type StreamsParams struct {
	After      string   `query:"after"`
	Before     string   `query:"before"`
	First      int      `query:"first,20"`   // Limit 100
	GameIDs    []string `query:"game_id"`    // Limit 100
	Language   []string `query:"language"`   // Limit 100
	Type       string   `query:"type,all"`   // "all" (default), "live" and "vodcast"
	UserIDs    []string `query:"user_id"`    // limit 100
	UserLogins []string `query:"user_login"` // limit 100
}

StreamsParams ...

type StreamsResponse

type StreamsResponse struct {
	ResponseCommon
	Data ManyStreams
}

StreamsResponse ...

type Subscription added in v0.5.3

type Subscription struct {
	BroadcasterID   string `json:"broadcaster_id"`
	BroadcasterName string `json:"broadcaster_name"`
	IsGift          bool   `json:"is_gift"`
	Tier            string `json:"tier"`
	PlanName        string `json:"plan_name"`
	UserID          string `json:"user_id"`
	UserName        string `json:"user_name"`
}

Subscription ...

type SubscriptionsParams added in v0.5.3

type SubscriptionsParams struct {
	BroadcasterID string   `query:"broadcaster_id"` // Limit 1
	UserID        []string `query:"user_id"`        // Limit 100
}

SubscriptionsParams ...

type SubscriptionsResponse added in v0.5.3

type SubscriptionsResponse struct {
	ResponseCommon
	Data ManySubscriptions
}

SubscriptionsResponse ...

type Time

type Time struct {
	time.Time
}

Time is our custom time struct.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON is our custom datetime unmarshaller. Twitch sometimes returns datetimes as empty strings, which casuses issues with the native time UnmarshalJSON method when decoding the JSON string. Here we hanlde that scenario, by returning a zero time value for any JSON time field that is either an empty string or "null".

type TopGamesParams

type TopGamesParams struct {
	After  string `query:"after"`
	Before string `query:"before"`
	First  int    `query:"first,20"` // Limit 100
}

TopGamesParams ...

type TopGamesResponse

type TopGamesResponse struct {
	ResponseCommon
	Data ManyGamesWithPagination
}

TopGamesResponse ...

type UpdateUserExtensionsPayload added in v0.5.7

type UpdateUserExtensionsPayload struct {
	Component map[string]UserActiveExtensionInfo `json:"component,omitempty"`
	Overlay   map[string]UserActiveExtensionInfo `json:"overlay,omitempty"`
	Panel     map[string]UserActiveExtensionInfo `json:"panel,omitempty"`
}

type UpdateUserParams added in v0.5.0

type UpdateUserParams struct {
	Description string `query:"description"`
}

UpdateUserParams ...

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"`
}

User ...

type UserAccessTokenResponse

type UserAccessTokenResponse struct {
	ResponseCommon
	Data AccessCredentials
}

UserAccessTokenResponse ...

type UserActiveExtension added in v0.5.6

type UserActiveExtension struct {
	Component map[string]UserActiveExtensionInfo `json:"component"`
	Overlay   map[string]UserActiveExtensionInfo `json:"overlay"`
	Panel     map[string]UserActiveExtensionInfo `json:"panel"`
}

UserActiveExtension ...

type UserActiveExtensionInfo added in v0.5.6

type UserActiveExtensionInfo struct {
	Active  bool   `json:"active"`
	ID      string `json:"id"`
	Name    string `json:"name"`
	Version string `json:"version"`
	X       int    `json:"x"`
	Y       int    `json:"y"`
}

UserActiveExtensionInfo ...

type UserActiveExtensionSet added in v0.5.6

type UserActiveExtensionSet struct {
	UserActiveExtensions UserActiveExtension `json:"data"`
}

UserActiveExtensionSet ...

type UserActiveExtensionsParams added in v0.5.6

type UserActiveExtensionsParams struct {
	UserID string `query:"user_id"` // Optional, limit 1
}

UserActiveExtensionsParams ...

type UserActiveExtensionsResponse added in v0.5.6

type UserActiveExtensionsResponse struct {
	ResponseCommon
	Data UserActiveExtensionSet
}

UserActiveExtensionsResponse ...

type UserBitTotal

type UserBitTotal struct {
	UserID   string `json:"user_id"`
	UserName string `json:"user_name"`
	Rank     int    `json:"rank"`
	Score    int    `json:"score"`
}

UserBitTotal ...

type UserExtension added in v0.5.6

type UserExtension struct {
	CanActivate bool     `json:"can_activate"`
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Type        []string `json:"type"`
	Version     string   `json:"version"`
}

UserExtension ...

type UserExtensionsResponse added in v0.5.6

type UserExtensionsResponse struct {
	ResponseCommon
	Data ManyUserExtensions
}

UserExtensionsResponse ...

type UserFollow

type UserFollow struct {
	FromID     string    `json:"from_id"`
	FromName   string    `json:"from_name"`
	ToID       string    `json:"to_id"`
	ToName     string    `json:"to_name"`
	FollowedAt time.Time `json:"followed_at"`
}

UserFollow ...

type UsersFollowsParams

type UsersFollowsParams struct {
	After  string `query:"after"`
	First  int    `query:"first,20"` // Limit 100
	FromID string `query:"from_id"`
	ToID   string `query:"to_id"`
}

UsersFollowsParams ...

type UsersFollowsResponse

type UsersFollowsResponse struct {
	ResponseCommon
	Data ManyFollows
}

UsersFollowsResponse ...

type UsersParams

type UsersParams struct {
	IDs    []string `query:"id"`    // Limit 100
	Logins []string `query:"login"` // Limit 100
}

UsersParams ...

type UsersResponse

type UsersResponse struct {
	ResponseCommon
	Data ManyUsers
}

UsersResponse ...

type ValidateTokenResponse added in v0.5.9

type ValidateTokenResponse struct {
	ResponseCommon
	Data validateTokenDetails
}

ValidateTokenResponse ...

type Video

type Video struct {
	ID           string `json:"id"`
	UserID       string `json:"user_id"`
	UserName     string `json:"user_name"`
	Title        string `json:"title"`
	Description  string `json:"description"`
	CreatedAt    string `json:"created_at"`
	PublishedAt  string `json:"published_at"`
	URL          string `json:"url"`
	ThumbnailURL string `json:"thumbnail_url"`
	Viewable     string `json:"viewable"`
	ViewCount    int    `json:"view_count"`
	Language     string `json:"language"`
	Type         string `json:"type"`
	Duration     string `json:"duration"`
}

Video ...

type VideoMarker added in v0.4.1

type VideoMarker struct {
	VideoID string   `json:"video_id"`
	Markers []Marker `json:"markers"`
}

VideoMarker ...

type VideosParams

type VideosParams struct {
	IDs    []string `query:"id"`      // Limit 100
	UserID string   `query:"user_id"` // Limit 1
	GameID string   `query:"game_id"` // Limit 1

	// Optional
	After    string `query:"after"`
	Before   string `query:"before"`
	First    int    `query:"first,20"`   // Limit 100
	Language string `query:"language"`   // Limit 1
	Period   string `query:"period,all"` // "all" (default), "day", "month", and "week"
	Sort     string `query:"sort,time"`  // "time" (default), "trending", and "views"
	Type     string `query:"type,all"`   // "all" (default), "upload", "archive", and "highlight"
}

VideosParams ...

type VideosResponse

type VideosResponse struct {
	ResponseCommon
	Data ManyVideos
}

VideosResponse ...

type WebhookSubscription added in v0.3.1

type WebhookSubscription struct {
	Topic     string `json:"topic"`
	Callback  string `json:"callback"`
	ExpiresAt Time   `json:"expires_at"`
}

WebhookSubscription ...

type WebhookSubscriptionPayload added in v0.4.2

type WebhookSubscriptionPayload struct {
	Mode         string `json:"hub.mode"`
	Topic        string `json:"hub.topic"`
	Callback     string `json:"hub.callback"`
	LeaseSeconds int    `json:"hub.lease_seconds,omitempty"`
	Secret       string `json:"hub.secret,omitempty"`
}

WebhookSubscriptionPayload ...

type WebhookSubscriptionResponse added in v0.4.2

type WebhookSubscriptionResponse struct {
	ResponseCommon
}

WebhookSubscriptionResponse ...

type WebhookSubscriptionsParams added in v0.3.1

type WebhookSubscriptionsParams struct {
	After string `query:"after"`
	First int    `query:"first,20"` // Limit 100
}

WebhookSubscriptionsParams ...

type WebhookSubscriptionsResponse added in v0.3.1

type WebhookSubscriptionsResponse struct {
	ResponseCommon
	Data ManyWebhookSubscriptions
}

WebhookSubscriptionsResponse ...

type WebhookTopic added in v0.4.2

type WebhookTopic int

WebhookTopic is a topic that relates to a specific webhook event.

const (
	UserFollowsTopic WebhookTopic = iota
	StreamChangedTopic
	UserChangedTopic
	GameAnalyticsTopic
	ExtensionAnalyticsTopic
)

Enumerated webhook topics

func GetWebhookTopicFromRequest added in v0.4.2

func GetWebhookTopicFromRequest(req *http.Request) WebhookTopic

GetWebhookTopicFromRequest inspects the "Link" request header to determine if it matches against any recognised webhooks topics. The matched topic is returned. Otherwise -1 is returned.

Jump to

Keyboard shortcuts

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