2024-03-03 14:09:31 -05:00
|
|
|
|
package gueststar
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
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 GetGuestStarSessionParams 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"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type GetGuestStarSessionResponse struct {
|
|
|
|
|
// Summary of the session details
|
|
|
|
|
Data []Session `json:"data"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Gets information about an ongoing Guest Star session for a particular channel.
|
|
|
|
|
//
|
|
|
|
|
// Requires OAuth Scope: channel:read:guest_star, channel:manage:guest_star, moderator:read:guest_star or moderator:manage:guest_star
|
|
|
|
|
// Guests must be either invited or assigned a slot within the session
|
|
|
|
|
func (g *GuestStar) GetGuestStarSession(ctx context.Context, params *GetGuestStarSessionParams) (*GetGuestStarSessionResponse, error) {
|
|
|
|
|
v, _ := query.Values(params)
|
|
|
|
|
|
2024-03-07 20:52:42 -05:00
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(g.baseUrl, "guest_star/session", v), nil)
|
2024-03-03 14:09:31 -05:00
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res, err := g.client.Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
defer res.Body.Close()
|
|
|
|
|
|
2024-03-07 19:41:05 -05:00
|
|
|
|
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
|
|
|
|
if !statusOK {
|
|
|
|
|
return nil, fmt.Errorf("failed to get guest star session (%d)", res.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-03 14:09:31 -05:00
|
|
|
|
var data GetGuestStarSessionResponse
|
|
|
|
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &data, nil
|
|
|
|
|
}
|