go-twitch/api/ads/snooze_next_ad.go

54 lines
1.6 KiB
Go
Raw 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 ads
import (
"context"
"encoding/json"
"net/http"
"net/url"
"time"
)
type SnoozeNextAdResponse struct {
// A list that contains information about the channels snoozes and next upcoming ad after successfully snoozing.
Data []SnoozeNextAdData `json:"data"`
}
type SnoozeNextAdData struct {
// The number of snoozes available for the broadcaster.
SnoozeCount int `json:"snooze_count"`
// The UTC timestamp when the broadcaster will gain an additional snooze, in RFC3339 format.
SnoozeRefreshAt time.Time `json:"snooze_refresh_at"`
// The UTC timestamp of the broadcasters next scheduled ad, in RFC3339 format.
NextAdAt time.Time `json:"next_ad_at"`
}
// If available, pushes back the timestamp of the upcoming automatic mid-roll ad by 5 minutes.
// This endpoint duplicates the snooze functionality in the creator dashboards Ads Manager.
//
// Requires a user access token that includes the channel:manage:ads scope.
// The user_id in the user access token must match the broadcaster_id.
func (e *Ads) SnoozeNextAd(ctx context.Context, broadcasterID string) (*SnoozeNextAdResponse, error) {
endpoint := e.baseUrl.ResolveReference(&url.URL{Path: "channels/ads/schedule/snooze", RawQuery: "broadcaster_id=" + broadcasterID})
req, err := http.NewRequest(http.MethodPost, endpoint.String(), nil)
if err != nil {
return nil, err
}
res, err := e.client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
var data SnoozeNextAdResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}