2024-03-03 18:00:22 -05:00
|
|
|
|
package teams
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
2024-03-07 19:41:05 -05:00
|
|
|
|
"fmt"
|
2024-03-03 18:00:22 -05:00
|
|
|
|
"net/http"
|
|
|
|
|
"net/url"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type GetChannelTeamsResponse struct {
|
|
|
|
|
// The list of teams that the broadcaster is a member of.
|
|
|
|
|
// Returns an empty array if the broadcaster is not a member of a team.
|
|
|
|
|
Teams []ChannelTeam `json:"teams"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ChannelTeam struct {
|
|
|
|
|
// The ID that 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"`
|
|
|
|
|
|
|
|
|
|
// A URL to the team’s background image.
|
|
|
|
|
BackgroundImageURL string `json:"background_image_url"`
|
|
|
|
|
|
|
|
|
|
// A URL to the team’s banner.
|
|
|
|
|
Banner string `json:"banner"`
|
|
|
|
|
|
|
|
|
|
// The UTC date and time (in RFC3339 format) of when the team was created.
|
|
|
|
|
CreatedAt time.Time `json:"created_at"`
|
|
|
|
|
|
|
|
|
|
// The UTC date and time (in RFC3339 format) of the last time the team was updated.
|
|
|
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
|
|
|
|
|
|
|
|
// The team’s description. The description may contain formatting such as Markdown, HTML, newline (\n) characters, etc.
|
|
|
|
|
Info string `json:"info"`
|
|
|
|
|
|
|
|
|
|
// A URL to a thumbnail image of the team’s logo.
|
|
|
|
|
ThumbnailURL string `json:"thumbnail_url"`
|
|
|
|
|
|
|
|
|
|
// The team’s name.
|
|
|
|
|
TeamName string `json:"team_name"`
|
|
|
|
|
|
|
|
|
|
// The team’s display name.
|
|
|
|
|
TeamDisplayName string `json:"team_display_name"`
|
|
|
|
|
|
|
|
|
|
// An ID that identifies the team.
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Gets the list of Twitch teams that the broadcaster is a member of.
|
|
|
|
|
//
|
|
|
|
|
// Requires an app access token or user access token.
|
|
|
|
|
func (c *Teams) GetChannelTeams(ctx context.Context, broadcasterID string) (*GetChannelTeamsResponse, error) {
|
|
|
|
|
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "teams/channel", RawQuery: url.Values{"broadcaster_id": {broadcasterID}}.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()
|
|
|
|
|
|
2024-03-07 19:41:05 -05:00
|
|
|
|
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
|
|
|
|
if !statusOK {
|
|
|
|
|
return nil, fmt.Errorf("failed to get channel teams (%d)", res.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-03 18:00:22 -05:00
|
|
|
|
var data GetChannelTeamsResponse
|
|
|
|
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &data, nil
|
|
|
|
|
}
|