# pollster Pollster - the Ruby gem for the Pollster API Download election-related polling data from Pollster. [HuffPost Pollster](https://elections.huffingtonpost.com/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](https://github.com/swagger-api/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](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: ```shell gem build pollster.gemspec ``` Then either install the gem locally: ```shell 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](https://rubygems.org/). 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: ```shell ruby -Ilib script.rb ``` ## Getting Started Please follow the [installation](#installation) procedure and then run the following code: ```ruby # 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` and `charts/{slug}/pollster-chart-poll-questions.tsv`, the return values include a `responses` Hash that maps from `label` (String) to `value` (Float). * Ruby API method names are snake-cased versions of the API endpoints and end with `_get`. For example, the Ruby method to access `questions/{slug}/poll-responses-clean.tsv` is `api.questions_slug_poll_responses_clean_tsv_get(slug)`. ## Author Adam Hooper, adam.hooper@huffingtonpost.com. ## Copyright Copyright © 2016 The Huffington Post. See LICENSE for details.