gotwitch

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2020 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

gotwitch Build Status

This branch is using the new helix api which is under development.

Example for getting a Stream object

package main

import (
    "fmt"

    "github.com/dankeroni/gotwitch"
)

var api = gotwitch.New("<ClientID>")

func main() {
    api.GetStream("pajlada", onSuccess, onHTTPError, onInternalError)
}

func onSuccess(stream gotwitch.Stream) {
    fmt.Printf("%+v\n", stream)
}

func onHTTPError(statusCode int, statusMessage, errorMessage string) {
    fmt.Println("statusCode:", statusCode)
    fmt.Println("statusMessage:", statusMessage)
    fmt.Println("errorMessage:", errorMessage)
}

func onInternalError(err error) {
    fmt.Println("internalError:", err)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotAuthenticated is returned by functions that requires user-authentication
	ErrNotAuthenticated = errors.New("not authenticated")

	// ErrMissingParameters is returned if parameters are not passed to a function that requires parameters
	ErrMissingParameters = errors.New("missing required parameters")

	// ErrCannotPassEmptyStringAsLookupValue is returned if
	ErrCannotPassEmptyStringAsLookupValue = errors.New("cannot pass empty string as lookup value")

	// ErrMissingID is returned if the ID class was not initialized properly for the helix api object
	ErrMissingID = errors.New("missing id class in helix class")

	// ErrMissingClientSecret is returned if a function requires a client secret to be set but no client secret has been set
	ErrMissingClientSecret = errors.New("missing client secret")
)
View Source
var (
	ErrGetUsersNoUsers      = errors.New("at least one user must be specified")
	ErrGetUsersTooManyUsers = errors.New("too many users specified")
)
View Source
var (
	// ErrInvalidCommercialLength is returned from StartCommercial if the commercial length parameter is INVALID
	ErrInvalidCommercialLength = errors.New("invalid commercial length")
)
View Source
var (
	// ErrMissingGameOrTitle is returned from V5's UpdateChannel in case neither a game or title has been passed to the parameters
	ErrMissingGameOrTitle = errors.New("missing required game or title parameters")
)

Functions

This section is empty.

Types

type Chatters

type Chatters struct {
	Moderators []string `json:"moderators"`
	Staff      []string `json:"staff"`
	Admins     []string `json:"admins"`
	GlobalMods []string `json:"global_mods"`
	Viewers    []string `json:"viewers"`
}

Chatters json to struct

type GetStreamsParameters

type GetStreamsParameters struct {
	GameID     string
	Language   string
	UserIDs    []string
	UserLogins []string
}

func NewGetStreamsParameters

func NewGetStreamsParameters() *GetStreamsParameters

func (*GetStreamsParameters) Apply

func (p *GetStreamsParameters) Apply(req *resty.Request)

func (*GetStreamsParameters) SetUserIDs

func (p *GetStreamsParameters) SetUserIDs(v []string) *GetStreamsParameters

func (*GetStreamsParameters) SetUserLogins

func (p *GetStreamsParameters) SetUserLogins(v []string) *GetStreamsParameters

func (*GetStreamsParameters) Validate

func (p *GetStreamsParameters) Validate() error

type GetUsersParameters

type GetUsersParameters struct {
	UserIDs    []string
	UserLogins []string
}

func NewGetUsersParameters

func NewGetUsersParameters() *GetUsersParameters

func (*GetUsersParameters) Apply

func (p *GetUsersParameters) Apply(req *resty.Request)

func (*GetUsersParameters) SetUserIDs

func (p *GetUsersParameters) SetUserIDs(v []string) *GetUsersParameters

func (*GetUsersParameters) SetUserLogins

func (p *GetUsersParameters) SetUserLogins(v []string) *GetUsersParameters

func (*GetUsersParameters) Validate

func (p *GetUsersParameters) Validate() error

type HelixError

type HelixError struct {
	Error   string `json:"error"`
	Status  int    `json:"status"`
	Message string `json:"message"`
}

type HelixResponse

type HelixResponse struct {
	Data interface{} `json:"data"`

	// TODO: Handle this
	Pagination interface{} `json:"pagination"`
}

type HelixStream

type HelixStream struct {
	ID           string    `json:"id"`
	UserID       string    `json:"user_id"`
	UserName     string    `json:"user_name"`
	GameID       string    `json:"game_id"`
	CommunityIds []string  `json:"community_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"`
}

HelixStream json to struct

type IDError

type IDError struct {
	Error   string `json:"error"`
	Status  int    `json:"status"`
	Message string `json:"message"`
}

