kraken

package
v0.0.0-...-1cc4fbe Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2017 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package kraken exposes a client for interacting with version 5 of the Twitch.tv API. Helix is considered the "new" and "current" API, though at this time it is incomlete. Kraken is v5 and complete, but considered deprecated and will be turned of ~Dec. 2018. When possible, you should use helix.

Index

Constants

View Source
const AccessTokenEnvVar = "TWITCH_ACCESS_TOKEN"

AccessTokenEnvVar is the name of the environment variable where the Twitch API key should be read from. ClientIdEnvVar is the name of the environment variable the client id should be read from.

View Source
const AccessTokenHeader = "Authorization"

AccessTokenHeader is the name of the header that contains the Twitch API key.

View Source
const ClientIdEnvVar = "TWITCH_CLIENT_ID"

Probably not needed, but offered

View Source
const ClientIdHeader = "Client-ID"
View Source
const ClientSecretEnvVar = "TWITCH_CLIENT_SECRET"

Not used yet

Variables

This section is empty.

Functions

This section is empty.

Types

type Broadcaster

type Broadcaster struct {
	// The Broadcaster is a user/streamer, unfortunately, the API returns the
	// broadcater ID without the normal _id prefix that User has (uses just id
	// here) , so mapstructure doesn't parse it out. The result is we get User
	// fields as we expect, except ID is 0
	//
	// This could be addressed with a method on Broadcaster that looks up the id
	// by the name.
	User       `mapstructure:",squash"`
	ChannelURL string `mapstructure:"channel_url"`
}

type Channel

type Channel struct {
	Id int `mapstructure:"_id"`

	BroadcasterLanguage string `mapstructure:"broadcaster_language"`
	Description         string `mapstructure:"description"`
	DisplayName         string `mapstructure:"display_name"`
	Followers           int    `mapstructure:"followers"`
	Game                string `mapstructure:"game"`
	HTMLURL             string `mapstructure:"url"`
	Language            string `mapstructure:"language"`
	Name                string `mapstructure:"name"`
	Mature              bool   `mapstructure:"mature"`
	Status              string `mapstructure:"status"`
	Views               int    `mapstructure:"views"`

	CreatedAt *time.Time `mapstructure:"created_at"`
	UpdatedAt *time.Time `mapstructure:"updated_at"`
}

Version represents a distinct configuration version.

type Client

type Client struct {
	Config *twitch.Config
	// contains filtered or unexported fields
}

func DefaultClient

func DefaultClient(config *twitch.Config) *Client

DefaultClient instantiates a new Twitch API client. This function requires the environment variables `TWITCH_ACCESS_TOKEN` and `TWITCH_CLIENT_ID` to be set and contain valid access token and client id, respectively, to authenticate with Twitch.

func NewClient

func NewClient(config *twitch.Config) (*Client, error)

NewClient creates a new API client with the given key and the default API endpoint. Twitch requires both an access token and a client id for requests, so we error if either is empty.

Creating an access token is not yet supported by this libary TODO: Support creating an access token

func (*Client) Delete

func (c *Client) Delete(p string, ro *twitch.RequestOptions) (*http.Response, error)

Delete issues an HTTP DELETE request.

func (*Client) Get

func (c *Client) Get(p string, ro *twitch.RequestOptions) (*http.Response, error)

func (*Client) GetChannel

func (k *Client) GetChannel(i *GetChannelInput) (*GetChannelOutput, error)

GetChannel returns the full list of all versions of the given service. GetChannel with a nil GetChannelInput, or GetChannelInput with Id 0 will hit the /channel/ endpoint, which retrieves the channel based on the scoped OAuth token. Otherwise we hit the /channels/<id> enpoint for the given ID See:

func (*Client) GetChannelFollowers

func (k *Client) GetChannelFollowers(i *GetChannelFollowersInput) (*GetChannelFollowersOutput, error)

GetChannelFollowers returns the full list of users following a channel

func (*Client) GetChannelVideos

func (k *Client) GetChannelVideos(i *GetChannelVideosInput) (*GetChannelVideosOutput, error)

GetChannelVideos returns the full list of users following a channel

func (*Client) GetClip

func (k *Client) GetClip(i *GetClipInput) (*GetClipOutput, error)

Gets details about a specified clip See:

