twitch

package module
v0.0.0-...-1ddbb1b Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2017 License: MIT Imports: 7 Imported by: 1

README

Build Status

go-twitch

Test
CLIENT_ID="<my client ID>" go test -v -cover
Usage

Example File:

package main

import (
  "log"
  "os"

  "github.com/knspriggs/go-twitch"
)

var clientID string

func init() {
  clientID = os.Getenv("CLIENT_ID")
}

func main() {
  twitchSession, err := twitch.NewSession(twitch.NewSessionInput{ClientID: clientID})
  if err != nil {
    log.Fatalln(err)
  }

  searchChannelsInput := twitch.SearchChannelsInputType{
    Query: "knspriggs",   // see https://github.com/justintv/Twitch-API/blob/master/v3_resources/search.md for query syntax
    Limit: 2,             // optional
    Offset: 0,            // optional
  }

  resp, err := twitchSession.SearchChannels(&searchChannelsInput)
  if err != nil {
    log.Fatalln(err)
  }
  log.Printf("Resp: \n%#v", resp)
}
CLIENT_ID="<my client ID>" go run example/main.go

To get a client ID see the documentation from the Twitch API https://github.com/justintv/Twitch-API/blob/master/authentication.md

Documentation

Index

Constants

View Source
const (
	// APIV3Header - default v3 api header
	APIV3Header = "application/vnd.twitchtv.v3+json"
)

Variables

View Source
var (
	// DefaultURL - default URLs for the Twitch v3 API
	DefaultURL = &url.URL{
		Scheme: "https",
		Host:   "api.twitch.tv",
		Path:   "kraken",
	}
)

Functions

This section is empty.

Types

type ChannelType

type ChannelType struct {
	Mature                       bool              `json:"mature"`
	Status                       string            `json:"status"`
	BroadcasterLanguage          string            `json:"broadcaster_language"`
	DisplayName                  string            `json:"display_name"`
	Game                         string            `json:"game"`
	Delay                        int               `json:"delay"`
	Language                     string            `json:"language"`
	ID                           int               `json:"_id"`
	Name                         string            `json:"name"`
	CreatedAt                    string            `json:"created_at"`
	UpdatedAt                    string            `json:"updated_at"`
	Banner                       string            `json:"banner"`
	VideoBanner                  string            `json:"video_banner"`
	Background                   string            `json:"background"`
	ProfileBanner                string            `json:"profile_banner"`
	ProfileBannerBackgroundColor string            `json:"profile_banner_background_color"`
	Partner                      bool              `json:"partner"`
	URL                          string            `json:"url"`
	Views                        int               `json:"views"`
	Followers                    int               `json:"followers"`
	Links                        map[string]string `json:"_links"`
}

ChannelType - describes a channel on twitch

type FeaturedType

type FeaturedType struct {
	Image     string     `json:"image"`
	Text      string     `json:"text"`
	Title     string     `json:"title"`
	Sponsored bool       `json:"sponsored"`
	Scheduled bool       `json:"scheduled"`
	Stream    StreamType `json:"stream"`
}

FeaturedType - describes the relationship a stream has if it is featured

type FollowsChannelType

type FollowsChannelType struct {
	CreatedAt     string            `json:"created_at"`
	Notifications bool              `json:"notifications"`
	User          UserType          `json:"user"`
	Links         map[string]string `json:"_links"`
}

FollowsChannelType - struct describing a following channel

type FollowsUserType

type FollowsUserType struct {
	CreatedAt     string            `json:"created_at"`
	Notifications bool              `json:"notifications"`
	Channel       ChannelType       `json:"channel"`
	Links         map[string]string `json:"_links"`
}

FollowsUserType - struct describing a following user

type Game

type Game struct {
	GameInfo GameInfo `json:"game"`
	Viewers  int      `json:"viewers"`
	Channels int      `json:"channels"`
}

Game - describes a game on twitch

type GameInfo

type GameInfo struct {
	Name        string            `json:"name"`
	Box         map[string]string `json:"box"`
	Links       map[string]string `json:"_links"`
	ID          int               `json:"_id"`
	GiantBombID int               `json:"giantbomb_id"`
}

GameInfo - details about the specific game

type GetAllTeamsInputType

type GetAllTeamsInputType struct {
	Limit  int `url:"limit,omitempty"`
	Offset int `url:"offset,omitempty"`
}

GetAllTeamsInputType - request parameters for the GetAllTeams function

type GetAllTeamsOutputType

type GetAllTeamsOutputType struct {
	Teams []TeamType        `json:"teams"`
	Links map[string]string `json:"_links"`
}

GetAllTeamsOutputType - contains a list of teams

type GetChannelFollowsInputType

type GetChannelFollowsInputType struct {
	Channel   string
	Limit     int    `url:"limit,omitempty"`
	Cursor    string `url:"cursor,omitempty"`
	Direction string `url:"direction,omitempty"`
}

GetChannelFollowsInputType - request type for querying users following a channel

type GetChannelFollowsOutputType

type GetChannelFollowsOutputType struct {
	Total   int               `json:"_total"`
	Cursor  string            `json:"_cursor"`
	Follows []FollowsUserType `json:"follows"`
	Links   map[string]string `json:"_links"`
}

GetChannelFollowsOutputType - response type containing users following a channel

type GetChannelInputType

type GetChannelInputType struct {
	Channel string
}

GetChannelInputType - input type for the GetChannel function

type GetChannelOutputType

type GetChannelOutputType ChannelType

GetChannelOutputType - returned type containing the channel

type GetChannelTeamsInputType

type GetChannelTeamsInputType struct {
	Channel string
}

GetChannelTeamsInputType - input type for the GetChannelTeams function

type GetChannelTeamsOutputType

type GetChannelTeamsOutputType struct {
	Teams []TeamType        `json:"teams"`
	Links map[string]string `json:"_links"`
}

GetChannelTeamsOutputType - returned type container an array of teams

type GetChannelVideosInputType

type GetChannelVideosInputType struct {
	Channel    string
	Broadcasts bool `url:"broadcasts,omitempty"`
	HLS        bool `url:"hls,omitempty"`
	Limit      int  `url:"limit,omitempty"`
	Offset     int  `url:"offset,omitempty"`
}

GetChannelVideosInputType - request parameters for the GetChannelVideos function

type GetChannelVideosOutputType

type GetChannelVideosOutputType struct {
	Videos []VideoType       `json:"videos"`
	Total  int               `json:"total"`
	Links  map[string]string `json:"_links"`
}

GetChannelVideosOutputType - contains a list of videos for the specified channel

type GetFeaturedStreamsInputType

type GetFeaturedStreamsInputType struct {
	Limit  int `url:"limit,omitempty"`
	Offset int `url:"offset,omitempty"`
}

GetFeaturedStreamsInputType - input parameters for the GetFeaturedStreams function

type GetFeaturedStreamsOutputType

type GetFeaturedStreamsOutputType struct {
	Featured []FeaturedType    `json:"featured"`
	Links    map[string]string `json:"_links"`
}

GetFeaturedStreamsOutputType - contains a list of featured streams

type GetIngestsOutputType

type GetIngestsOutputType struct {
	Ingests []IngestType      `json:"ingests"`
	Links   map[string]string `json:"_links"`
}

GetIngestsOutputType - contains an array of ingest types

type GetStreamByChannelInputType

type GetStreamByChannelInputType struct {
	Channel string `url:"channel"`
}

GetStreamByChannelInputType - specifies the channel for the GetStreamByChannel function

type GetStreamByChannelOutputType

type GetStreamByChannelOutputType struct {
	Stream StreamType        `json:"stream"`
	Links  map[string]string `json:"_links"`
}

GetStreamByChannelOutputType - response for the GetStreamByChannel function

type GetStreamsInputType

type GetStreamsInputType struct {
	Game       string `url:"game,omitempty"`
	Channel    string `url:"channel,omitempty"`
	Limit      int    `url:"limit,omitempty"`
	Offset     int    `url:"offset,omitempty"`
	ClientID   string `url:"client_id,omitempty"`
	StreamType string `url:"stream_type,omitempty"`
	Language   string `url:"language,omitempty"`
}

