govtrack

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package govtrack is the library behind the govtrack command line: the HTTP client, request shaping, and typed data models for the GovTrack.us API v2 (https://www.govtrack.us/api/v2).

The API requires no key. The Client paces requests, sets a real User-Agent, and retries transient failures (429 and 5xx).

Index

Constants

View Source
const BaseURL = "https://" + Host + "/api/v2"

BaseURL is the root every API request is built from.

View Source
const Host = "www.govtrack.us"

Host is the API hostname.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bill

type Bill struct {
	ID             int    `json:"id" kit:"id"`
	Congress       int    `json:"congress"`
	Type           string `json:"type"`
	Number         int    `json:"number"`
	Title          string `json:"title"`
	IntroducedDate string `json:"introducedDate,omitempty"`
	Status         string `json:"status,omitempty"`
	URL            string `json:"url"`
}

Bill holds flattened bill metadata from GovTrack.us.

type Client

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

Client talks to GovTrack.us API over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) GetBill

func (c *Client) GetBill(ctx context.Context, id int) (*Bill, error)

GetBill returns a single bill by numeric ID.

func (*Client) ListBills

func (c *Client) ListBills(ctx context.Context, congress, limit int) ([]Bill, error)

ListBills returns bills for a congress, limited to limit results.

func (*Client) ListPeople

func (c *Client) ListPeople(ctx context.Context, role string, limit int) ([]Person, error)

ListPeople returns congress members filtered by role type. role: "senator", "representative", or "" for all.

func (*Client) ListVotes

func (c *Client) ListVotes(ctx context.Context, congress, limit int) ([]Vote, error)

ListVotes returns votes for a congress, limited to limit results.

func (*Client) SearchBills

func (c *Client) SearchBills(ctx context.Context, query string, limit int) ([]Bill, error)

SearchBills searches bills by title keyword.

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
}

Config holds all tunable parameters for the Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults for GovTrack.us.

type Domain

type Domain struct{}

Domain is the govtrack driver for the kit framework.

func (Domain) Classify

func (Domain) Classify(input string) (string, string, error)

Classify turns any accepted input into (type, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, hostnames, and binary identity.

func (Domain) Locate

func (Domain) Locate(t, id string) (string, error)

Locate returns the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and all operations onto app.

type Person

type Person struct {
	ID        int    `json:"id" kit:"id"`
	FirstName string `json:"firstName"`
	LastName  string `json:"lastName"`
	Party     string `json:"party,omitempty"`
	State     string `json:"state,omitempty"`
	Role      string `json:"role,omitempty"`
	URL       string `json:"url"`
}

Person holds a congress member's metadata from GovTrack.us.

type Vote

type Vote struct {
	ID       int    `json:"id" kit:"id"`
	Congress int    `json:"congress"`
	Question string `json:"question"`
	Result   string `json:"result"`
	Created  string `json:"created,omitempty"`
	Chamber  string `json:"chamber,omitempty"`
	URL      string `json:"url"`
}

Vote holds flattened vote metadata from GovTrack.us.

Jump to

Keyboard shortcuts

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