func (*Client) GetFeaturedStreams

func (k *Client) GetFeaturedStreams(i *GetFeaturedStreamsInput) (*GetFeaturedStreamsOutput, error)

GetFeaturedStreams returns the full list of all versions of the given service.

func (*Client) GetFollowedClips

func (k *Client) GetFollowedClips(i *GetFollowedClipsInput) (*GetFollowedClipsOutput, error)

Gets Followed clips TODO/Note: I'm not sure how this api is supposed to return things, I'm getting [] for a reply and I can't seem to "follow" clips right now. I don't consider this endpoint of the SDK to "work" Scope: user_read See:

func (*Client) GetFollowedStreams

func (k *Client) GetFollowedStreams(i *GetFollowedStreamsInput) (*GetFollowedStreamsOutput, error)

GetFollowedStreams returns a list of online streams a user is following, based on a specified OAuth token.

func (*Client) GetIngestServerList

func (k *Client) GetIngestServerList(_ *GetIngestServerListInput) (*GetIngestServerListOutput, error)

GetIngestServerList returns a list of servers for ingesting streams. See https://dev.twitch.tv/docs/v5/reference/ingests/#get-ingest-server-list

func (*Client) GetLiveStreams

func (k *Client) GetLiveStreams(i *GetLiveStreamsInput) (*GetLiveStreamsOutput, error)

GetStream returns the full list of all versions of the given service.

func (*Client) GetStream

func (k *Client) GetStream(i *GetStreamInput) (*GetStreamOutput, *http.Response, error)

GetStream returns the full list of all versions of the given service.

func (*Client) GetStreamSummary

func (k *Client) GetStreamSummary(i *GetStreamSummaryInput) (*GetStreamSummaryOutput, error)

GetStream returns the full list of all versions of the given service.

func (*Client) GetUser

func (k *Client) GetUser(i *GetUserInput) (*GetUserOutput, error)

GetUser returns information on the user. With no GetUserInput specified, gets users info scoped to the access token

func (*Client) GetUserFollows

func (k *Client) GetUserFollows(i *GetUserFollowsInput) (*GetUserFollowsOutput, error)

GetUserFollows returns information on the channels a user is following.

func (*Client) Head

func (c *Client) Head(p string, ro *twitch.RequestOptions) (*http.Response, error)

Head issues an HTTP HEAD request.

func (*Client) Post

func (c *Client) Post(p string, ro *twitch.RequestOptions) (*http.Response, error)

Post issues an HTTP POST request.

func (*Client) PostForm

func (c *Client) PostForm(p string, i interface{}, ro *twitch.RequestOptions) (*http.Response, error)

PostForm issues an HTTP POST request with the given interface form-encoded.

func (*Client) Put

func (c *Client) Put(p string, ro *twitch.RequestOptions) (*http.Response, error)

Put issues an HTTP PUT request.

func (*Client) PutForm

func (c *Client) PutForm(p string, i interface{}, ro *twitch.RequestOptions) (*http.Response, error)

PutForm issues an HTTP PUT request with the given interface form-encoded.

func (*Client) RawRequest

func (c *Client) RawRequest(verb, p string, ro *twitch.RequestOptions) (*http.Request, error)

RawRequest accepts a verb, URL, and twitch.RequestOptions struct and returns the constructed http.Request and any errors that occurred

func (*Client) Request

func (c *Client) Request(verb, p string, ro *twitch.RequestOptions) (*http.Response, error)

Request makes an HTTP request against the HTTPClient using the given verb, Path, and request options.

func (*Client) RequestForm

func (c *Client) RequestForm(verb, p string, i interface{}, ro *twitch.RequestOptions) (*http.Response, error)

RequestForm makes an HTTP request with the given interface being encoded as form data.

type Clip

type Clip struct {
	Slug string

	// Embeded types
	Broadcaster *Broadcaster `mapstructure:"broadcaster"`
	Curator     *Curator     `mapstructure:"curator"`
	Vod         *Vod         `mapstructure:"vod"`
	Thumbnails  *Thumbnails  `mapstructure:"thumbnails"`

	TrackingId   int    `mapstructure:"tracking_id"`
	URL          string `mapstructure:"url"`
	EmbedURL     string `mapstructure:"embed_url"`
	EmbedHTMLURL string `mapstructure:"embed_html"`

	BroadcastId int     `mapstructure:"broadcast_id"`
	Game        string  `mapstructure:"game"`
	Language    string  `mapstructure:"language"`
	Title       string  `mapstructure:"title"`
	Views       int     `mapstructure:"views"`
	Duration    float64 `mapstructure:"duration"`

	CreatedAt *time.Time `mapstructure:"created_at"`
}