GetStreamsInputType - request paramaters for the GetStream function

type GetStreamsOutputType

type GetStreamsOutputType struct {
	Total   int               `json:"_total"`
	Streams []StreamType      `json:"streams"`
	Links   map[string]string `json:"_links"`
}

GetStreamsOutputType - response for the GetStream function

type GetStreamsSummaryInputType

type GetStreamsSummaryInputType struct {
	Game string `url:"game,omitempty"`
}

GetStreamsSummaryInputType - contains the game to scope the query to

type GetStreamsSummaryOutputType

type GetStreamsSummaryOutputType struct {
	Viewers  int               `json:"viewers"`
	Links    map[string]string `json:"_links"`
	Channels int               `json:"channels"`
}

GetStreamsSummaryOutputType - response object describing the summary of a game

type GetTeamInputType

type GetTeamInputType struct {
	Team string
}

GetTeamInputType - specifies the team name

type GetTeamOutputType

type GetTeamOutputType TeamType

GetTeamOutputType - containers the team

type GetTopGamesInputType

type GetTopGamesInputType struct {
	Limit  int `url:"limit,omitempty"`
	Offset int `url:"offset,omitempty"`
}

GetTopGamesInputType - request type for GetTopGames

type GetTopGamesOutputType

type GetTopGamesOutputType struct {
	Links map[string]string `json:"_links"`
	Total int               `json:"_total"`
	Top   []Game            `json:"top"`
}

GetTopGamesOutputType - response type containing an array of games

type GetTopVideosInputType

type GetTopVideosInputType struct {
	Game   string `url:"game,omitempty"`
	Period string `url:"period,omitempty"`
	Limit  int    `url:"limit,omitempty"`
	Offset int    `url:"offset,omitempty"`
}

GetTopVideosInputType - request paramaters for the GetTopVideos function

type GetTopVideosOutputType

type GetTopVideosOutputType struct {
	Videos []VideoType       `json:"videos"`
	Links  map[string]string `json:"_links"`
}

GetTopVideosOutputType - contains a list of top videos

type GetUserFollowsChannelInputType

type GetUserFollowsChannelInputType struct {
	User    string
	Channel string
}

GetUserFollowsChannelInputType - request type container user and channel

type GetUserFollowsChannelOutputType

type GetUserFollowsChannelOutputType struct {
	Follows       bool
	CreatedAt     string            `json:"created_at"`
	Notifications bool              `json:"notifications"`
	Channel       ChannelType       `json:"channel"`
	Links         map[string]string `json:"_links"`
}

GetUserFollowsChannelOutputType - response type container wether a user follows the spcified channel

type GetUserFollowsInputType

type GetUserFollowsInputType struct {
	User      string
	Limit     int    `url:"limit,omitempty"`
	Direction string `url:"direction,omitempty"`
	SortyBy   string `url:"sortby,omitempty"`
}

GetUserFollowsInputType - request type for querying what channels a user follows

type GetUserFollowsOutputType

type GetUserFollowsOutputType struct {
	Total   int                  `json:"_total"`
	Cursor  string               `json:"_cursor"`
	Follows []FollowsChannelType `json:"follows"`
	Links   map[string]string    `json:"_links"`
}

GetUserFollowsOutputType - response type containing channels a user follows

type IngestType

type IngestType struct {
	Name         string  `json:"name"`
	Default      bool    `json:"default"`
	ID           int     `json:"_id"`
	URLTemplate  string  `json:"url_template"`
	Availability float64 `json:"availability"`
}

IngestType - type described ingest endpoints for twitch

type NewSessionInput

type NewSessionInput struct {
	URL           *url.URL
	VersionHeader string
	ClientID      string // required
}

NewSessionInput - input struct for creating a new session

type SearchChannelsInputType

type SearchChannelsInputType struct {
	Query  string `url:"query,omitempty"`
	Limit  int    `url:"limit,omitempty"`
	Offset int    `url:"offset,omitempty"`
}

