go-twitch/api/videos/delete_videos.go

47 lines
1.0 KiB
Go

package videos
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
"go.fifitido.net/twitch/api/endpoint"
)
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.
func (i *Videos) DeleteVideos(ctx context.Context, ids []string) (*DeleteVideosResponse, error) {
v := url.Values{"id": ids}
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(i.baseUrl, "videos", v), nil)
if err != nil {
return nil, err
}
res, err := i.client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to delete videos (%d)", res.StatusCode)
}
var data DeleteVideosResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}