<commit_before># CivicAide

[![Gem Version](https://badge.fury.io/rb/civic_aide.png)](http://badge.fury.io/rb/civic_aide)
[![Build Status](https://travis-ci.org/tylerpearson/civic_aide.png?branch=master)](https://travis-ci.org/tylerpearson/civic_aide)

A (unofficial) Ruby wrapper to interact with the [Google Civic Information API](https://developers.google.com/civic-information/).

Currently the API only provides information for the United States.

## Installation

Add this line to your application's Gemfile:

    gem 'civic_aide'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install civic_aide

## Usage

### Setup

The Google Civic Information API requires an API key, so before you start grab a [server API key](https://developers.google.com/civic-information/docs/using_api) from the [Google Cloud Console](https://cloud.google.com/console#/project).

The current default API limits for the Google Civic Information API are 1/request/second/user and 25,000 requests/day.

### Response

All responses are wrapped in a [hashie](https://github.com/intridea/hashie) object that can be accessed in a number of ways. All methods have been rubyify'ed **but** those matching [Open Civic Data identifiers](https://github.com/opencivicdata/ocd-division-ids) (e.g. `ocd-division/country:us/state:nc/county:durham`).

Additionally, to avoid clashing with the [Array#zip Ruby method](http://apidock.com/ruby/Array/zip), any `zip` address fields in the API response have been renamed to `zip_code`.

### Configuration

```ruby
api_key = `<KEY>`
client = CivicAide::Client.new(api_key)
```

Alternatively, the API key can be set with global configuration and the resources can be accessed directly.

```ruby
CivicAide.api_key = "<KEY>"
CivicAide.elections.all
```

To [receive data that is only from official state sources](https://developers.google.com/civic-information/docs/us_v1/elections/voterInfoQuery), set `CivicPage.official_sources` to `true`. By default this is set to `false`.

```ruby
CivicAide.official_sources = true
# or
client.official_sources = true
```

## Resources

### [Elections](https://developers.google.com/civic-information/docs/us_v1/elections)

#### All elections

To fetch a list of all available elections and their ids.<commit_msg>Clarify API key is a string in README<commit_after># CivicAide

[![Gem Version](https://badge.fury.io/rb/civic_aide.png)](http://badge.fury.io/rb/civic_aide)
[![Build Status](https://travis-ci.org/tylerpearson/civic_aide.png?branch=master)](https://travis-ci.org/tylerpearson/civic_aide)

A (unofficial) Ruby wrapper to interact with the [Google Civic Information API](https://developers.google.com/civic-information/).

Currently the API only provides information for the United States.

## Installation

Add this line to your application's Gemfile:

    gem 'civic_aide'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install civic_aide

## Usage

### Setup

The Google Civic Information API requires an API key, so before you start grab a [server API key](https://developers.google.com/civic-information/docs/using_api) from the [Google Cloud Console](https://cloud.google.com/console#/project).

The current default API limits for the Google Civic Information API are 1/request/second/user and 25,000 requests/day.

### Response

All responses are wrapped in a [hashie](https://github.com/intridea/hashie) object that can be accessed in a number of ways. All methods have been rubyify'ed **but** those matching [Open Civic Data identifiers](https://github.com/opencivicdata/ocd-division-ids) (e.g. `ocd-division/country:us/state:nc/county:durham`).

Additionally, to avoid clashing with the [Array#zip Ruby method](http://apidock.com/ruby/Array/zip), any `zip` address fields in the API response have been renamed to `zip_code`.

### Configuration

```ruby
api_key = "<KEY>"
client = CivicAide::Client.new(api_key)
```

Alternatively, the API key can be set with global configuration and the resources can be accessed directly.

```ruby
CivicAide.api_key = "<KEY>"
CivicAide.elections.all
```

To [receive data that is only from official state sources](https://developers.google.com/civic-information/docs/us_v1/elections/voterInfoQuery), set `CivicPage.official_sources` to `true`. By default this is set to `false`.

```ruby
CivicAide.official_sources = true
# or
client.official_sources = true
```

## Resources

### [Elections](https://developers.google.com/civic-information/docs/us_v1/elections)

#### All elections

To fetch a list of all available elections and their ids.
{'fraction_non_alphanumeric': 0.12102742707879843, 'fraction_numerical': 0.0034828036569438396, 'mean_word_length': 4.9366925064599485, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 20, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7671842', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1436, 'n_words': 434}