SearchChannelsInputType - specifies the query parameters for a channel search

type SearchChannelsOutputType

type SearchChannelsOutputType struct {
	Channels []ChannelType     `json:"channels"`
	Total    int               `json:"_total"`
	Links    map[string]string `json:"_links"`
}

SearchChannelsOutputType - contains the results for a channel search

type SearchGamesInputType

type SearchGamesInputType struct {
	Query string `url:"query,omitempty"`
	Type  string `url:"type,omitempty"`
	Live  bool   `url:"live,omitempty"`
}

SearchGamesInputType - specifies the query parameters for a game search

type SearchGamesOutputType

type SearchGamesOutputType struct {
	Games []StreamType      `json:"games"`
	Links map[string]string `json:"_links"`
}

SearchGamesOutputType - contains the results for a game search

type SearchStreamsInputType

type SearchStreamsInputType struct {
	Query  string `url:"query,omitempty"`
	Limit  int    `url:"limit,omitempty"`
	Offset int    `url:"offset,omitempty"`
	HLS    bool   `url:"hls,omitempty"`
}

SearchStreamsInputType - specifies the query parameters for a stream search

type SearchStreamsOutputType

type SearchStreamsOutputType struct {
	Streams []StreamType      `json:"streams"`
	Total   int               `json:"_total"`
	Links   map[string]string `json:"_links"`
}

SearchStreamsOutputType - contains the results for a stream search

type Session

type Session struct {
	Client        *http.Client
	URL           *url.URL
	VersionHeader string
	ClientID      string
}

Session represents a persistent connection to Twitch

func NewSession

func NewSession(input NewSessionInput) (*Session, error)

NewSession creates and returns a new Twtich session

func (*Session) CheckClientID

func (session *Session) CheckClientID() error

CheckClientID ensures that the client ID is correct. This is done by performing a get to the root of twitch and confirming that the response's identified field is true

func (*Session) GetAllTeams

func (session *Session) GetAllTeams() (*GetAllTeamsOutputType, error)

GetAllTeams - returns all the teams on twitch

func (*Session) GetChannel

func (session *Session) GetChannel(getChannelInputType *GetChannelInputType) (*GetChannelOutputType, error)

GetChannel - returns the specified channel

func (*Session) GetChannelFollows

func (session *Session) GetChannelFollows(getChannelFollowsInputType *GetChannelFollowsInputType) (*GetChannelFollowsOutputType, error)

GetChannelFollows - returns the users who follow the specified channel

func (*Session) GetChannelTeams

func (session *Session) GetChannelTeams(getChannelTeamsInputType *GetChannelTeamsInputType) (*GetChannelTeamsOutputType, error)

GetChannelTeams - - returns an array of the teams the specified channel belongs to

func (*Session) GetChannelVideos

func (session *Session) GetChannelVideos(getChannelVideosInputType *GetChannelVideosInputType) (*GetChannelVideosOutputType, error)

GetChannelVideos - returns the videos for the specified channel

func (*Session) GetFeaturedStreams

func (session *Session) GetFeaturedStreams(getFeaturedStreamsInputType *GetFeaturedStreamsInputType) (*GetFeaturedStreamsOutputType, error)

GetFeaturedStreams - returns the featured streams

func (*Session) GetIngests

func (session *Session) GetIngests() (*GetIngestsOutputType, error)

GetIngests - returns the ingest endpoints available for twitch

func (*Session) GetStream

func (session *Session) GetStream(getStreamsInputType *GetStreamsInputType) (*GetStreamsOutputType, error)

GetStream - returns the streams matching the input parameters

func (*Session) GetStreamByChannel

func (session *Session) GetStreamByChannel(getStreamByChannelInputType *GetStreamByChannelInputType) (*GetStreamByChannelOutputType, error)

GetStreamByChannel - returns the current stream for a channel

func (*Session) GetStreamsSummary

func (session *Session) GetStreamsSummary(getStreamsSummaryInputType *GetStreamsSummaryInputType) (*GetStreamsSummaryOutputType, error)