Version represents a distinct configuration version.

type Curator

type Curator struct {
	Id          int    `mapstructure:"id"`
	Name        string `mapstructure:"name"`
	DisplayName string `mapstructure:"display_name"`
	ChannelURL  string `mapstructure:"channel_url"`
}

type FeaturedStream

type FeaturedStream struct {
	Image     string
	Priority  int
	Scheduled bool
	Sponsored bool
	Stream    *Stream
}

type GetChannelFollowersInput

type GetChannelFollowersInput struct {
	Id int
}

GetChannelFollowersInput is the input to the GetChannelFollowers function.

type GetChannelFollowersOutput

type GetChannelFollowersOutput struct {
	Total     int     `mapstructure:"_total"`
	Followers []*User `mapstructure:"follows"`
}

GetChannelOutput is the output of the GetChannel function.

type GetChannelInput

type GetChannelInput struct {
	Id int
}

GetChannelInput is the input to the GetChannel function.

type GetChannelOutput

type GetChannelOutput struct {
	Channel *Channel `mapstructure:"channel"`
}

GetChannelOutput is the output of the GetChannel function.

type GetChannelVideosInput

type GetChannelVideosInput struct {
	Id       int
	Limit    int             `mapstructure:"limit"`
	Language string          `mapstructure:"language"`
	Sort     VideoSortString `mapstructure:"sort"`
}

GetChannelVideosInput is the input to the GetChannelVideos function.

type GetChannelVideosOutput

type GetChannelVideosOutput struct {
	Total  int      `mapstructure:"_total"`
	Videos []*Video `mapstructure:"videos"`
}

GetChannelOutput is the output of the GetChannel function.

type GetClipInput

type GetClipInput struct {
	// Clips are referenced by a globally unique string called a slug
	Slug string
}

GetClipInput is the input to the GetClip function.

type GetClipOutput

type GetClipOutput struct {
	Clip
}

GetClipOutput is the output of the GetClip function.

type GetFeaturedStreamsInput

type GetFeaturedStreamsInput struct {
	// Maximum number of objects to return. Default: 25. Maximum: 100.O
	Limit int `mapstructure:"limit"`

	// Constrains the type of streams returned. Valid values: live, playlist, all. Playlists are offline streams of VODs (Video on Demand) that appear live. Default: live.
	StreamType StreamType `mapstructure:"stream_type"`

	//Object offset for pagination of results. Default: 0.
	Offset int `mapstructure:"offset"`
}

GetFeaturedStreamsInput is the input to the GetFeaturedStreams function.

type GetFeaturedStreamsOutput

type GetFeaturedStreamsOutput struct {
	// Total results returned
	Total int

	// List of matching Streams
	FeaturedStreams []*FeaturedStream `mapstructure:"featured"`
}

GetFeaturedStreamsOutput is the output of the GetFeaturedStreams function.

type GetFollowedClipsInput

type GetFollowedClipsInput struct {

	// Game name. (Game names can be retrieved with the Search Games endpoint.) If this is specified, top clips for only this game are returned; otherwise, top clips for all games are returned. If both channel and game are specified, game is ignored.
	Game string
	//   Comma-separated list of languages, which constrains the languages of videos returned. Examples: es, en,es,th. If no language is specified, all languages are returned. Default: "". Maximum: 28 languages.
	Language string
	//   If true, the clips returned are ordered by popularity; otherwise, by viewcount. Default: false.
	Trending bool
	// contains filtered or unexported fields
}

GetFollowedClipsInput is the input to the GetFollowedClips function.

type GetFollowedClipsOutput

type GetFollowedClipsOutput struct {
	Clips []*Clip `mapstructure:"clips"`
	// contains filtered or unexported fields
}

GetFollowedClipsOutput is the output of the GetFollowedClips function.

type GetFollowedStreamsInput

