class Sunlight::Congress::Legislator

Constants

SEARCH_ATTRIBUTES

Public Class Methods

all() click to toggle source
# File lib/sunlight/congress/legislator.rb, line 47
def all
  response = Net::HTTP.get_response(find_uri)
  create_from_response(response)
end
find(query) click to toggle source
# File lib/sunlight/congress/legislator.rb, line 52
def find(query)
  if query.is_a?(String)
    response = Net::HTTP.get_response(find_uri(query: query))
  else
    response = Net::HTTP.get_response(find_uri(query))
  end

  create_from_response(response)
end
find_uri(options = {}) click to toggle source
# File lib/sunlight/congress/legislator.rb, line 70
def find_uri(options = {})
  encode_uri('legislators', options)
end
locate(options) click to toggle source
# File lib/sunlight/congress/legislator.rb, line 32
def locate(options)
  if options.is_a?(String) || options[:address]
    coords = Geocoder.coordinates(options)
    response = Net::HTTP.get_response(locate_uri(latitude: coords[0], longitude: coords[1]))
  else
    response = Net::HTTP.get_response(locate_uri(options))
  end

  create_from_response(response)
end
locate_by_zip(zip) click to toggle source
# File lib/sunlight/congress/legislator.rb, line 24
def locate_by_zip(zip)
  response = Net::HTTP.get_response(locate_uri(zip: zip))

  JSON.parse(response.body)['results'].map do |legislator_attrs|
    self.new(legislator_attrs)
  end
end
locate_uri(options = {}) click to toggle source
# File lib/sunlight/congress/legislator.rb, line 43
def locate_uri(options = {})
  encode_uri('legislators/locate', options)
end
new(options = {}) click to toggle source
# File lib/sunlight/congress/legislator.rb, line 17
def initialize(options = {})
  options.each do |attribute, value|
    instance_variable_set("@#{attribute}", value)
  end
end