GetStreamsSummary - returns the summary of a game on twitch

func (*Session) GetTeam

func (session *Session) GetTeam(getTeamInputType *GetTeamInputType) (*GetTeamOutputType, error)

GetTeam - returns the specified team

func (*Session) GetTopGames

func (session *Session) GetTopGames(getTopeGamesInputType *GetTopGamesInputType) (*GetTopGamesOutputType, error)

GetTopGames - returns the top games at the time of request on twitch

func (*Session) GetTopVideos

func (session *Session) GetTopVideos(getTopVideosInputType *GetTopVideosInputType) (*GetTopVideosOutputType, error)

GetTopVideos - returns the top videos for a specified game

func (*Session) GetUserFollows

func (session *Session) GetUserFollows(getUserFollowsInputType *GetUserFollowsInputType) (*GetUserFollowsOutputType, error)

GetUserFollows - returns the channels that a specified user follows

func (*Session) GetUserFollowsChannel

func (session *Session) GetUserFollowsChannel(getUserFollowsChannelInputType *GetUserFollowsChannelInputType) (*GetUserFollowsChannelOutputType, error)

GetUserFollowsChannel - returns wether a user follows the specified channel

func (*Session) SearchChannels

func (session *Session) SearchChannels(searchChannelsInputType *SearchChannelsInputType) (*SearchChannelsOutputType, error)

SearchChannels - returns channels matching the query

func (*Session) SearchGames

func (session *Session) SearchGames(searchGamesInputType *SearchGamesInputType) (*SearchGamesOutputType, error)

SearchGames - returns games matching the query

func (*Session) SearchStreams

func (session *Session) SearchStreams(searchStreamsInputType *SearchStreamsInputType) (*SearchStreamsOutputType, error)

SearchStreams - returns streams matching the query

type StreamType

type StreamType struct {
	Game        string            `json:"game"`
	Viewers     int               `json:"viewers"`
	AverageFPS  float32           `json:"average_fps"`
	Delay       int               `json:"delay"`
	VideoHeight int               `json:"video_height"`
	IsPlaylist  bool              `json:"is_playlist"`
	CreatedAt   string            `json:"created_at"`
	ID          int               `json:"_id"`
	Channel     ChannelType       `json:"channel"`
	Preview     map[string]string `json:"preview"`
	Links       map[string]string `json:"_links"`
}

StreamType - describes a stream

type TeamType

type TeamType struct {
	ID          int               `json:"_id"`
	Name        string            `json:"name"`
	Info        string            `json:"info"`
	DisplayName string            `json:"display_name"`
	CreatedAt   string            `json:"created_at"`
	UpdatedAt   string            `json:"updated_at"`
	Banner      string            `json:"banner"`
	Background  string            `json:"background"`
	Links       map[string]string `json:"_links"`
}

TeamType - describes a team on twitch

type UserType

type UserType struct {
	Type        string            `json:"type"`
	Bio         string            `json:"bio"`
	DisplayName string            `json:"display_name"`
	CreatedAt   string            `json:"created_at"`
	UpdatedAt   string            `json:"updated_at"`
	ID          int               `json:"_id"`
	Name        string            `json:"name"`
	Links       map[string]string `json:"_links"`
}

UserType - describes a user on twitch

type VideoType

type VideoType struct {
	Title         string            `json:"title"`
	Description   string            `json:"description"`
	BroadcastID   int64             `json:"broadcast_id"`
	Status        string            `json:"status"`
	ID            string            `json:"_id"`
	TagList       string            `json:"tag_list"`
	RecordedAt    string            `json:"recorded_at"`
	Game          interface{}       `json:"game"`
	Length        int               `json:"length"`
	Preview       string            `json:"preview"`
	URL           string            `json:"url"`
	Views         int               `json:"views"`
	BroadcastType string            `json:"broadcast_type"`
	Links         map[string]string `json:"_links"`
	Channel       struct {
		Name        string `json:"name"`
		DisplayName string `json:"display_name"`
	} `json:"channel"`
}

VideoType - describes a saved or highlighted video on twitch

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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