56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
package gueststar
|
||
|
||
import (
|
||
"context"
|
||
"fmt"
|
||
"net/http"
|
||
"net/url"
|
||
|
||
"github.com/google/go-querystring/query"
|
||
)
|
||
|
||
type UpdateGuestStarSlot struct {
|
||
// The ID of the broadcaster running the Guest Star session.
|
||
BroadcasterID string `url:"broadcaster_id"`
|
||
|
||
// The ID of the broadcaster or a user that has permission to moderate the broadcaster’s chat room.
|
||
// This ID must match the user_id in the user access token.
|
||
ModeratorID string `url:"moderator_id"`
|
||
|
||
// The ID of the Guest Star session in which to update slot settings.
|
||
SessionID string `url:"session_id"`
|
||
|
||
// The slot assignment previously assigned to a user.
|
||
SourceSlotID int `url:"source_slot_id"`
|
||
|
||
// The slot to move this user assignment to. If the destination slot is occupied, the user assigned will be swapped into source_slot_id.
|
||
DestinationSlotID int `url:"destination_slot_id"`
|
||
}
|
||
|
||
// Allows a user to update the assigned slot for a particular user within the active Guest Star session.
|
||
//
|
||
// Query parameter moderator_id must match the user_id in the User-Access token
|
||
// Requires OAuth Scope: channel:manage:guest_star or moderator:manage:guest_star
|
||
func (g *GuestStar) UpdateGuestStarSlot(ctx context.Context, params *UpdateGuestStarSlot) error {
|
||
v, _ := query.Values(params)
|
||
endpoint := g.baseUrl.ResolveReference(&url.URL{Path: "guest_star/slot", RawQuery: v.Encode()})
|
||
|
||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
|
||
res, err := g.client.Do(req)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
defer res.Body.Close()
|
||
|
||
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
||
if !statusOK {
|
||
return fmt.Errorf("failed to update guest star slot (%d)", res.StatusCode)
|
||
}
|
||
|
||
return nil
|
||
}
|