2024-03-03 14:09:31 -05:00
|
|
|
|
package gueststar
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2024-03-07 19:41:05 -05:00
|
|
|
|
"fmt"
|
2024-03-03 14:09:31 -05:00
|
|
|
|
"net/http"
|
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
|
|
"github.com/google/go-querystring/query"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type AssignGuestStarSlot 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 assign the slot.
|
|
|
|
|
SessionID string `url:"session_id"`
|
|
|
|
|
|
|
|
|
|
// The Twitch User ID corresponding to the guest to assign a slot in the session.
|
|
|
|
|
// This user must already have an invite to this session, and have indicated that they are ready to join.
|
|
|
|
|
GuestID string `url:"guest_id"`
|
|
|
|
|
|
|
|
|
|
// The slot assignment to give to the user. Must be a numeric identifier between “1” and “N” where N is the max number of slots for the session.
|
|
|
|
|
// Max number of slots allowed for the session is reported by Get Channel Guest Star Settings.
|
|
|
|
|
SlotID int `url:"slot_id"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Allows a previously invited user to be assigned a slot within the active Guest Star session, once that guest has indicated they are ready to join.
|
|
|
|
|
//
|
|
|
|
|
// 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) AssignGuestStarSlot(ctx context.Context, params *AssignGuestStarSlot) 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()
|
|
|
|
|
|
2024-03-07 19:41:05 -05:00
|
|
|
|
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
|
|
|
|
if !statusOK {
|
|
|
|
|
return fmt.Errorf("failed to assign guest star slot (%d)", res.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-03 14:09:31 -05:00
|
|
|
|
return nil
|
|
|
|
|
}
|