52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
|
package gueststar
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"encoding/json"
|
||
|
"net/http"
|
||
|
"net/url"
|
||
|
|
||
|
"github.com/google/go-querystring/query"
|
||
|
)
|
||
|
|
||
|
type EndGuestStarSession 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"`
|
||
|
|
||
|
// ID for the session to end on behalf of the broadcaster.
|
||
|
SessionID string `url:"session_id"`
|
||
|
}
|
||
|
|
||
|
type EndGuestStarSessionResponse struct {
|
||
|
// Summary of the session details when the session was ended.
|
||
|
Data []Session `json:"data"`
|
||
|
}
|
||
|
|
||
|
// Programmatically ends a Guest Star session on behalf of the broadcaster.
|
||
|
// Performs the same action as if the host clicked the “End Call” button in the Guest Star UI.
|
||
|
//
|
||
|
// Query parameter broadcaster_id must match the user_id in the User-Access token
|
||
|
// Requires OAuth Scope: channel:manage:guest_star
|
||
|
func (g *GuestStar) EndGuestStarSession(ctx context.Context, params *EndGuestStarSession) (*EndGuestStarSessionResponse, error) {
|
||
|
v, _ := query.Values(params)
|
||
|
endpoint := g.baseUrl.ResolveReference(&url.URL{Path: "guest_star/session", RawQuery: v.Encode()})
|
||
|
|
||
|
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, 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()
|
||
|
|
||
|
var data EndGuestStarSessionResponse
|
||
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return &data, nil
|
||
|
}
|