go-twitch/api/gueststar/get_gueststar_session.go

58 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package gueststar
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
"github.com/google/go-querystring/query"
)
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 broadcasters 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)
endpoint := g.baseUrl.ResolveReference(&url.URL{Path: "guest_star/session", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), 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 session (%d)", res.StatusCode)
}
var data GetGuestStarSessionResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}