type GetFollowedStreamsInput struct {
	// Maximum number of objects to return. Default: 25. Maximum: 100.O
	Limit int `mapstructure:"limit"`

	// Constrains the type of streams returned. Valid values: live, playlist, all.
	// Playlists are offline streams of VODs (Video on Demand) that appear live.
	// Default: live.
	StreamType StreamType `mapstructure:"stream_type"`

	//Object offset for pagination of results. Default: 0.
	Offset int `mapstructure:"offset"`
}

GetFollowedStreamsInput is the input to the GetFollowedStreams function.

type GetFollowedStreamsOutput

type GetFollowedStreamsOutput struct {
	// Total results returned
	Total int `mapstructure:"_total"`

	// List of matching Streams
	Streams []*Stream
}

GetFollowedStreamsOutput is the output of the GetFollowedStreams function.

type GetIngestServerListInput

type GetIngestServerListInput struct {
}

GetIngestServerListInput has no paramters

type GetIngestServerListOutput

type GetIngestServerListOutput struct {
	IngestList []*Ingest `mapstructure:"ingests"`
}

GetFollowedIngestsOutput is the output of the GetFollowedIngests function.

type GetLiveStreamsInput

type GetLiveStreamsInput struct {
	// Slice of channel ids to filter
	ChannelIds []string `mapstructure:"channel"`

	// Game name to filter on
	Game string `mapstructure:"game"`

	// Constrains streams to a language.
	// Ex: en, fi, es-mx. Only one language can be specified.
	// Omit to search default "all languages"
	Language string `mapstructure:"language"`

	// Maximum number of objects to return. Default: 25. Maximum: 100.O
	Limit int `mapstructure:"limit"`

	// Constrains the type of streams returned. Valid values: live, playlist, all. Playlists are offline streams of VODs (Video on Demand) that appear live. Default: live.
	StreamType StreamType `mapstructure:"stream_type"`

	//Object offset for pagination of results. Default: 0.
	Offset int `mapstructure:"offset"`
}

GetLiveStreamsInput is the input to the GetStream function.

type GetLiveStreamsOutput

type GetLiveStreamsOutput struct {
	// Total
	Total int `mapstructure:"_total"`

	// List of matching Streams
	Streams []*Stream
}

GetLiveStreamsOutput is the output of the GetStream function.

type GetStreamInput

type GetStreamInput struct {
	ChannelId int
	// Constrains the type of streams returned. Valid values: live, playlist, all. Playlists are offline streams of VODs (Video on Demand) that appear live. Default: live.
	StreamType StreamType
}

GetStreamInput is the input to the GetStream function.

type GetStreamOutput

type GetStreamOutput struct {
	// List of matching Streams
	Stream *Stream
}

GetStreamOutput is the output of the GetStream function.

type GetStreamSummaryInput

type GetStreamSummaryInput struct {
	// Game name to filter on
	Game string `mapstructure:"game"`
}

GetStreamSummaryInput is the input to the GetStreamSummary function.

type GetStreamSummaryOutput

type GetStreamSummaryOutput struct {
	Channels int `mapstructure:"channels"`
	Viewers  int `mapstructure:"viewers"`
}

GetLiveStreamsOutput is the output of the GetStream function.

type GetTopClipsInput

type GetTopClipsInput struct {
	// Channel name. If this is specified, top clips for only this channel are returned; otherwise, top clips for all channels are returned. If both channel and game are specified, game is ignored.
	Channel string
	// Tells the server where to start fetching the next set of results, in a multi-page response.
	Cursor string
	// Game name. (Game names can be retrieved with the Search Games endpoint.) If this is specified, top clips for only this game are returned; otherwise, top clips for all games are returned. If both channel and game are specified, game is ignored.
	Game string
	//   Comma-separated list of languages, which constrains the languages of videos returned. Examples: es, en,es,th. If no language is specified, all languages are returned. Default: "". Maximum: 28 languages.
	Language string
	// Maximum number of most-recent objects to return. Default: 10. Maximum: 100.
	Limit int
	// The window of time to search for clips. Valid values: day, week, month, all. Default: week.
	Period string
	//   If true, the clips returned are ordered by popularity; otherwise, by viewcount. Default: false.
	Trending bool
}

