go-twitch/api/channels/get_channel_information.go

87 lines
3.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package channels
import (
"encoding/json"
"net/url"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/types"
)
type GetChannelInformationParams struct {
// The ID of the broadcaster whose channel you want to get. To specify more than one ID, include this parameter for each broadcaster you want to get.
// For example, broadcaster_id=1234&broadcaster_id=5678. You may specify a maximum of 100 IDs. The API ignores duplicate IDs and IDs that are not found.
BroadcasterIDs []string `url:"broadcaster_id,omitempty"`
}
type GetChannelInformdationResponse struct {
// A list that contains information about the specified channels. The list is empty if the specified channels werent found.
Data []ChannelInformation `json:"data"`
}
type ChannelInformation struct {
// An ID that uniquely identifies the broadcaster.
BroadcasterID string `json:"broadcaster_id"`
// The broadcasters login name.
BroadcasterLogin string `json:"broadcaster_login"`
// The broadcasters display name.
BroadcasterName string `json:"broadcaster_name"`
// The broadcasters preferred language. The value is an ISO 639-1 two-letter language code (for example, en for English).
// The value is set to “other” if the language is not a Twitch supported language.
BroadcasterLanguage string `json:"broadcaster_language"`
// The name of the game that the broadcaster is playing or last played. The value is an empty string if the broadcaster has never played a game.
GameName string `json:"game_name"`
// An ID that uniquely identifies the game that the broadcaster is playing or last played.
// The value is an empty string if the broadcaster has never played a game.
GameID string `json:"game_id"`
// The title of the stream that the broadcaster is currently streaming or last streamed. The value is an empty string if the broadcaster has never streamed.
Title string `json:"title"`
// The value of the broadcasters stream delay setting, in seconds.
// This fields value defaults to zero unless
//
// 1) the request specifies a user access token
//
// 2) the ID in the broadcaster_id query parameter matches the user ID in the access token
//
// 3) the broadcaster has partner status and they set a non-zero stream delay value.
Delay uint `json:"delay"`
// The tags applied to the channel.
Tags []string `json:"tags"`
// The CCLs applied to the channel.
ContentClassficationLabels []types.CCL `json:"content_classification"`
// Boolean flag indicating if the channel has branded content.
IsBrandedContent bool `json:"is_branded_content"`
}
// Gets information about one or more channels.
//
// Requires an app access token or user access token.
func (c *Channels) GetChannelInformation(params *GetChannelInformationParams) (*GetChannelInformdationResponse, error) {
v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channels", RawQuery: v.Encode()})
resp, err := c.client.Get(endpoint.String())
if err != nil {
return nil, err
}
defer resp.Body.Close()
var data GetChannelInformdationResponse
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}