60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
package gueststar
|
||
|
||
import (
|
||
"context"
|
||
"encoding/json"
|
||
"fmt"
|
||
"net/http"
|
||
|
||
"github.com/google/go-querystring/query"
|
||
"go.fifitido.net/twitch/api/endpoint"
|
||
)
|
||
|
||
type GetGuestStarInvitesParams 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 broadcaster’s chat room.
|
||
// This ID must match the user ID in the user access token.
|
||
ModeratorID string `url:"moderator_id"`
|
||
|
||
// The session ID to query for invite status.
|
||
SessionID string `url:"session_id"`
|
||
}
|
||
|
||
type GetGuestStarInvitesResponse struct {
|
||
// A list of invite objects describing the invited user as well as their ready status.
|
||
Data []Invite `json:"data"`
|
||
}
|
||
|
||
// Provides the caller with a list of pending invites to a Guest Star session, including the invitee’s ready status while joining the waiting room.
|
||
//
|
||
// Query parameter broadcaster_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) GetGuestStarInvites(ctx context.Context, params *GetGuestStarInvitesParams) (*GetGuestStarInvitesResponse, error) {
|
||
v, _ := query.Values(params)
|
||
|
||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(g.baseUrl, "guest_star/invites", v), nil)
|
||
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 guest star invites (%d)", res.StatusCode)
|
||
}
|
||
|
||
var data GetGuestStarInvitesResponse
|
||
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return &data, nil
|
||
}
|