go-twitch/api/videos/delete_videos.go

45 lines
1.1 KiB
Go
Raw Normal View History

2024-03-03 21:41:49 -05:00
package videos
import (
"context"
"encoding/json"
"fmt"
2024-03-03 21:41:49 -05:00
"net/http"
"net/url"
)
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 (v *Videos) DeleteVideos(ctx context.Context, ids []string) (*DeleteVideosResponse, error) {
endpoint := v.baseUrl.ResolveReference(&url.URL{Path: "videos", RawQuery: url.Values{"id": ids}.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil)
if err != nil {
return nil, err
}
res, err := v.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)
}
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
}