73 lines
2.4 KiB
Go
73 lines
2.4 KiB
Go
package schedule
|
||
|
||
import (
|
||
"context"
|
||
"encoding/json"
|
||
"net/http"
|
||
"net/url"
|
||
"time"
|
||
|
||
"github.com/google/go-querystring/query"
|
||
"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 broadcaster’s 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 cursor’s value.
|
||
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
|
||
After *types.Cursor `url:"after,omitempty"`
|
||
}
|
||
|
||
type GetChannelStreamScheduleResponse struct {
|
||
// The broadcaster’s streaming schedule.
|
||
Data ChannelStreamSchedule `json:"data"`
|
||
}
|
||
|
||
// Gets the broadcaster’s 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)
|
||
endpoint := s.baseUrl.ResolveReference(&url.URL{Path: "schedule", 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()
|
||
|
||
var data GetChannelStreamScheduleResponse
|
||
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return &data, nil
|
||
}
|