class Congress::Client

Attributes

key[R]

Public Class Methods

new(key) click to toggle source
# File lib/congress/client.rb, line 11
def initialize(key)
  @key = key
end

Public Instance Methods

bills(options = {}) click to toggle source

Legislation in the House and Senate, back to 2009. Updated daily.

@return [Hashie::Rash] @example

client.bills
# File lib/congress/client.rb, line 60
def bills(options = {})
  get('/bills', options)
end
committees(options = {}) click to toggle source

Current committees, subcommittees, and their membership.

@return [Hashie::Rash] @example

client.committees
# File lib/congress/client.rb, line 51
def committees(options = {})
  get('/committees', options)
end
districts_locate(*args) click to toggle source

Find congressional districts for a latitude/longitude, zip, or address.

@return [Hashie::Rash] @example

client.districts_locate('94107')
client.districts_locate(37.775, -122.418)
client.districts_locate('2169 Mission Street, San Francisco, CA 94110')
# File lib/congress/client.rb, line 42
def districts_locate(*args)
  get('/districts/locate', extract_location(args))
end
floor_updates(options = {}) click to toggle source

To-the-minute updates from the floor of the House and Senate.

@return [Hashie::Rash] @example

client.floor_updates
# File lib/congress/client.rb, line 87
def floor_updates(options = {})
  get('/floor_updates', options)
end
hearings(options = {}) click to toggle source

Committee hearings in client. Updated as hearings are announced.

@return [Hashie::Rash] @example

client.hearings
# File lib/congress/client.rb, line 96
def hearings(options = {})
  get('/hearings', options)
end
legislators(options = {}) click to toggle source

Current legislators’ names, IDs, biography, and social media.

@return [Hashie::Rash] @example

client.legislators
# File lib/congress/client.rb, line 20
def legislators(options = {})
  get('/legislators', options)
end
legislators_locate(*args) click to toggle source

Find representatives and senators for a latitude/longitude, zip, or address.

@return [Hashie::Rash] @example

client.legislators_locate('94107')
client.legislators_locate(37.775, -122.418)
client.legislators_locate('2169 Mission Street, San Francisco, CA 94110')
# File lib/congress/client.rb, line 31
def legislators_locate(*args)
  get('/legislators/locate', extract_location(args))
end
upcoming_bills(options = {}) click to toggle source

Bills scheduled for debate in the future, as announced by party leadership.

@return [Hashie::Rash] @example

client.upcoming_bills
# File lib/congress/client.rb, line 105
def upcoming_bills(options = {})
  get('/upcoming_bills', options)
end
votes(options = {}) click to toggle source

Roll call votes in Congress, back to 2009. Updated within minutes of votes.

@return [Hashie::Rash] @example

client.votes
# File lib/congress/client.rb, line 78
def votes(options = {})
  get('/votes', options)
end

Private Instance Methods

extract_location(args) click to toggle source
# File lib/congress/client.rb, line 111
def extract_location(args) # rubocop:disable AbcSize, MethodLength
  options = args.last.is_a?(::Hash) ? args.pop : {}
  case args.size
  when 1
    case args[0]
    when Integer, /\A[\d]{5}\Z/
      options.merge!(zip: to_zip_code(args[0]))
    when String
      placemark = Geocoder.search(args[0]).first
      options.merge!(latitude: placemark.latitude, longitude: placemark.longitude)
    end
  when 2
    options.merge!(latitude: args[0], longitude: args[1])
  end
  options
end
to_zip_code(number) click to toggle source

Proper zip code from a number, adding leading zeroes if required @param number [Integer] zip code as an integer @return [String]

# File lib/congress/client.rb, line 131
def to_zip_code(number)
  format('%05d', number.to_i)
end