api

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResultsVisibilityAlways        = "always"
	ResultsVisibilityAfterDeadline = "after_deadline"
	ResultsVisibilityAfterVote     = "after_vote"
	ResultsVisibilityHidden        = "hidden" // NOT "never" -- doc bug
)

Results visibility constants (actual API values).

View Source
const (
	PollTypeMultipleChoice = "multiple_choice"
	PollTypeMeeting        = "meeting"
	PollTypeRanking        = "ranking" // NOT "ranked_choice" -- doc bug
)

Poll type constants (actual API values).

View Source
const (
	OptionTypeText      = "text"
	OptionTypeDate      = "date"
	OptionTypeTimeRange = "time_range"
)

Option type constants.

View Source
const (
	VoteTypeDefault         = "default"
	VoteTypeParticipantGrid = "participant_grid"
)

Vote type constants.

View Source
const (
	DupcheckIP      = "ip"
	DupcheckSession = "session"
	DupcheckNone    = "none"
)

Duplicate check constants.

Variables

This section is empty.

Functions

func NewAPIError

func NewAPIError(statusCode int, body []byte) error

NewAPIError parses a JSON error response body and returns the appropriate typed error.

func ParsePollID

func ParsePollID(input string) string

ParsePollID extracts a poll ID from a URL or returns the input as-is if it's a raw ID.

Types

type APIError

type APIError struct {
	StatusCode int
	Message    string
	Details    string
}

APIError represents a generic API error response.

func (*APIError) Error

func (e *APIError) Error() string

type AuthError

type AuthError struct {
	APIError
}

AuthError represents a 401/403 authentication error.

func (*AuthError) Error

func (e *AuthError) Error() string

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the StrawPoll API client.

func NewClient

func NewClient(apiKey string) *Client

NewClient creates a Client with retry transport, rate limiter, and auth.

func (*Client) Close

func (c *Client) Close()

Close releases resources held by the client.

func (*Client) CreatePoll

func (c *Client) CreatePoll(ctx context.Context, req *CreatePollRequest) (*Poll, error)

CreatePoll creates a new poll via POST /polls. Sets type to "multiple_choice" if not already set.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string) error

Delete performs a DELETE request.

func (*Client) DeletePoll

func (c *Client) DeletePoll(ctx context.Context, id string) error

DeletePoll deletes a poll via DELETE /polls/{id}.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, out any) error

Get performs a GET request.

func (*Client) GetPoll

func (c *Client) GetPoll(ctx context.Context, id string) (*Poll, error)

GetPoll retrieves a poll by ID via GET /polls/{id}.

func (*Client) GetPollResults

func (c *Client) GetPollResults(ctx context.Context, id string) (*PollResults, error)

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) Post

func (c *Client) Post(ctx context.Context, path string, body, out any) error

Post performs a POST request.

func (*Client) Put

func (c *Client) Put(ctx context.Context, path string, body, out any) error

Put performs a PUT request.

func (*Client) ResetPollResults

func (c *Client) ResetPollResults(ctx context.Context, id string) error

ResetPollResults resets poll results via DELETE /polls/{id}/results.

func (*Client) UpdatePoll

func (c *Client) UpdatePoll(ctx context.Context, id string, req *UpdatePollRequest) (*Poll, error)

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

type Pagination struct {
	Page  int `json:"page"`
	Limit int `json:"limit"`
	Total int `json:"total"`
}

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

type RateLimitError struct {
	APIError
	RetryAfter time.Duration
}

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.

func (*RateLimiter) Close

func (r *RateLimiter) Close()

Close stops the refill goroutine.

func (*RateLimiter) Wait

func (r *RateLimiter) Wait(ctx context.Context) error

Wait blocks until a token is available or ctx is cancelled.

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.

func (*RetryTransport) RoundTrip

func (t *RetryTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes the request with retry logic.

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

type ValidationError struct {
	Field   string
	Message string
}

ValidationError represents a field validation error.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL