go-twitch/api/schedule/get_channel_stream_schedule.go

78 lines
2.5 KiB
Go
Raw Permalink Normal View History

2024-03-03 16:30:10 -05:00
package schedule
import (
"context"
"encoding/json"
"fmt"
2024-03-03 16:30:10 -05:00
"net/http"
"time"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
2024-03-03 16:30:10 -05:00
"go.fifitido.net/twitch/api/types"
)
type GetChannelStreamScheduleParams struct {
// The ID of the broadcaster that owns the streaming schedule you want to get.
BroadcasterId string `url:"broadcaster_id"`
// The ID of the scheduled segment to return.
// To specify more than one segment, include the ID of each segment you want to get. For example, id=1234&id=5678.
// You may specify a maximum of 100 IDs.
IDs []string `url:"id,omitempty"`
// The UTC date and time that identifies when in the broadcasters schedule to start returning segments.
// If not specified, the request returns segments starting after the current UTC date and time.
// Specify the date and time in RFC3339 format (for example, 2022-09-01T00:00:00Z).
StartTime *time.Time `url:"start_time,omitempty"`
// Not supported.
UTCOffset *string `url:"utc_offset,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 25 items per page.
// The default is 20.
First int `url:"first,omitempty"`
// The cursor used to get the next page of results.
// The Pagination object in the response contains the cursors value.
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
After *types.Cursor `url:"after,omitempty"`
}
type GetChannelStreamScheduleResponse struct {
// The broadcasters streaming schedule.
Data ChannelStreamSchedule `json:"data"`
}
// Gets the broadcasters streaming schedule. You can get the entire schedule or specific segments of the schedule.
// Learn More: https://help.twitch.tv/s/article/channel-page-setup#Schedule
//
// Requires an app access token or user access token.
func (s *Schedule) GetChannelStreamSchedule(ctx context.Context, params *GetChannelStreamScheduleParams) (*GetChannelStreamScheduleResponse, error) {
v, _ := query.Values(params)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(s.baseUrl, "schedule", v), nil)
2024-03-03 16:30:10 -05:00
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 channel stream schedule (%d)", res.StatusCode)
}
2024-03-03 16:30:10 -05:00
var data GetChannelStreamScheduleResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}