go-twitch/api/schedule/update_channel_stream_sched...

59 lines
2.0 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package schedule
import (
"context"
"fmt"
"net/http"
"time"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
)
type UpdateChannelStreamScheduleParams struct {
// The ID of the broadcaster whose schedule settings you want to update.
// The ID must match the user ID in the user access token.
BroadcasterId string `url:"broadcaster_id"`
// A Boolean value that indicates whether the broadcaster has scheduled a vacation.
// Set to true to enable Vacation Mode and add vacation dates, or false to cancel a previously scheduled vacation.
IsVacationEnabled *bool `url:"is_vacation_enabled,omitempty"`
// The UTC date and time of when the broadcasters vacation starts.
// Specify the date and time in RFC3339 format (for example, 2021-05-16T00:00:00Z).
VacationStartTime *time.Time `url:"vacation_start_time,omitempty"`
// The UTC date and time of when the broadcasters vacation ends.
// Specify the date and time in RFC3339 format (for example, 2021-05-30T23:59:59Z).
VacationEndTime *time.Time `url:"vacation_end_time,omitempty"`
// The time zone that the broadcaster broadcasts from.
// Specify the time zone using IANA time zone database format (for example, America/New_York).
Timezone *time.Location `url:"timezone,omitempty"`
}
// Updates the broadcasters schedule settings, such as scheduling a vacation.
//
// Requires a user access token that includes the channel:manage:schedule scope.
func (s *Schedule) UpdateChannelStreamSchedule(ctx context.Context, params *UpdateChannelStreamScheduleParams) error {
v, _ := query.Values(params)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(s.baseUrl, "schedule/settings", v), nil)
if err != nil {
return err
}
res, err := s.client.Do(req)
if err != nil {
return err
}
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to update channel stream schedule (%d)", res.StatusCode)
}
return nil
}