2024-02-27 23:03:40 -05:00
|
|
|
package eventsub
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-03-07 19:41:05 -05:00
|
|
|
"fmt"
|
2024-02-27 23:03:40 -05:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
2024-03-07 20:52:42 -05:00
|
|
|
|
|
|
|
"go.fifitido.net/twitch/api/endpoint"
|
2024-02-27 23:03:40 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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 {
|
2024-03-07 20:52:42 -05:00
|
|
|
v := url.Values{"id": {id}}
|
2024-02-27 23:03:40 -05:00
|
|
|
|
2024-03-07 20:52:42 -05:00
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(e.baseUrl, "eventsub/subscriptions", v), nil)
|
2024-02-27 23:03:40 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-03-07 19:41:05 -05:00
|
|
|
res, err := e.client.Do(req)
|
|
|
|
if err != nil {
|
2024-02-27 23:03:40 -05:00
|
|
|
return err
|
|
|
|
}
|
2024-03-07 19:41:05 -05:00
|
|
|
defer res.Body.Close()
|
|
|
|
|
|
|
|
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
|
|
|
if !statusOK {
|
|
|
|
return fmt.Errorf("failed to delete EventSub subscription (%d)", res.StatusCode)
|
|
|
|
}
|
2024-02-27 23:03:40 -05:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|