votesmart

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 6 Imported by: 0

README

go-votesmart

A golang client for the Votesmart API.

Go Reference Actions Status

Installation

$ go get dev.freespoke.com/go-votesmart

Usage

Create an API client instance using your API Key.

client, err := votesmart.New(os.Getenv("VOTESMART_API_KEY"))
if err != nil {
    t.Fatal(err)
}

Make requests by providing a VoteSmart response object, and a *url.Values containing desired URL params:

var resp votesmarttypes.CandidatesGetByLastname
vals := url.Values{}
vals.Add("lastName", "desantis")
vals.Add("electionYear", "2022")

if err := client.Invoke(context.Background(), &vals, &resp); err != nil {
    log.Fatal(err)
}

log.Println(resp)

Refer to the API Documentation for required and optional parameters. Do not set o or key, as the library handles these for you.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Invoke(ctx context.Context, params *url.Values, dst Method) error
}

func New

func New(apiKey string, options ...Option) (Client, error)

type Error

type Error struct {
	ErrorMessage string `json:"errorMessage"`
}

func (Error) Error

func (e Error) Error() string

type Method

type Method interface {
	Method() string
}

type Option

type Option func(clientOptions) clientOptions

func WithBaseURL

func WithBaseURL(v string) Option

func WithClient

func WithClient(v *http.Client) Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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