From d86d7d89145230100980ca13bf44083ae1e954cb Mon Sep 17 00:00:00 2001 From: John Dong Date: Tue, 14 Aug 2007 17:31:59 -0400 Subject: [PATCH] * Refactor candidate map over to its own API call --- app/apis/selectricity_api.rb | 4 ++++ app/models/selectricity_service.rb | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/app/apis/selectricity_api.rb b/app/apis/selectricity_api.rb index 8c0f04f..d478a5a 100644 --- a/app/apis/selectricity_api.rb +++ b/app/apis/selectricity_api.rb @@ -4,6 +4,9 @@ class VoteResultStruct < ActionWebService::Struct member :condorcet_winners, [:int] member :ssd_winners, [:int] member :borda_winners, [:int] + member :errors, [:string] +end +class CandidateMap < ActionWebService::Struct member :candidate_ids, [:int] member :candidate_names, [:string] member :errors, [:string] @@ -11,6 +14,7 @@ end class SelectricityAPI < ActionWebService::API::Base api_method :cast_quickvote, :expects => [:int, :int, [[:int]]], :returns => [:string] api_method :get_quickvote_results, :expects => [:string], :returns => [VoteResultStruct] + api_method :get_quickvote_candidate_map, :expects => [:string], :returns => [CandidateMap] end diff --git a/app/models/selectricity_service.rb b/app/models/selectricity_service.rb index c0adc8a..75d2e3e 100644 --- a/app/models/selectricity_service.rb +++ b/app/models/selectricity_service.rb @@ -20,10 +20,21 @@ class SelectricityService < ActionWebService::Base result.condorcet_winners=qv.condorcet_result.winners result.ssd_winners=qv.ssd_result.winners result.borda_winners=qv.borda_result.winners + result + end + def get_quickvote_candidate_map(shortname) + qv=QuickVote.ident_to_quickvote(shortname) + result=CandidateMap.new + result.errors=[] + unless qv + result.errors << "No quickvote with name #{shortname} found!" + return result + end candidates={} qv.candidates.each {|c| candidates[c.id] = c.name} result.candidate_ids=candidates.keys result.candidate_names=candidates.values result end + end -- 2.39.5