package teams import ( "context" "encoding/json" "fmt" "net/http" "net/url" "time" "go.fifitido.net/twitch/api/endpoint" ) 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 (t *Teams) GetChannelTeams(ctx context.Context, broadcasterID string) (*GetChannelTeamsResponse, error) { v := url.Values{"broadcaster_id": {broadcasterID}} req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(t.baseUrl, "teams/channel", v), nil) if err != nil { return nil, err } res, err := t.client.Do(req) if err != nil { return nil, err } defer res.Body.Close() statusOK := res.StatusCode >= 200 && res.StatusCode < 300 if !statusOK { return nil, fmt.Errorf("failed to get channel teams (%d)", res.StatusCode) } var data GetChannelTeamsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err } return &data, nil }