2024-03-03 15:27:37 -05:00
|
|
|
|
package polls
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2024-03-07 19:41:05 -05:00
|
|
|
|
"fmt"
|
2024-03-03 15:27:37 -05:00
|
|
|
|
"net/http"
|
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
|
|
"github.com/google/go-querystring/query"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type EndPollParams struct {
|
|
|
|
|
|
|
|
|
|
// The ID of the broadcaster that’s 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)
|
|
|
|
|
endpoint := p.baseUrl.ResolveReference(&url.URL{Path: "polls", RawQuery: v.Encode()})
|
|
|
|
|
|
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res, err := p.client.Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
defer res.Body.Close()
|
|
|
|
|
|
2024-03-07 19:41:05 -05:00
|
|
|
|
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
|
|
|
|
if !statusOK {
|
|
|
|
|
return fmt.Errorf("failed to end poll (%d)", res.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-03 15:27:37 -05:00
|
|
|
|
return nil
|
|
|
|
|
}
|