go-twitch/api/channels/get_channel_information.go

98 lines
3.4 KiB
Go
Raw Normal View History

2024-02-27 22:13:57 -05:00
package channels
import (
"context"
2024-02-27 22:13:57 -05:00
"encoding/json"
"fmt"
"net/http"
2024-02-27 22:13:57 -05:00
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/ccls"
"go.fifitido.net/twitch/api/endpoint"
2024-02-27 22:13:57 -05:00
)
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 []ccls.ContentClassificationLabel `json:"content_classification"`
2024-02-27 22:13:57 -05:00
// 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(ctx context.Context, params *GetChannelInformationParams) (*GetChannelInformdationResponse, error) {
2024-02-27 22:13:57 -05:00
v, _ := query.Values(params)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "channels", v), nil)
2024-02-27 22:13:57 -05:00
if err != nil {
return nil, err
}
res, err := c.client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
2024-02-27 22:13:57 -05:00
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get channel information (%d)", res.StatusCode)
}
2024-02-27 22:13:57 -05:00
var data GetChannelInformdationResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
2024-02-27 22:13:57 -05:00
return nil, err
}
return &data, nil
}