Documentation
¶
Index ¶
- Constants
- func NewAPIError(statusCode int, body []byte) error
- func ParsePollID(input string) string
- type APIError
- type AuthError
- type Client
- func (c *Client) Close()
- func (c *Client) CreatePoll(ctx context.Context, req *CreatePollRequest) (*Poll, error)
- func (c *Client) Delete(ctx context.Context, path string) error
- func (c *Client) DeletePoll(ctx context.Context, id string) error
- func (c *Client) Get(ctx context.Context, path string, out any) error
- func (c *Client) GetPoll(ctx context.Context, id string) (*Poll, error)
- func (c *Client) GetPollResults(ctx context.Context, id string) (*PollResults, error)
- func (c *Client) ListMyPolls(ctx context.Context, pollType string, page, limit int) (*PollListResponse, error)
- func (c *Client) Post(ctx context.Context, path string, body, out any) error
- func (c *Client) Put(ctx context.Context, path string, body, out any) error
- func (c *Client) ResetPollResults(ctx context.Context, id string) error
- func (c *Client) UpdatePoll(ctx context.Context, id string, req *UpdatePollRequest) (*Poll, error)
- type CreatePollRequest
- type Pagination
- type Poll
- type PollConfig
- type PollListResponse
- type PollMeta
- type PollOption
- type PollParticipant
- type PollResults
- type RateLimitError
- type RateLimiter
- type RetryTransport
- type UpdatePollRequest
- type ValidationError
Constants ¶
const ( ResultsVisibilityAlways = "always" ResultsVisibilityAfterDeadline = "after_deadline" ResultsVisibilityAfterVote = "after_vote" ResultsVisibilityHidden = "hidden" // NOT "never" -- doc bug )
Results visibility constants (actual API values).
const ( PollTypeMultipleChoice = "multiple_choice" PollTypeMeeting = "meeting" PollTypeRanking = "ranking" // NOT "ranked_choice" -- doc bug )
Poll type constants (actual API values).
const ( OptionTypeText = "text" OptionTypeDate = "date" OptionTypeTimeRange = "time_range" )
Option type constants.
const ( VoteTypeDefault = "default" VoteTypeParticipantGrid = "participant_grid" )
Vote type constants.
const ( DupcheckIP = "ip" DupcheckSession = "session" DupcheckNone = "none" )
Duplicate check constants.
Variables ¶
This section is empty.
Functions ¶
func NewAPIError ¶
NewAPIError parses a JSON error response body and returns the appropriate typed error.
func ParsePollID ¶
ParsePollID extracts a poll ID from a URL or returns the input as-is if it's a raw ID.
Types ¶
type AuthError ¶
type AuthError struct {
APIError
}
AuthError represents a 401/403 authentication error.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the StrawPoll API client.
func (*Client) CreatePoll ¶
CreatePoll creates a new poll via POST /polls. Sets type to "multiple_choice" if not already set.
func (*Client) DeletePoll ¶
DeletePoll deletes a poll via DELETE /polls/{id}.
func (*Client) GetPollResults ¶
GetPollResults retrieves poll results via GET /polls/{id}/results.
func (*Client) ListMyPolls ¶
func (c *Client) ListMyPolls(ctx context.Context, pollType string, page, limit int) (*PollListResponse, error)
ListMyPolls lists the user's polls via GET /users/@me/polls. pollType must be "created" or "participated".
func (*Client) ResetPollResults ¶
ResetPollResults resets poll results via DELETE /polls/{id}/results.
func (*Client) UpdatePoll ¶
UpdatePoll updates a poll via PUT /polls/{id}.
type CreatePollRequest ¶
type CreatePollRequest struct {
Title string `json:"title"`
Type string `json:"type"`
PollOptions []*PollOption `json:"poll_options"`
PollConfig *PollConfig `json:"poll_config,omitempty"`
PollMeta *PollMeta `json:"poll_meta,omitempty"`
}
CreatePollRequest is the request body for creating a poll.
type Pagination ¶
Pagination holds page-based pagination metadata.
type Poll ¶
type Poll struct {
ID string `json:"id"`
Title string `json:"title"`
Type string `json:"type"`
PollOptions []*PollOption `json:"poll_options"`
PollConfig *PollConfig `json:"poll_config"`
PollMeta *PollMeta `json:"poll_meta"`
CreatedAt int64 `json:"created_at"`
UpdatedAt *int64 `json:"updated_at"`
ResetAt *int64 `json:"reset_at"`
Version string `json:"version"`
}
Poll represents a StrawPoll poll.
type PollConfig ¶
type PollConfig struct {
IsPrivate *bool `json:"is_private,omitempty"`
VoteType string `json:"vote_type,omitempty"`
AllowComments *bool `json:"allow_comments,omitempty"`
AllowIndeterminate *bool `json:"allow_indeterminate,omitempty"`
AllowOtherOption *bool `json:"allow_other_option,omitempty"`
AllowVpnUsers *bool `json:"allow_vpn_users,omitempty"`
DeadlineAt *int64 `json:"deadline_at,omitempty"`
DuplicationChecking string `json:"duplication_checking,omitempty"`
EditVotePermissions string `json:"edit_vote_permissions,omitempty"`
ForceAppearance string `json:"force_appearance,omitempty"`
HideParticipants *bool `json:"hide_participants,omitempty"`
IsMultipleChoice *bool `json:"is_multiple_choice,omitempty"`
MaxChoices *int `json:"max_choices,omitempty"`
MinChoices *int `json:"min_choices,omitempty"`
MultipleChoiceMax *int `json:"multiple_choice_max,omitempty"`
MultipleChoiceMin *int `json:"multiple_choice_min,omitempty"`
NumberOfWinners *int `json:"number_of_winners,omitempty"`
RandomizeOptions *bool `json:"randomize_options,omitempty"`
RequireVoterNames *bool `json:"require_voter_names,omitempty"`
ResultsVisibility string `json:"results_visibility,omitempty"`
}
PollConfig holds all poll configuration fields.
type PollListResponse ¶
type PollListResponse struct {
Data []Poll `json:"data"`
Pagination Pagination `json:"pagination"`
}
PollListResponse represents a paginated list of polls.
type PollMeta ¶
type PollMeta struct {
Description string `json:"description,omitempty"`
Location string `json:"location,omitempty"`
Timezone string `json:"timezone,omitempty"` // IANA timezone (e.g. "Europe/Berlin")
VoteCount int `json:"vote_count,omitempty"`
ParticipantCount int `json:"participant_count,omitempty"` // read-only
ViewCount int `json:"view_count,omitempty"` // read-only
}
PollMeta holds poll metadata.
type PollOption ¶
type PollOption struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Value string `json:"value"`
Position int `json:"position,omitempty"`
VoteCount int `json:"vote_count,omitempty"`
MaxVotes int `json:"max_votes,omitempty"`
Description string `json:"description,omitempty"`
IsWriteIn bool `json:"is_write_in,omitempty"`
Date string `json:"date,omitempty"` // YYYY-MM-DD for type="date" (meeting all-day)
StartTime *int64 `json:"start_time,omitempty"` // Unix timestamp for type="time_range"
EndTime *int64 `json:"end_time,omitempty"` // Unix timestamp for type="time_range"
}
PollOption represents a single option in a poll.
type PollParticipant ¶
type PollParticipant struct {
ID string `json:"id"`
Name string `json:"name"`
CountryCode string `json:"country_code"`
IsEditAllowed bool `json:"is_edit_allowed"`
PollVotes []*int `json:"poll_votes"`
CreatedAt int64 `json:"created_at"`
}
PollParticipant represents a participant in a poll.
type PollResults ¶
type PollResults struct {
ID string `json:"id"`
Version string `json:"version"`
VoteCount int `json:"voteCount"` // camelCase per OpenAPI spec
ParticipantCount int `json:"participantCount"` // camelCase per OpenAPI spec
PollOptions []*PollOption `json:"poll_options"`
PollParticipants []*PollParticipant `json:"poll_participants"`
}
PollResults represents poll results from the API.
type RateLimitError ¶
RateLimitError represents a 429 rate limit error.
func (*RateLimitError) Error ¶
func (e *RateLimitError) Error() string
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter implements a simple token bucket rate limiter.
func NewRateLimiter ¶
func NewRateLimiter(rate int, interval time.Duration) *RateLimiter
NewRateLimiter creates a token bucket that allows rate requests per interval. Tokens are pre-filled and refilled at a steady rate.
type RetryTransport ¶
type RetryTransport struct {
Base http.RoundTripper
MaxRetries int
}
RetryTransport wraps an http.RoundTripper with retry logic and exponential backoff.
func NewRetryTransport ¶
func NewRetryTransport(base http.RoundTripper) *RetryTransport
NewRetryTransport creates a RetryTransport with default 3 retries.
type UpdatePollRequest ¶
type UpdatePollRequest struct {
Title string `json:"title,omitempty"`
PollOptions []*PollOption `json:"poll_options,omitempty"`
PollConfig *PollConfig `json:"poll_config,omitempty"`
PollMeta *PollMeta `json:"poll_meta,omitempty"`
}
UpdatePollRequest is the request body for updating a poll.
type ValidationError ¶
ValidationError represents a field validation error.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string