Skip to content

Commit

Permalink
Raise ResourceNotFound if VoteSmart items are not found
Browse files Browse the repository at this point in the history
  • Loading branch information
tashian committed Aug 26, 2010
1 parent 9d54187 commit 204f12a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/gov_kit/vote_smart.rb
Expand Up @@ -36,9 +36,10 @@ def self.list(state_id)
class SIG < VoteSmartResource
def self.list(category_id, state_id)
response = get("/Rating.getSigList", :query => {"categoryId" => category_id, "stateId" => state_id})

raise(ResourceNotFound, response['error']['errorMessage']) if response['error'] && response['error']['errorMessage'] == 'No SIGs fit this criteria.'

instantiate(response['sigs']['sig'])
rescue
pp response
end

def self.find(sig_id)
Expand All @@ -50,9 +51,10 @@ def self.find(sig_id)
class Rating < VoteSmartResource
def self.find(candidate_id, sig_id)
response = get("/Rating.getCandidateRating", :query => {"candidateId" => candidate_id, "sigId" => sig_id})

raise(ResourceNotFound, response['error']['errorMessage']) if response['error'] && response['error']['errorMessage'] == 'No Ratings fit this criteria.'

instantiate(response['candidateRating']['rating'])
rescue
pp response
end
end

Expand All @@ -64,10 +66,9 @@ def self.find(bill_id)

def self.find_by_year_and_state(year, state_abbrev)
response = get('/Votes.getBillsByYearState', :query => {'year' => year, 'stateId' => state_abbrev})
raise(ResourceNotFound, response['error']['errorMessage']) if response['error'] && response['error']['errorMessage'] == 'No bills for this state and year.'

instantiate_record(response['bills'])
rescue
return nil if response.parsed_response && response.parsed_response['error']['errorMessage'] == 'No bills for this state and year.'
raise
end


Expand Down

0 comments on commit 204f12a

Please sign in to comment.