{"name":"FEC Results","tagline":"Federal election results data from the Federal Election Commission","body":"# FecResults\r\n\r\nFecResults is a Ruby library that provides access to federal election results as published by the Federal Election Commission. Although it is primarily a campaign finance disclosure agency, the FEC also compiles election results on its site. This library provides ways to access summary and contest-specific information about elections for the U.S. House of Representatives, the U.S. Senate and President from 2000-2012. This data represents regularly-scheduled primary and general elections, plus special elections held on the date of general elections. It does not include special elections held outside the regularly scheduled election calendar. The results are race-wide only; they do not contain any geographic breakdowns such as county.\r\n\r\nWhat's not here is results below the \"race-wide\" level; there are no county or precinct-level results, only those for the state and House district.\r\n\r\nPlease be aware that there can be typos in some of the FEC results files, mainly in the FEC candidate IDs.\r\n\r\n## Installation\r\n\r\nAdd this line to your application's Gemfile:\r\n\r\n gem 'fec_results'\r\n\r\nAnd then execute:\r\n\r\n $ bundle\r\n\r\nOr install it yourself as:\r\n\r\n $ gem install fec_results\r\n\r\n## Getting Started\r\n\r\nFecResults can be used to retrieve both summary and contest-specific election results. Every instance of an FecResults class must include a year passed into the `new` method.\r\n\r\n#### Summary Results\r\n\r\nThe Summary class represents state, race and chamber totals for 2000-2012, plus a few other methods that are not strictly results themselves. Summary methods return Ruby objects built with OpenStruct. To get started, create an instance of the `Summary` class using a year hash:\r\n\r\n```ruby\r\ns = FecResults::Summary.new(:year => 2012)\r\n```\r\n\r\n`Summary` objects have a handful of methods, from the general election votes by race type (President, Senate, House) to party vote totals by chamber. To retrieve general election votes:\r\n\r\n```ruby\r\ngeneral_votes = s.general_election_votes\r\n=> [, ,...]\r\ngeneral_votes.\r\nalabama = general_votes.first\r\n=> \r\nalabama.house_votes\r\n=> 1933630\r\n```\r\n\r\nAnother way to isolate a single state is to pass in an optional hash with the state abbreviation to the method called. The state filter is the only filter for `Summary` objects.\r\n\r\n```ruby\r\nalabama_votes = s.general_election_votes({state: 'AL'})\r\n=> [, ]\r\n```\r\n\r\nThe `Summary` object methods work for all years except `house_party_gains`, which only applies to the 2010 cycle. In addition to summary election results, each cycle also has a `party_labels` method that lists political parties and the abbreviations used by the FEC for that cycle's results data.\r\n\r\n#### Presidential Results\r\n\r\nIn presidential years (2000, 2004, 2008 and 2012), FecResults offers totals of the popular and electoral vote, along with election results for both the primary and general elections. Retrieving presidential data works the same way, by passing a year:\r\n\r\n```ruby\r\np = FecResults::President.new(:year => 2000)\r\np.primary_party_summary\r\n=> [, #, ..]\r\n```\r\n\r\nPresidential methods include popular vote totals, state totals for electoral and popular votes, primary totals by party and election results for the primary and general elections.\r\n\r\n#### Congressional Results\r\n\r\nFecResults offers House and Senate results for 2000-2012, which are built using the `Result` object (as are presidential results). For congressional results, the file can take awhile to load, so try not to call `results` more than once, but rather save the output to a variable:\r\n\r\n```ruby\r\nc = FecResults::Congress.new(:year => 2012)\r\nresults = c.results\r\nresults.first\r\n=> \r\n```\r\nNot all years have the same data available - for example, general election winners are not always marked. In addition, some states permit candidates to run as the nominee of multiple parties; these candidates usually have a `Result` instance with a combined parties total and separate instances for each party.\r\n\r\n### JSON API\r\n\r\nUsing the [FecResultsGenerator library](https://github.com/openelections/fec_results_generator), there is a static file JSON API of data retrieved by FecResults. It covers the years 2000-2012 and consists of three sections: Congress, President and Summary, matching the classes found in the gem. You can browse the API by changing the year, class name and method name. Here is a listing of the endpoints, using 2012 data:\r\n\r\n##### Summary\r\n\r\n* [Party Labels](http://openelections.github.io/fec_results/api/2012/summary/party_labels.json)\r\n* [Chamber Votes by Party](http://openelections.github.io/fec_results/api/2012/summary/chamber_votes_by_party.json)\r\n* [Congressional Votes by Election](http://openelections.github.io/fec_results/api/2012/summary/congressional_votes_by_election.json)\r\n* [General Election Votes by Party](http://openelections.github.io/fec_results/api/2012/summary/general_election_votes_by_party.json)\r\n\r\n##### President\r\n\r\n* [Popular Vote Summary](http://openelections.github.io/fec_results/api/2012/president/popular_vote_summary.json)\r\n* [State Electoral and Popular Vote Summary](http://openelections.github.io/fec_results/api/2012/president/state_electoral_and_popular_vote_summary.json)\r\n* [General Election Results](http://openelections.github.io/fec_results/api/2012/president/general_election_results.json)\r\n* [Primary Election Results](http://openelections.github.io/fec_results/api/2012/president/primary_election_results.json)\r\n\r\n##### Congress\r\n\r\n* [Results](http://openelections.github.io/fec_results/api/2012/congress/results.json)","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."}