package streams import ( "context" "encoding/json" "fmt" "net/http" "net/url" "github.com/google/go-querystring/query" "go.fifitido.net/twitch/api/types" ) type GetStreamMarkersParams struct { // A user ID. The request returns the markers from this user’s most recent video. // This ID must match the user ID in the access token or the user in the access token must be one of the broadcaster’s editors. // // This parameter and the video_id query parameter are mutually exclusive. UserID *string `url:"user_id,omitempty"` // A video on demand (VOD)/video ID. The request returns the markers from this VOD/video. // The user in the access token must own the video or the user must be one of the broadcaster’s editors. // // This parameter and the user_id query parameter are mutually exclusive. VideoID *string `url:"video_id,omitempty"` // The maximum number of items to return per page in the response. // The minimum page size is 1 item per page and the maximum is 100 items per page. // The default is 20. First *int `url:"first,omitempty"` // The cursor used to get the previous page of results. // The Pagination object in the response contains the cursor’s value. // Read More: https://dev.twitch.tv/docs/api/guide#pagination Before *types.Cursor `url:"before,omitempty"` // The cursor used to get the next page of results. // The Pagination object in the response contains the cursor’s value. // Read More: https://dev.twitch.tv/docs/api/guide#pagination After *types.Cursor `url:"after,omitempty"` } type GetStreamMarkersResponse struct { // The list of markers grouped by the user that created the marks. Data []StreamMarkers `json:"data"` // The information used to page through the list of results. // The object is empty if there are no more pages left to page through. // Read More: https://dev.twitch.tv/docs/api/guide#pagination Pagination types.Pagination `json:"pagination"` } // Gets a list of markers from the user’s most recent stream or from the specified VOD/video. // A marker is an arbitrary point in a live stream that the broadcaster or editor marked, // so they can return to that spot later to create video highlights (see Video Producer, Highlights in the Twitch UX). // // Requires a user access token that includes the user:read:broadcast or channel:manage:broadcast scope. func (s *Streams) GetStreamMarkers(ctx context.Context, params *GetStreamMarkersParams) (*GetStreamMarkersResponse, error) { v, _ := query.Values(params) endpoint := s.baseUrl.ResolveReference(&url.URL{Path: "streams/markers", RawQuery: v.Encode()}) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) if err != nil { return nil, err } res, err := s.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 get stream markers (%d)", res.StatusCode) } var data GetStreamMarkersResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err } return &data, nil }