go-twitch/api/raids/cancel_a_raid.go

42 lines
1016 B
Go
Raw Normal View History

2024-03-03 16:00:12 -05:00
package raids
import (
"context"
"fmt"
2024-03-03 16:00:12 -05:00
"net/http"
"net/url"
"go.fifitido.net/twitch/api/endpoint"
2024-03-03 16:00:12 -05:00
)
// 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 (r *Raids) CancelARaid(ctx context.Context, broadcasterID string) error {
v := url.Values{"broadcaster_id": {broadcasterID}}
2024-03-03 16:00:12 -05:00
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(r.baseUrl, "raids", v), nil)
2024-03-03 16:00:12 -05:00
if err != nil {
return err
}
res, err := r.client.Do(req)
2024-03-03 16:00:12 -05:00
if err != nil {
return err
}
defer res.Body.Close()
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
}