94 lines
3.3 KiB
Go
94 lines
3.3 KiB
Go
package channels
|
||
|
||
import (
|
||
"context"
|
||
"encoding/json"
|
||
"net/http"
|
||
"net/url"
|
||
|
||
"github.com/google/go-querystring/query"
|
||
"go.fifitido.net/twitch/api/ccls"
|
||
)
|
||
|
||
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 weren’t found.
|
||
Data []ChannelInformation `json:"data"`
|
||
}
|
||
|
||
type ChannelInformation struct {
|
||
// An ID that uniquely identifies the broadcaster.
|
||
BroadcasterID string `json:"broadcaster_id"`
|
||
|
||
// The broadcaster’s login name.
|
||
BroadcasterLogin string `json:"broadcaster_login"`
|
||
|
||
// The broadcaster’s display name.
|
||
BroadcasterName string `json:"broadcaster_name"`
|
||
|
||
// The broadcaster’s 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 broadcaster’s stream delay setting, in seconds.
|
||
// This field’s 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"`
|
||
|
||
// 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) {
|
||
v, _ := query.Values(params)
|
||
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channels", RawQuery: v.Encode()})
|
||
|
||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
res, err := c.client.Do(req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
defer res.Body.Close()
|
||
|
||
var data GetChannelInformdationResponse
|
||
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return &data, nil
|
||
}
|