GetTopClipsInput is the input to the GetTopClips function.

type GetTopClipsOutput

type GetTopClipsOutput struct {
	Clips  []*Clip `mapstructure:"clips"`
	Cursor string  `mapstructure:"_cursor"`
}

GetTopClipsOutput is the output of the GetTopClips function.

type GetUserFollowsInput

type GetUserFollowsInput struct {
	Id int
}

GetUserFollowsInput is the input to the GetUserFollows function.

type GetUserFollowsOutput

type GetUserFollowsOutput struct {
	Total   int            `mapstructure:"_total"`
	Follows []*userFollows `mapstructure:"follows"`
}

GetUserFollowssOutput is the output of the GetUserFollows function.

type GetUserInput

type GetUserInput struct {
	// Id represents a users Id, and is used for looking up users by their ID.
	// This does not require any authentication
	// Ex:
	//   GET https://api.twitch.tv/kraken/users/<user ID>
	Id int
}

GetUserInput is the input to the GetUser function.

type GetUserOutput

type GetUserOutput struct {
	User
}

GetUsersOutput is the output of the GetUser function.

type Ingest

type Ingest struct {
	Id           int     `mapstructure:"_id"`
	Name         string  `mapstructure:"name"`
	Default      bool    `mapstructure:"default"`
	Availability float32 `mapstructure:"availability"`
	UrlTemplate  string  `mapstructure:"url_template"`
}

The Twitch ingesting system is the first stop for a broadcast stream. An ingest server receives your stream, and the ingesting system authorizes and registers streams, then prepares them for viewers.

type Preview

type Preview struct {
	Large    string `mapstructure:"large"`
	Medium   string `mapstructure:"medium"`
	Small    string `mapstructure:"small"`
	Template string `mapstructure:"template"`
}

type Stream

type Stream struct {
	Id         int      `mapstructure:"_id"` // maybe _id ?
	AverageFps int      `mapstructure:"average_fps"`
	Delay      int      `mapstructure:"delay"`
	Game       string   `mapstructure:"game"`
	Channel    *Channel `mapstructure:"channel"`
}

Stream represents a distinct stream

type StreamType

type StreamType string

StreamType is the type of cache action.

const (
	// TODO These docs are copy/pasta/wrong
	// StreamTypeLive
	StreamTypeLive StreamType = "live"

	// StreamTypePass sets the cache to pass through.
	StreamTypePlayList StreamType = "playlist"

	// StreamTypeRestart sets the cache to restart the request.
	StreamTypeAll StreamType = "all"
)

type Thumbnails

type Thumbnails struct {
	Medium string `mapstructure:"medium"`
	Small  string `mapstructure:"small"`
	Tiny   string `mapstructure:"tiny"`
}

type User

type User struct {
	//Id          int    `mapstructure:"_id,id"` // Debug, mapstructure thing
	Id          int    `mapstructure:"_id"`
	Name        string `mapstructure:"name"`
	DisplayName string `mapstructure:"display_name"`
	Type        string `mapstructure:"type"`
	Bio         string `mapstructure:"bio"`
}

User represents a user/streamer

type Video

type Video struct {
	Id            string    `mapstructure:"_id"`
	BroadcastId   int       `mapstructure:"broadcast_id"`
	BroadcastType string    `mapstructure:"broadcast_type"`
	Channel       *Channel  `mapstructure:"channel"`
	CreatedAt     time.Time `mapstructure:"created_at"`
	PublishedAt   time.Time `mapstructure:"published_at"`
	Description   string    `mapstructure:"description"`
	Game          string    `mapstructure:"game"`
	Preview       *Preview  `mapstructure:"preview"`
	Title         string    `mapstructure:"title"`
	URLString     string    `mapstructure:"url"`
	Viewable      string    `mapstructure:"viewable"`
	Views         int       `mapstructure:"views"`
}

type VideoSortString

type VideoSortString string

VideoSort determine how video results are sorted

const (
	VideoSortViews VideoSortString = "views"
	// Default
	VideoSortTime VideoSortString = "time"
)

type Vod

type Vod struct {
	Id     int    `mapstructure:"id"`
	URL    string `mapstructure:"url"`
	Offset int    `mapstructure:"offset"`
}

Jump to

Keyboard shortcuts

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