2024-02-28 13:50:07 -05:00
|
|
|
package conduit
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-03-07 19:41:05 -05:00
|
|
|
"fmt"
|
2024-02-28 13:50:07 -05:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Deletes a specified conduit.
|
|
|
|
// Note that it may take some time for Eventsub subscriptions on a deleted conduit to show as disabled when calling Get Eventsub Subscriptions.
|
|
|
|
//
|
|
|
|
// Requires an app access token.
|
|
|
|
func (c *Conduit) DeleteConduit(ctx context.Context, id string) error {
|
|
|
|
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "eventsub/conduits", RawQuery: "id=" + id})
|
|
|
|
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := c.client.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer res.Body.Close()
|
|
|
|
|
2024-03-07 19:41:05 -05:00
|
|
|
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
|
|
|
if !statusOK {
|
|
|
|
return fmt.Errorf("failed to delete conduit (%d)", res.StatusCode)
|
|
|
|
}
|
|
|
|
|
2024-02-28 13:50:07 -05:00
|
|
|
return nil
|
|
|
|
}
|