* Refactor candidate map over to its own API call
authorJohn Dong <jdong@mit.edu>
Tue, 14 Aug 2007 21:31:59 +0000 (17:31 -0400)
committerJohn Dong <jdong@mit.edu>
Tue, 14 Aug 2007 21:31:59 +0000 (17:31 -0400)
app/apis/selectricity_api.rb
app/models/selectricity_service.rb

index 8c0f04f64c11b6e61c060926ae977f0424f3d1cc..d478a5a8b6f9b26f5548d47cbf0683fb23ca85ac 100644 (file)
@@ -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
 
 
index c0adc8a7b438242dda11225d6099a20d176497f7..75d2e3e775a72e5207ea2ac7146c3c8cbc9f7c70 100644 (file)
@@ -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

Benjamin Mako Hill || Want to submit a patch?