A Go wrapper for the HuffPost Pollster API
Go
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
LICENSE
README.md
charts_test.go
estimates_test.go
polls_test.go
pollster.go

README.md

Pollster

A Go wrapper for the Pollster API which provides access to political opinion polling data and trend estimates from The Huffington Post.

Installation

go get github.com/bycoffe/pollster

Usage

import "github.com/bycoffe/pollster"

will import the package into your project.

The wrapper provides functions for listing and accessing details of charts and polls (for more on the definitions of charts and polls in the context of the Pollster API, see the API documentation.

A map of parameters is required for both the Charts and Polls functions.

Charts returns a list of Chart structs. To list all charts:

charts := pollster.Charts(map[string]string{})

To access the chart for the 2014 Maryland governor's race:

params := map[string]string{
  "state": "MD",
  "topic": "2014-governor",
}
charts := pollster.Charts(params)

Once you have access to a Chart, you can get a list of Pollster's estimates by date:

params := map[string]string{
  "state": "MD",
  "topic": "2014-governor",
}
charts := pollster.Charts(params)
chart := charts[0]
for _, estimate := range chart.EstimatesByDate() {
  fmt.Printf("%s\n", estimate.Date)
  for _, e := range estimate.Estimates {
    fmt.Printf("%s : %f\n", e.Choice, e.Value)
  }
}

Accessing polls works in a similar way. To list all polls (paginated in pages of 10):

polls := pollster.Polls(map[string]string{})

To access the polls for the 2014 Colorado Senate race:

params := map[string]string{
  "state": "CO",
  "topic": "2014-senate",
}
polls := pollster.Polls(params)
for _, poll := range polls {
  fmt.Printf("\n%s: %s\n", poll.Pollster, poll.Method)
  for _, question := range poll.Questions {
    subpop := question.Subpopulations[0]
    fmt.Printf("%s: %s (%d)\n", question.Name, subpop.Name, subpop.Observations)
  }
}