From: John Dong Date: Tue, 14 Aug 2007 19:39:18 +0000 (-0400) Subject: Introduce XMLRPC API files. It is not currently functional, but it doesn't break... X-Git-Url: https://projects.mako.cc/source/selectricity/commitdiff_plain/80fe90c787f595b0554297d2fe5eb810e3ca652a Introduce XMLRPC API files. It is not currently functional, but it doesn't break anything outside of itself. --- diff --git a/app/apis/selectricity_api.rb b/app/apis/selectricity_api.rb new file mode 100644 index 0000000..e94eaaa --- /dev/null +++ b/app/apis/selectricity_api.rb @@ -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 index 0000000..e1f9f98 --- /dev/null +++ b/app/controllers/selectricity_service_controller.rb @@ -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 index 0000000..d383dcd --- /dev/null +++ b/app/models/selectricity_service.rb @@ -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