go-twitch/api/eventsub/delete_eventsub_subscriptio...

38 lines
1017 B
Go

package eventsub
import (
"context"
"fmt"
"net/http"
"net/url"
)
// Deletes an EventSub subscription.
//
// If you use webhooks to receive events, the request must specify an app access token.
// The request will fail if you use a user access token.
//
// If you use WebSockets to receive events, the request must specify a user access token.
// The request will fail if you use an app access token. The token may include any scopes.
func (e *EventSub) DeleteEventSubSubscription(ctx context.Context, id string) error {
endpoint := e.baseUrl.ResolveReference(&url.URL{Path: "eventsub/subscriptions", RawQuery: "id=" + id})
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil)
if err != nil {
return err
}
res, err := e.client.Do(req)
if err != nil {
return err
}
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to delete EventSub subscription (%d)", res.StatusCode)
}
return nil
}