go-twitch/api/polls/end_poll.go

52 lines
1.3 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 polls
import (
"context"
"fmt"
"net/http"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
)
type EndPollParams struct {
// The ID of the broadcaster thats running the poll. This ID must match the user ID in the user access token.
BroadcasterID string `url:"broadcaster_id"`
// The ID of the poll to update.
ID string `url:"id"`
// The status to set the poll to. Possible case-sensitive values are:
//
// TERMINATED — Ends the poll before the poll is scheduled to end. The poll remains publicly visible.
//
// ARCHIVED — Ends the poll before the poll is scheduled to end, and then archives it so it's no longer publicly visible.
Status Status `url:"status"`
}
// Ends an active poll. You have the option to end it or end it and archive it.
//
// Requires a user access token that includes the channel:manage:polls scope.
func (p *Polls) EndPoll(ctx context.Context, params *EndPollParams) error {
v, _ := query.Values(params)
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(p.baseUrl, "polls", v), nil)
if err != nil {
return err
}
res, err := p.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 end poll (%d)", res.StatusCode)
}
return nil
}