From 204f12a4c3e05adf0676873307a6bde00b12e6f2 Mon Sep 17 00:00:00 2001 From: tashian Date: Thu, 26 Aug 2010 16:37:30 -0700 Subject: [PATCH] Raise ResourceNotFound if VoteSmart items are not found --- lib/gov_kit/vote_smart.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/gov_kit/vote_smart.rb b/lib/gov_kit/vote_smart.rb index 265d39d..1a22c4b 100644 --- a/lib/gov_kit/vote_smart.rb +++ b/lib/gov_kit/vote_smart.rb @@ -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) @@ -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 @@ -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