Skip to content

Commit

Permalink
adding Official.find_by_government method
Browse files Browse the repository at this point in the history
  • Loading branch information
ajb committed Jun 23, 2012
1 parent 2ebaf50 commit 420e952
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/gov_kit/vote_smart.rb
Expand Up @@ -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})
Expand All @@ -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.
Expand Down

0 comments on commit 420e952

Please sign in to comment.