2024-03-03 16:00:12 -05:00
|
|
|
package raids
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-03-07 19:41:05 -05:00
|
|
|
"fmt"
|
2024-03-03 16:00:12 -05:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Cancel a pending raid.
|
|
|
|
//
|
|
|
|
// You can cancel a raid at any point up until the broadcaster clicks Raid Now in the Twitch UX or the 90-second countdown expires.
|
|
|
|
//
|
|
|
|
// Rate Limit: The limit is 10 requests within a 10-minute window.
|
|
|
|
//
|
|
|
|
// Requires a user access token that includes the channel:manage:raids scope.
|
|
|
|
//
|
|
|
|
// The broadcaster ID must match the user ID in the user access token.
|
|
|
|
func (c *Raids) CancelARaid(ctx context.Context, broadcasterID string) error {
|
|
|
|
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "raids", RawQuery: url.Values{"broadcaster_id": {broadcasterID}}.Encode()})
|
|
|
|
|
|
|
|
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 cancel a raid (%d)", res.StatusCode)
|
|
|
|
}
|
|
|
|
|
2024-03-03 16:00:12 -05:00
|
|
|
return nil
|
|
|
|
}
|