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"
|
|
|
|
|
|
|
|
|
|
"github.com/google/go-querystring/query"
|
2024-03-07 20:52:42 -05:00
|
|
|
|
"go.fifitido.net/twitch/api/endpoint"
|
2024-03-03 14:09:31 -05:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type SendGuestStarInviteParams struct {
|
|
|
|
|
// The ID of the broadcaster you want to end a Guest Star session for. Provided broadcaster_id must match the user_id in the auth token.
|
|
|
|
|
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 session ID for the invite to be sent on behalf of the broadcaster.
|
|
|
|
|
SessionID string `url:"session_id"`
|
|
|
|
|
|
|
|
|
|
// Twitch User ID for the guest to invite to the Guest Star session.
|
|
|
|
|
GuestID string `url:"guest_id"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sends an invite to a specified guest on behalf of the broadcaster for a Guest Star session in progress.
|
|
|
|
|
//
|
|
|
|
|
// 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) SendGuestStarInvite(ctx context.Context, params *SendGuestStarInviteParams) error {
|
|
|
|
|
v, _ := query.Values(params)
|
|
|
|
|
|
2024-03-07 20:52:42 -05:00
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(g.baseUrl, "guest_star/invite", v), nil)
|
2024-03-03 14:09:31 -05:00
|
|
|
|
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 send guest star invite (%d)", res.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-03 14:09:31 -05:00
|
|
|
|
return nil
|
|
|
|
|
}
|