twitch

package module
v0.0.0-...-f1f107e Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2019 License: MIT Imports: 7 Imported by: 2

README

twitchgo

Go client library to make requests to Twitch

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel struct {
	Mature                       bool      `json:"mature"`
	Status                       string    `json:"status"`
	BroadcasterLanguage          string    `json:"broadcaster_language"`
	BroadcasterType              string    `json:"broadcaster_type"`
	DisplayName                  string    `json:"display_name"`
	Game                         string    `json:"game"`
	Delay                        int64     `json:"delay"`
	Language                     string    `json:"language"`
	Id                           int64     `json:"_id"`
	Name                         string    `json:"name"`
	CreatedAt                    time.Time `json:"created_at"`
	UpdatedAt                    time.Time `json:"updated_at"`
	Banner                       string    `json:"banner"`
	VideoBanner                  string    `json:"video_banner"`
	ProfileBanner                string    `json:"profile_banner"`
	ProfileBannerBackgroundColor string    `json:"profile_banner_background_color"`
	Partner                      bool      `json:"partner"`
	Views                        int64     `json:"views"`
	Followers                    int64     `json:"followers"`
}

type CommonChannelFields

type CommonChannelFields struct {
	Mature                       bool      `json:"mature"`
	Status                       string    `json:"status"`
	BroadcasterLanguage          string    `json:"broadcaster_language"`
	BroadcasterType              string    `json:"broadcaster_type"`
	DisplayName                  string    `json:"display_name"`
	Game                         string    `json:"game"`
	Delay                        int64     `json:"delay"`
	Language                     string    `json:"language"`
	Id                           int64     `json:"_id"`
	Name                         string    `json:"name"`
	CreatedAt                    time.Time `json:"created_at"`
	UpdatedAt                    time.Time `json:"updated_at"`
	Banner                       string    `json:"banner"`
	VideoBanner                  string    `json:"video_banner"`
	ProfileBanner                string    `json:"profile_banner"`
	ProfileBannerBackgroundColor string    `json:"profile_banner_background_color"`
	Partner                      bool      `json:"partner"`
	Views                        int64     `json:"views"`
	Followers                    int64     `json:"followers"`
}

type Follow

type Follow struct {
	CreatedAt     time.Time `json:"created_at"`
	Id            string    `json:"_id"`
	User          User      `json:"user"`
	Notifications bool      `json:"notifications"`
}

type FollowResponse

type FollowResponse struct {
	Total   int64    `json:"_total"`
	Follows []Follow `json:"follows"`
}

type HelixUser

type HelixUser 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       int64  `json:"view_count"`
	Email           string `json:"email"`
}

func (*HelixUser) IsPartnered

func (user *HelixUser) IsPartnered() bool

type HelixVideo

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

type HelixVideosResponse

type HelixVideosResponse struct {
	Videos     []HelixVideo `json:"data"`
	Pagination map[string]string
}

type RequestOptions

type RequestOptions struct {
	Limit     int64  `url:"limit"`
	Offset    int64  `url:"offset"`
	Direction string `url:"direction"`
	Nonce     int64  `url:"_"`
	Channel   string `url:"channel"`
	Version   string
	Extra     *url.Values
}

type Stream

type Stream struct {
	CreatedAt time.Time `json:"created_at"`
	Id        int64     `json:"_id"`
	Viewers   int64     `json:"viewers"`
	Game      string    `json:"game"`
	Channel   Channel   `json:"channel"`

	// StreamType is only avaliable when querying with the V5 endpoint.
	StreamType string `json:"stream_type"`
}

type StreamResponse

type StreamResponse struct {
	Total  int64   `json:"_total"`
	Stream *Stream `json:"stream"`
}

type StreamsResponse

type StreamsResponse struct {
	Total   int64    `json:"_total"`
	Streams []Stream `json:"streams"`
}

type Subscription

type Subscription struct {
	CreatedAt time.Time `json:"created_at"`
	Id        string    `json:"_id"`
	User      User      `json:"user"`
}

type SubscriptionResponse

type SubscriptionResponse struct {
	Total         int64          `json:"_total"`
	Subscriptions []Subscription `json:"subscriptions"`
}

type TwitchChannel

type TwitchChannel interface {
	// GetBroadcasterType can be one of [partner|affiliate|”]
	GetBroadcasterType() string

	// GetProfileBanner returns the URL of the channel's profile banner, if set
	GetProfileBanner() string
}

type TwitchClient

type TwitchClient struct {
	HttpClient *http.Client
	ClientID   string
}

func NewTwitchClient

func NewTwitchClient(clientID string) TwitchClient

func NewTwitchClientWithHTTPClient

func NewTwitchClientWithHTTPClient(clientID string, httpClient *http.Client) TwitchClient

func (*TwitchClient) GetChannel

