2024-03-03 21:41:49 -05:00
|
|
|
package videos
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
2024-03-07 19:41:05 -05:00
|
|
|
"fmt"
|
2024-03-03 21:41:49 -05:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
2024-03-07 20:52:42 -05:00
|
|
|
|
|
|
|
"go.fifitido.net/twitch/api/endpoint"
|
2024-03-03 21:41:49 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type DeleteVideosResponse struct {
|
|
|
|
// The list of IDs of the videos that were deleted.
|
|
|
|
Data []string `json:"data"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deletes one or more videos. You may delete past broadcasts, highlights, or uploads.
|
|
|
|
//
|
|
|
|
// Requires a user access token that includes the channel:manage:videos scope.
|
2024-03-07 20:52:42 -05:00
|
|
|
func (i *Videos) DeleteVideos(ctx context.Context, ids []string) (*DeleteVideosResponse, error) {
|
|
|
|
v := url.Values{"id": ids}
|
2024-03-03 21:41:49 -05:00
|
|
|
|
2024-03-07 20:52:42 -05:00
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(i.baseUrl, "videos", v), nil)
|
2024-03-03 21:41:49 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-03-07 20:52:42 -05:00
|
|
|
res, err := i.client.Do(req)
|
2024-03-03 21:41:49 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer res.Body.Close()
|
|
|
|
|
2024-03-07 19:41:05 -05:00
|
|
|
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
|
|
|
if !statusOK {
|
|
|
|
return nil, fmt.Errorf("failed to delete videos (%d)", res.StatusCode)
|
|
|
|
}
|
|
|
|
|
2024-03-03 21:41:49 -05:00
|
|
|
var data DeleteVideosResponse
|
|
|
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &data, nil
|
|
|
|
}
|