]> projects.mako.cc - selectricity/blob - app/models/selectricity_service.rb
Import latest subversion RubyVote.
[selectricity] / app / models / selectricity_service.rb
1 require 'action_controller/integration'
2
3 class SelectricityService < ActionWebService::Base
4   web_service_api SelectricityAPI
5   def cast_quickvote(election_id, vote_id, vote_list)
6     #Obviously not implemented
7   end
8   def get_quickvote_results(shortname)
9     #TODO: Validate shortname
10     qv=QuickVote.ident_to_quickvote(shortname)
11     result=VoteResultStruct.new
12     result.errors=[]
13     unless qv
14       result.errors << "No quickvote with name #{shortname} found!"
15       return result
16     end
17     qv.results
18     result.plurality_winners=qv.plurality_result.winners
19     result.approval_winners=qv.approval_result.winners
20     result.condorcet_winners=qv.condorcet_result.winners
21     result.ssd_winners=qv.ssd_result.winners
22     result.borda_winners=qv.borda_result.winners
23     result
24   end
25   def get_quickvote_candidate_map(shortname)
26     qv=QuickVote.ident_to_quickvote(shortname)
27     result=CandidateMap.new
28     result.errors=[]
29     unless qv
30       result.errors << "No quickvote with name #{shortname} found!"
31       return result
32     end
33     candidates={}
34     qv.candidates.each {|c| candidates[c.id] = c.name}
35     result.candidate_ids=candidates.keys
36     result.candidate_names=candidates.values
37     result
38   end
39     
40 end

Benjamin Mako Hill || Want to submit a patch?