go-twitch/api/gueststar/get_channel_gueststar_setti...

56 lines
1.7 KiB
Go
Raw Permalink Normal View History

2024-03-03 14:09:31 -05:00
package gueststar
import (
"context"
"encoding/json"
"fmt"
2024-03-03 14:09:31 -05:00
"net/http"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
2024-03-03 14:09:31 -05:00
)
type GetChannelGuestStarSettingsParams struct {
// The ID of the broadcaster you want to get guest star settings for.
BroadcasterID string `url:"broadcaster_id"`
// The ID of the broadcaster or a user that has permission to moderate the broadcasters chat room.
// This ID must match the user ID in the user access token.
ModeratorID string `url:"moderator_id"`
}
type GetChannelGuestStarSettingsResponse struct {
Data []ChannelSettings `json:"data"`
}
// Gets the channel settings for configuration of the Guest Star feature for a particular host.
//
// Query parameter moderator_id must match the user_id in the User-Access token
// Requires OAuth Scope: channel:read:guest_star, channel:manage:guest_star, moderator:read:guest_star or moderator:manage:guest_star
func (g *GuestStar) GetChannelGuestStarSettings(ctx context.Context, params *GetChannelGuestStarSettingsParams) (*GetChannelGuestStarSettingsResponse, error) {
v, _ := query.Values(params)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(g.baseUrl, "guest_star/channel_settings", v), nil)
2024-03-03 14:09:31 -05:00
if err != nil {
return nil, err
}
res, err := g.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 guest star settings (%d)", res.StatusCode)
}
2024-03-03 14:09:31 -05:00
var data GetChannelGuestStarSettingsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}