type IDResponse

type IDResponse struct {
	Data interface{} `json:"data"`

	// TODO: Handle this
	Pagination interface{} `json:"pagination"`
}

type StartCommercialParameters

type StartCommercialParameters struct {
	Length int `json:"length"`
}

StartCommercialParameters are parameters sent through to the V5 StartCommercial function

func NewStartCommercialParameters

func NewStartCommercialParameters() *StartCommercialParameters

NewStartCommercialParameters creates a start commercial parameters struct with proper default values

func (*StartCommercialParameters) ResetLength

ResetLength resets the length of the parameters to its default value (30)

func (*StartCommercialParameters) SetLength

SetLength sets the commercial length to the given value. Note that parameter validity is now checked here, but in the StartCommercial function

func (*StartCommercialParameters) Validate

func (p *StartCommercialParameters) Validate() error

Validate validates the parameters

type TMIError

type TMIError json.RawMessage

type Token

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

type TwitchAPI

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

TwitchAPI struct

func New

func New(clientID string) *TwitchAPI

New instantiates a new TwitchAPI object

func (*TwitchAPI) Helix

func (a *TwitchAPI) Helix() *TwitchAPIHelix

Helix returns the Helix API object

func (*TwitchAPI) ID

func (a *TwitchAPI) ID() *TwitchAPIID

ID returns the ID API object

func (*TwitchAPI) SetClientSecret

func (a *TwitchAPI) SetClientSecret(clientSecret string)

SetClientSecret sets the client secret for the ID api

func (*TwitchAPI) SetDebug

func (a *TwitchAPI) SetDebug(v bool)

SetDebug sets the debug flag on all api objects resty client

func (*TwitchAPI) TMI

func (a *TwitchAPI) TMI() *TwitchAPITMI

TMI returns the TMI API object

func (*TwitchAPI) V5

func (a *TwitchAPI) V5() *TwitchAPIV5

V5 returns the V5 API object

type TwitchAPIHelix

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

func NewTwitchAPIHelix

func NewTwitchAPIHelix(clientID string, id *TwitchAPIID) *TwitchAPIHelix

func (*TwitchAPIHelix) Authenticate

func (a *TwitchAPIHelix) Authenticate(oauthToken string) error

func (*TwitchAPIHelix) Authenticated

func (a *TwitchAPIHelix) Authenticated() bool

func (*TwitchAPIHelix) GetStreams

func (a *TwitchAPIHelix) GetStreams(parameters *GetStreamsParameters) ([]HelixStream, error)

func (*TwitchAPIHelix) GetUsers

func (a *TwitchAPIHelix) GetUsers(parameters *GetUsersParameters) ([]User, error)

GetUsers request for GET https://api.twitch.tv/helix/users

func (*TwitchAPIHelix) GetWebhookSubscriptions

func (a *TwitchAPIHelix) GetWebhookSubscriptions(after, first string) (result WebhookSubscriptionsResponse, err error)

func (*TwitchAPIHelix) RefreshAppAccessToken

func (a *TwitchAPIHelix) RefreshAppAccessToken() (err error)

func (*TwitchAPIHelix) WebhookSubscribe

func (a *TwitchAPIHelix) WebhookSubscribe(callbackURL string, topic WebhookTopic, twitchUserID string, lease time.Duration, secret string) (result WebhookSubscribeResponse, err error)

type TwitchAPIID

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

func NewTwitchAPIID

func NewTwitchAPIID(clientID string) *TwitchAPIID

func (*TwitchAPIID) Authenticate

func (a *TwitchAPIID) Authenticate(oauthToken string) *TwitchAPIID

func (*TwitchAPIID) Authenticated

func (a *TwitchAPIID) Authenticated() bool

func (*TwitchAPIID) GetAppAccessToken

func (a *TwitchAPIID) GetAppAccessToken() (Token, error)

func (*TwitchAPIID) SetClientSecret

func (a *TwitchAPIID) SetClientSecret(clientSecret string)

func (*TwitchAPIID) Token

func (a *TwitchAPIID) Token(grantType string) (result Token, err error)

func (*TwitchAPIID) Validate

func (a *TwitchAPIID) Validate() (ValidateResponse, error)

Validate request for GET https://id.twitch.tv/oauth2/validate

type TwitchAPITMI

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

func NewTwitchAPITMI

func NewTwitchAPITMI(clientID string) *TwitchAPITMI

func (*TwitchAPITMI) GetChatters

func (a *TwitchAPITMI) GetChatters(login string) (Chatters, error)

