Module: GetYourRep::Google

Extended by:
GetYourRep
Defined in:
lib/get_your_rep/google.rb

Overview

Retrieve your elected representatives from the Google Civic Information API, parse it from JSON, and assemble it into a usable Ruby Hash-like object called a Representative. Representatives are then wrapped in an Array-like object called a Delegation.

You must configure your own Google API key as an environment variable using the constant name ‘GOOGLE_API_KEY’ in order for this gem to work.

Constant Summary collapse

API_KEY =

The Google API key is used to access data from the Google Civic Information API. You must obtain your own and configure it as an environment variable on your system.

ENV['GOOGLE_API_KEY']

Constants included from GetYourRep

VERSION

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from GetYourRep

address_is_a_zip?, convert_int_address_to_string, convert_zip_to_address, get_coordinates, handle_reps_not_found_error, parse_address, trim_street_number

Class Attribute Details

.addressObject

Holds the parsed address for the HTTP request.



14
15
16
# File 'lib/get_your_rep/google.rb', line 14

def address
  @address
end

.delegationObject

Holds the Delegation object which will be returned by the all_reps class method.



16
17
18
# File 'lib/get_your_rep/google.rb', line 16

def delegation
  @delegation
end

.responseObject

Holds the raw JSON data response from the API.



18
19
20
# File 'lib/get_your_rep/google.rb', line 18

def response
  @response
end

Class Method Details

.all_reps(address, congress_only: nil) ⇒ Object

Makes the call to the Google API and delivers the response after parsing. Returns a GetYourRep::Delegation object, holding a collection of GetYourRep::Representatives



26
27
28
29
30
# File 'lib/get_your_rep/google.rb', line 26

def all_reps(address, congress_only: nil)
  init(address)
  ask_google_api(congress_only: congress_only)
  deliver_response
end