Permalink
Browse files

adding Official.find_by_government method

  • Loading branch information...
1 parent 2ebaf50 commit 420e952378e41b8da70b65abae6d631f9514cd97 @ajb ajb committed Jun 23, 2012
Showing with 12 additions and 3 deletions.
  1. +12 −3 lib/gov_kit/vote_smart.rb
View
@@ -22,6 +22,18 @@ def self.find_cities(stateId)
end
end
+ class Official < VoteSmartResource
+ def self.find_by_government(stateOrLocalId)
+ if stateOrLocalId.match(/[A-Za-z]/) # We're looking for state officals
+ response = get("/Officials.getStatewide", :query => {"stateId" => stateId})
+ else # We're looking for local officials
+ response = get("/Local.getOfficials", :query => {"localId" => stateId})
+ end
+
+ parse(response['candidateList']['candidate'])
+ end
+ end
+
class Address < VoteSmartResource
def self.find(candidate_id)
response = get("/Address.getOffice", :query => {"candidateId" => candidate_id})
@@ -37,14 +49,11 @@ def self.find(candidate_id)
end
class Bio < VoteSmartResource
- def self.find(candidate_id)
def self.find(candidate_id, include_office = false)
response = get("/CandidateBio.getBio", :query => {"candidateId" => candidate_id})
# Sometimes VoteSmart returns nil if no one is found!
raise(ResourceNotFound, 'Could not find bio for candidate') if response.blank? || response['error']
-
- parse(response['bio']['candidate'])
# Previous versions ommitted "office" data from response.
# include_office is optional so to not break backwards compatibility.

0 comments on commit 420e952

Please sign in to comment.