2024-03-03 15:14:59 -05:00
|
|
|
|
package moderation
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2024-03-07 19:41:05 -05:00
|
|
|
|
"fmt"
|
2024-03-03 15:14:59 -05:00
|
|
|
|
"net/http"
|
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
|
|
"github.com/google/go-querystring/query"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type AddChannelVIPParams struct {
|
|
|
|
|
// The ID of the user to give VIP status to.
|
|
|
|
|
UserID string `url:"user_id"`
|
|
|
|
|
|
|
|
|
|
// The ID of the broadcaster that’s adding the user as a VIP. This ID must match the user ID in the access token.
|
|
|
|
|
BroadcasterID string `url:"broadcaster_id"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Adds the specified user as a VIP in the broadcaster’s channel.
|
|
|
|
|
//
|
|
|
|
|
// Rate Limits: The broadcaster may add a maximum of 10 VIPs within a 10-second window.
|
|
|
|
|
//
|
|
|
|
|
// Requires a user access token that includes the channel:manage:vips scope.
|
|
|
|
|
func (m *Moderation) AddChannelVIP(ctx context.Context, params *AddChannelVIPParams) error {
|
|
|
|
|
v, _ := query.Values(params)
|
|
|
|
|
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "channels/vips", RawQuery: v.Encode()})
|
|
|
|
|
|
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res, err := m.client.Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
defer res.Body.Close()
|
|
|
|
|
|
2024-03-07 19:41:05 -05:00
|
|
|
|
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
|
|
|
|
if !statusOK {
|
|
|
|
|
return fmt.Errorf("failed to add channel VIP (%d)", res.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-03 15:14:59 -05:00
|
|
|
|
return nil
|
|
|
|
|
}
|