func (client *TwitchClient) GetChannel(channel string) (*Channel, error)

GetChannel requests channel information from Twitch. It returns a Channel struct if successful and any error encountered.

func (*TwitchClient) GetChannelFollows

func (client *TwitchClient) GetChannelFollows(channel string, options *RequestOptions) FollowResponse

func (*TwitchClient) GetChannelForId

func (client *TwitchClient) GetChannelForId(channelId int64) (TwitchChannel, error)

GetChannelForId requests channel information for the given channel ID. It returns a Channel struct if successful and any error encountered.

func (*TwitchClient) GetChannelForName

func (client *TwitchClient) GetChannelForName(channelName string) (TwitchChannel, error)

GetChannelForName requests channel information for the given channel name. It returns a v3Channel struct if successful and any error encountered.

func (*TwitchClient) GetChannelStream

func (client *TwitchClient) GetChannelStream(channel string, options *RequestOptions) (StreamResponse, error)

func (*TwitchClient) GetChannelSubscriptions

func (client *TwitchClient) GetChannelSubscriptions(channel string, options *RequestOptions) SubscriptionResponse

func (*TwitchClient) GetChannelVideos

func (client *TwitchClient) GetChannelVideos(channel string, broadcasts bool, limit int64) (VideosResponse, error)

func (*TwitchClient) GetChannelsStream

func (client *TwitchClient) GetChannelsStream(channels ...string) (StreamsResponse, error)

func (*TwitchClient) GetChannelsStreamV5

func (client *TwitchClient) GetChannelsStreamV5(channelIDs ...string) (StreamsResponse, error)

func (*TwitchClient) GetFollowersForID

func (client *TwitchClient) GetFollowersForID(userID string, options *RequestOptions) (helixFollowResponse, error)

GetFollowersForID requests follower information for a user/channel ID.

https://dev.twitch.tv/docs/api/reference/#get-users-follows

Follower data is sorted by Twitch: most recent follower first.

A pagination cursor may be available in yourResponse.Pagination["cursor"]. This can be supplied in the options.Extra struct with the key "after" on subsequent calls.

func (*TwitchClient) GetStreamsForIDs

func (client *TwitchClient) GetStreamsForIDs(options *RequestOptions, channelIDs ...string) (res helixStreamsResponse, err error)

GetStreamsForIDs requests stream info for one or more channels.

https://dev.twitch.tv/docs/api/reference/#get-streams

A pagination cursor may be available in yourResponse.Pagination["cursor"]. This can be supplied in the options.Extra struct with the key "after" on subsequent calls.

func (*TwitchClient) GetSubscribersForID

func (client *TwitchClient) GetSubscribersForID(userID string, options *RequestOptions) (res helixSubscriptionResponse, err error)

GetSubscribersForID requests subscriber info for a user/channel ID.

https://dev.twitch.tv/docs/api/reference/#get-broadcaster-subscriptions

Note: Twitch requires an OAuth access token with the `channel:read:subscriptions` scope in order to access subscriber information for the matching user.

A pagination cursor may be available in yourResponse.Pagination["cursor"]. This can be supplied in the options.Extra struct with the key "after" on subsequent calls.

func (*TwitchClient) GetUser

func (client *TwitchClient) GetUser(username string) (*User, error)

func (*TwitchClient) GetUsers

func (client *TwitchClient) GetUsers(id, login []string) (*[]HelixUser, error)

func (*TwitchClient) GetVideosForID

func (client *TwitchClient) GetVideosForID(userID string, options *RequestOptions) (res HelixVideosResponse, err error)

GetVideosForID requests video info for a user/channel ID.

https://dev.twitch.tv/docs/api/reference/#get-videos

A pagination cursor may be available in yourResponse.Pagination["cursor"]. This can be supplied in the options.Extra struct with the key "after" on subsequent calls.

type User

type User struct {
	DisplayName string    `json:"display_name"`
	Id          int64     `json:"_id"`
	Name        string    `json:"name"`
	Type        string    `json:"type"`
	Bio         string    `json:"bio"`
	Email       string    `json:"email"`
	Partnered   bool      `json:"partnered"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

type Video

type Video struct {
	CreatedAt time.Time `json:"created_at"`
	Id        string    `json:"_id"`
	Views     int64     `json:"views"`
	Game      string    `json:"game"`
	Title     string    `json:"title"`
	Channel   Channel   `json:"channel"`
	URL       string    `json:"url"`
	Status    string    `json:"status"`
}

type VideosResponse

type VideosResponse struct {
	Total  int64   `json:"_total"`
	Videos []Video `json:"videos"`
}

Directories

Path Synopsis
cmd
twitchClient
twitchClient is a simple CLI app for testing twitchgo API calls.
twitchClient is a simple CLI app for testing twitchgo API calls.

Jump to

Keyboard shortcuts

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