type TwitchAPIV5

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

func NewTwitchAPIV5

func NewTwitchAPIV5(clientID string) *TwitchAPIV5

func (*TwitchAPIV5) Authenticate

func (a *TwitchAPIV5) Authenticate(oauthToken string) error

func (*TwitchAPIV5) Authenticated

func (a *TwitchAPIV5) Authenticated() bool

func (*TwitchAPIV5) StartCommercial

func (a *TwitchAPIV5) StartCommercial(channelID string, parameters *StartCommercialParameters) (rResult *V5StartCommercialResponse, err error)

StartCommercial request for GET https://dev.twitch.tv/docs/v5/reference/channels#start-channel-commercial

func (*TwitchAPIV5) UpdateChannel

func (a *TwitchAPIV5) UpdateChannel(channelID string, parameters *UpdateChannelParameters) (rResult *V5Channel, err error)

UpdateChannel request for GET https://api.twitch.tv/kraken/channel

type UpdateChannelParameters

type UpdateChannelParameters struct {
	Game  *string `json:"game,omitempty"`
	Title *string `json:"status,omitempty"`
}

UpdateChannelParameters are parameters sent through to the V5 Update Channel API

func NewUpdateChannelParameters

func NewUpdateChannelParameters() *UpdateChannelParameters

NewUpdateChannelParameters is a helper for creating an UpdateChannelParameters struct

func (*UpdateChannelParameters) ResetGame

ResetGame resets the game

func (*UpdateChannelParameters) ResetTitle

ResetTitle resets the title

func (*UpdateChannelParameters) SetGame

SetGame sets the game

func (*UpdateChannelParameters) SetTitle

SetTitle sets the title

func (*UpdateChannelParameters) Validate

func (p *UpdateChannelParameters) Validate() error

Validate validates the given parameters Rule #1: Either Game or Title MUST be set

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 json to struct (HELIX)

type V5Channel

type V5Channel struct {
	ID                           string      `json:"_id"`
	BroadcasterLanguage          string      `json:"broadcaster_language"`
	BroadcasterSoftware          string      `json:"broadcaster_software"`
	BroadcasterType              string      `json:"broadcaster_type"`
	CreatedAt                    string      `json:"created_at"`
	Description                  string      `json:"description"`
	DisplayName                  string      `json:"display_name"`
	Followers                    int         `json:"followers"`
	Game                         string      `json:"game"`
	Language                     string      `json:"language"`
	Mature                       bool        `json:"mature"`
	Name                         string      `json:"name"`
	Partner                      bool        `json:"partner"`
	PrivacyOptionsEnabled        bool        `json:"privacy_options_enabled"`
	PrivateVideo                 bool        `json:"private_video"`
	ProfileBanner                interface{} `json:"profile_banner"`
	ProfileBannerBackgroundColor interface{} `json:"profile_banner_background_color"`
	Status                       string      `json:"status"`
	UpdatedAt                    string      `json:"updated_at"`
	URL                          string      `json:"url"`
	VideoBanner                  interface{} `json:"video_banner"`
	Views                        int         `json:"views"`
}

V5Channel is the struct returned from the V5 channel get API

type V5Error

type V5Error struct {
	Error   string `json:"error"`
	Status  int    `json:"status"`
	Message string `json:"message"`
}

type V5StartCommercialResponse

type V5StartCommercialResponse struct {
	Length     int
	Message    string
	RetryAfter int
}

V5StartCommercialResponse is returned from V5's StartCommercial function The fields indicate how long the commercial will run and in how long another commercial can be run

type ValidateResponse

type ValidateResponse struct {
	ClientID string   `json:"client_id"`
	Login    string   `json:"login"`
	UserID   string   `json:"user_id"`
	Scopes   []string `json:"scopes"`
}

type WebhookSubscribeResponse

type WebhookSubscribeResponse json.RawMessage

type WebhookSubscription

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

type WebhookSubscriptionsResponse

type WebhookSubscriptionsResponse struct {
	Total int                   `json:"total"`
	Data  []WebhookSubscription `json:"data"`

	// TODO: Handle this
	Pagination interface{} `json:"pagination"`
}

type WebhookTopic

type WebhookTopic int
const (
	WebhookTopicFollowers WebhookTopic = iota
	WebhookTopicStreams
	WebhookTopicUserChanged
)

func (WebhookTopic) String

func (t WebhookTopic) String() string

func (WebhookTopic) URL

func (t WebhookTopic) URL(twitchUserID string) string

Jump to

Keyboard shortcuts

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