Class: Daywalker::Legislator
- Includes:
- HappyMapper
- Defined in:
- lib/daywalker/legislator.rb
Overview
Represents a legislator, either a Senator or Representative.
They have the following attributes:
-
district_number
-
title (ether :senator or :representative)
-
eventful_id (on eventful.com)
-
in_office (true or false)
-
state (two-letter abbreviation)
-
votesmart_id (on www.votesmart.org)
-
party (:democrat, :republican, or :independent)
-
crp_id (on opensecrets.org)
-
website_url
-
fax_number
-
govtrack_id (on www.govtrack.us)
-
first_name
-
middle_name
-
last_name
-
congress_office (address in Washington, DC)
-
bioguide_id (on bioguide.congress.gov)
-
webform_url
-
youtube_url
-
nickname
-
phone
-
fec_id (on fec.gov)
-
gender (:male or :female)
-
name_suffix
-
twitter_id (on twitter.com)
-
congresspedia_url
Constant Summary collapse
- VALID_ATTRIBUTES =
[:district_number, :title, :eventful_id, :in_office, :state, :votesmart_id, :official_rss_url, :party, :email, :crp_id, :website_url, :fax_number, :govtrack_id, :first_name, :middle_name, :last_name, :congress_office, :bioguide_id, :webform_url, :youtube_url, :nickname, :phone, :fec_id, :gender, :name_suffix, :twitter_id, :sunlight_old_id, :congresspedia_url]
Class Method Summary collapse
-
.find(sym, conditions) ⇒ Object
Find one or many legislators, based on a set of conditions.
-
.find_all_by_zip(zip) ⇒ Object
Find all legislators in a particular zip code.
-
.method_missing(method_id, *args, &block) ⇒ Object
:nodoc:.
-
.respond_to?(method_id) ⇒ Boolean
:nodoc:.
Class Method Details
.find(sym, conditions) ⇒ Object
Find one or many legislators, based on a set of conditions. See VALID_ATTRIBUTES for possible attributes you can search for.
If you want one legislators, and you expect there is exactly one legislator, use :one. An error will be raised if there are more than one result.
Daywalker::Legislator.find(:one, :state => 'NY', :district => 4)
Otherwise, use :all.
Daywalker::Legislator.find(:all, :state => 'NY', :title => :senator)
Additionally, dynamic finders based on these attributes are available:
Daywalker::Legislator.find_by_state_and_district('NY', 4)
Daywalker::Legislator.find_all_by_state_and_senator('NY', :senator)
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/daywalker/legislator.rb', line 92 def self.find(sym, conditions) url = case sym when :one then '/legislators.get.xml' when :all then '/legislators.getList.xml' else raise ArgumentError, "invalid argument #{sym.inspect}, only :one and :all are allowed" end conditions = TypeConverter.normalize_conditions(conditions) query = conditions.merge(:apikey => Daywalker.api_key) response = get(url, :query => query) case sym when :one then handle_response(response).first when :all then handle_response(response) end end |
.find_all_by_zip(zip) ⇒ Object
Find all legislators in a particular zip code
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/daywalker/legislator.rb', line 66 def self.find_all_by_zip(zip) raise ArgumentError, 'missing required parameter zip' if zip.nil? query = { :zip => zip, :apikey => Daywalker.api_key } response = get('/legislators.allForZip.xml', :query => query) handle_response(response) end |
.method_missing(method_id, *args, &block) ⇒ Object
:nodoc:
109 110 111 112 113 114 115 116 117 |
# File 'lib/daywalker/legislator.rb', line 109 def self.method_missing(method_id, *args, &block) # :nodoc: match = DynamicFinderMatch.new(method_id) if match.match? create_finder_method(method_id, match.finder, match.attribute_names) send(method_id, *args, &block) else super end end |
.respond_to?(method_id) ⇒ Boolean
:nodoc:
120 121 122 123 124 125 126 127 |
# File 'lib/daywalker/legislator.rb', line 120 def self.respond_to?(method_id) # :nodoc: match = DynamicFinderMatch.new(method_id) if match.match? true else super end end |