pollster
Pollster - the Ruby gem for the Pollster API
Download election-related polling data from Pollster.
HuffPost Pollster is a website that tracks public opinion. Pollster's editors enter polling data for the \"Questions\" they care about -- questions the public answers in \"Polls\".
The Pollster website is organized into \"Charts\" and Pollster-calculated trendlines (descriptions of how the public felt each day, based on the polls and public algorithms). Each Chart is based on a single Question. The Pollster API provides every point plotted on all the \"Charts\" on the Pollster website. Furthermore, it provides the raw polling data that went into those charts: every response to every Question, at whichever level of detail the developer requests.
This SDK was originally generated by the Swagger Codegen project:
- API version: 2.0.0
- Package version: 2.0.0
- Build package: class io.swagger.codegen.languages.RubyClientCodegen
For more information, please visit https://groups.google.com/forum/#!forum/pollster-users
Installation
In short: add gem 'pollster', '~> 2.0.0'
to your Gemfile.
Full installation options:
Build a gem
To build the Ruby code into a gem:
gem build pollster.gemspec
Then either install the gem locally:
gem install ./pollster-2.0.0.gem
(for development, run gem install --dev ./pollster-1.0.0.gem
to install the development dependencies)
or publish the gem to a gem hosting service, e.g. RubyGems.
Finally add this to the Gemfile:
gem 'pollster', '~> 2.0.0'
Install from Git
If the Ruby gem is hosted at a git repository: https://github.com/YOUR_GIT_USERNAME/YOUR_GIT_REPO, then add the following in the Gemfile:
gem 'pollster', :git => 'https://github.com/YOUR_GIT_USERNAME/YOUR_GIT_REPO.git'
Include the Ruby code directly
Include the Ruby code directly using -I
as follows:
ruby -Ilib script.rb
Getting Started
Please follow the installation procedure and then run the following code:
# Load the gem
require 'pollster'
api = Pollster::Api.new
opts = {
cursor: nil, # Special string to index into the Array
tags: "2016-president", # Comma-separated list of tag slugs
election_date: Date.parse("2013-10-20") # Date of an election
}
begin
result = api.charts_get(opts)
p result
rescue Pollster::ApiError => e
puts "Exception when calling Api->charts_get: #{e}"
end
API documentation
Perhaps the best documentation is example.rb
: it shows how to use all API
endpoints and how to paginate.
See https://elections.huffingtonpost.com/pollster/api/v2/help for more details.
See https://app.swaggerhub.com/api/huffpostdata/pollster-api/2.0.0 for full API documentation. The Ruby-specific warts:
- For the TSV endpoints
questions/{slug}/poll-responses-clean.tsv
andcharts/{slug}/pollster-chart-poll-questions.tsv
, the return values include aresponses
Hash that maps fromlabel
(String) tovalue
(Float). - Ruby API method names are snake-cased versions of the API endpoints and end
with
_get
. For example, the Ruby method to accessquestions/{slug}/poll-responses-clean.tsv
isapi.questions_slug_poll_responses_clean_tsv_get(slug)
.
Author
Adam Hooper, [email protected].
Copyright
Copyright © 2016 The Huffington Post. See LICENSE for details.