]> projects.mako.cc - selectricity-live/commitdiff
Introduce XMLRPC API files. It is not currently functional, but it doesn't break...
authorJohn Dong <jdong@mit.edu>
Tue, 14 Aug 2007 19:39:18 +0000 (15:39 -0400)
committerJohn Dong <jdong@mit.edu>
Tue, 14 Aug 2007 19:39:18 +0000 (15:39 -0400)
app/apis/selectricity_api.rb [new file with mode: 0644]
app/controllers/selectricity_service_controller.rb [new file with mode: 0644]
app/models/selectricity_service.rb [new file with mode: 0644]

diff --git a/app/apis/selectricity_api.rb b/app/apis/selectricity_api.rb
new file mode 100644 (file)
index 0000000..e94eaaa
--- /dev/null
@@ -0,0 +1,14 @@
+class VoteResultStruct < ActionWebService::Struct
+  member :plurality_winners, :string
+  member :approval_winners, :string
+  member :condorcet_winners, :string
+  member :ssd_winners, :string
+  member :borda_winners, :string
+  member :errors, :string
+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]
+end
+
+
diff --git a/app/controllers/selectricity_service_controller.rb b/app/controllers/selectricity_service_controller.rb
new file mode 100644 (file)
index 0000000..e1f9f98
--- /dev/null
@@ -0,0 +1,4 @@
+class SelectricityServiceController < ApplicationController
+  web_service_dispatching_mode :delegated
+  web_service :vote, SelectricityService.new
+end
diff --git a/app/models/selectricity_service.rb b/app/models/selectricity_service.rb
new file mode 100644 (file)
index 0000000..d383dcd
--- /dev/null
@@ -0,0 +1,21 @@
+require 'action_controller/integration'
+
+class SelectricityService < ActionWebService::Base
+  web_service_api SelectricityAPI
+  def cast_quickvote(election_id, vote_id, vote_list)
+    #Obviously not implemented
+  end
+  def get_quickvote_results(shortname)
+    #TODO: Validate shortname
+    session=ActionController::Integration::Session.new
+    debugger
+    controller=session.get "quickvote/#{shortname}/results"
+    result=VoteResultStruct.new
+    result.plurality_winners=session.controller.plurality_result.winners.inspect
+    result.approval_winners=session.controller.approval_result.winners.inspect
+    result.condorcet_winners=session.controller.condorcet_result.winners.inspect
+    result.ssd_winners=session.controller.ssd_result.winners.inspect
+    result.borda_winners=session.controller.borda_result.winners.inspect
+    result
+  end
+end

Benjamin Mako Hill || Want to submit a patch?