-class ElectionStruct < ActionWebService::Struct
+class QuickVoteStruct < ActionWebService::Struct
member :name, :string
member :description, :string
member :candidate_ids, [:int]
member :candidate_names, [:string]
member :id, :int
end
-class VoteInfo < ActionWebService::Struct
+class QuickVoterInfo < ActionWebService::Struct
member :voter_id, :int
member :voter_session_id, :string
member :voter_ipaddress, :string
member :vote, [:int]
end
-class VoteResultStruct < ActionWebService::Struct
+class QuickVoteResultStruct < ActionWebService::Struct
member :plurality_winners, [:int]
member :approval_winners, [:int]
member :condorcet_winners, [:int]
member :ssd_winners, [:int]
member :borda_winners, [:int]
end
-class CandidateMap < ActionWebService::Struct
+class QuickVoteCandidateMap < ActionWebService::Struct
member :candidate_ids, [:int]
member :candidate_names, [:string]
end
class SelectricityAPI < ActionWebService::API::Base
api_method :cast_quickvote, :expects => [:string, :int, [[:int]]], :returns => [:string]
- api_method :get_quickvote_results, :expects => [:string], :returns => [VoteResultStruct]
- api_method :get_quickvote_candidate_map, :expects => [:string], :returns => [CandidateMap]
+ api_method :get_quickvote_results, :expects => [:string], :returns => [QuickVoteResultStruct]
+ api_method :get_quickvote_candidate_map, :expects => [:string], :returns => [QuickVoteCandidateMap]
api_method :quickvote_candidate_ids_to_names, :expects => [:string,[:int]], :returns => [[:string]]
- api_method :get_quickvote_votes, :expects => [:string], :returns => [ [VoteInfo] ]
- api_method :list_quickvotes, :expects => [], :returns => [[ElectionStruct]]
- api_method :get_quickvote, :expects => [:string], :returns => [ElectionStruct]
- api_method :create_quickvote, :expects => [ElectionStruct], :returns => [:string]
+ api_method :get_quickvote_votes, :expects => [:string], :returns => [ [QuickVoterInfo] ]
+ api_method :list_quickvotes, :expects => [], :returns => [[QuickVoteStruct]]
+ api_method :get_quickvote, :expects => [:string], :returns => [QuickVoteStruct]
+ api_method :create_quickvote, :expects => [QuickVoteStruct], :returns => [:string]
end
-
-
def get_quickvote_results(shortname)
#TODO: Validate shortname
qv=QuickVote.ident_to_quickvote(shortname)
- result=VoteResultStruct.new
+ result=QuickVoteResultStruct.new
unless qv
raise ArgumentError.new("No quickvote with name #{shortname} found!")
end
end
def get_quickvote_candidate_map(shortname)
qv=QuickVote.ident_to_quickvote(shortname)
- result=CandidateMap.new
+ result=QuickVoteCandidateMap.new
unless qv
raise ArgumentError.new("No quickvote with name #{shortname} found!")
end
end
qv.votes.collect do |vote|
- VoteInfo.new(:voter_id => vote.voter.id,
+ QuickVoterInfo.new(:voter_id => vote.voter.id,
:voter_ipaddress => vote.voter.ipaddress,
:vote_time => vote.time.to_i,
:vote => vote.votes,
raise ArgumentError.new("Cannot find QuickVote named #{shortname}")
end
- ElectionStruct.new(
+ QuickVoteStruct.new(
:id => election.id,
:name => election.name,
:description => election.description,
end
def test_create_quickvote
- election = ElectionStruct.new(
+ election = QuickVoteStruct.new(
{ :name => "TestVote",
:description => "Test Vote",
:candidate_names => ["Apple", "Orange", "Banana", "Pineapple"] })
def test_create_mass_quickvote
10.times do |t|
- assert_create_quickvote_succeeds ElectionStruct.new({
+ assert_create_quickvote_succeeds QuickVoteStruct.new({
:name => "test#{t}",
:description => "Test Vote",
:candidate_names => ["Apple", "Orange", "Banana", "Pineapple"]})
end
def test_create_quickvote_bad_name
- assert_create_quickvote_fails ElectionStruct.new({
+ assert_create_quickvote_fails QuickVoteStruct.new({
:name => "invalid space",
:description => "Test Vote",
:candidate_names => ["Apple", "Orange", "Banana", "Pineapple"]})
end
def test_create_quickvote_nil
- assert_create_quickvote_fails ElectionStruct.new()
+ assert_create_quickvote_fails QuickVoteStruct.new()
end
def test_create_quickvote_name_nil
- assert_create_quickvote_fails ElectionStruct.new({
+ assert_create_quickvote_fails QuickVoteStruct.new({
:name => "",
:description => "Test Vote",
:candidate_names => ["Apple", "Orange", "Banana", "Pineapple"]})
end
def test_create_quickvote_description_nil
- assert_create_quickvote_fails ElectionStruct.new({
+ assert_create_quickvote_fails QuickVoteStruct.new({
:name => "foobar",
:description => nil,
:candidate_names => ["Apple", "Orange", "Banana", "Pineapple"]})
end
def test_create_quickvote_description_whitespace
- assert_create_quickvote_fails ElectionStruct.new({
+ assert_create_quickvote_fails QuickVoteStruct.new({
:name => "foobar",
:description => " ",
:candidate_names => ["Apple", "Orange", "Banana", "Pineapple"]})
- assert_create_quickvote_fails ElectionStruct.new({
+ assert_create_quickvote_fails QuickVoteStruct.new({
:name => "foobar",
:description => "\t\t",
:candidate_names => ["Apple", "Orange", "Banana", "Pineapple"]})
end
def test_create_quickvote_candidates_nil
- assert_create_quickvote_fails ElectionStruct.new({
+ assert_create_quickvote_fails QuickVoteStruct.new({
:name => "foobar",
:description => "valid",
:candidate_names => nil })
end
def test_create_quickvote_insufficient_candidates
- assert_create_quickvote_fails ElectionStruct.new({
+ assert_create_quickvote_fails QuickVoteStruct.new({
:name => "foobar",
:description => "valid",
:candidate_names => ["Apple"] })
end
def test_create_quickvote_candidates_whitespace
- assert_create_quickvote_fails ElectionStruct.new({
+ assert_create_quickvote_fails QuickVoteStruct.new({
:name => "foobar",
:description => "valid",
:candidate_names => [" ", " ", " ", " "]})
end
def test_create_quickvote_dupe_candidates
- assert_create_quickvote_fails ElectionStruct.new({
+ assert_create_quickvote_fails QuickVoteStruct.new({
:name => "foobar",
:description => "valid",
:candidate_names => ["Apple", "Apple", "Apple", "Apple"]})
# We don't want this to happen. Dupe canidates should fail
# regardless of how many are left.
- assert_create_quickvote_fails ElectionStruct.new({
+ assert_create_quickvote_fails QuickVoteStruct.new({
:name => "foobar",
:description => "valid",
:candidate_names => ["Apple", "Apple", "Orange",
end
def test_create_quickvote_candidates_nil_mixed
- assert_create_quickvote_fails ElectionStruct.new({
+ assert_create_quickvote_fails QuickVoteStruct.new({
:name => "foobar",
:description => "valid",
:candidate_names => ["Apple", nil ]})
def test_create_quickvote_description_xmlescape
# Will an embedded XML element bork the table?
- assert_create_quickvote_succeeds ElectionStruct.new({
+ assert_create_quickvote_succeeds QuickVoteStruct.new({
:name => "foobar",
:description => "test </string>",
:candidate_names => ["Apple", "Orange", "Banana", "Pineapple"]})
end
def test_create_quickvote_unprintable_description
- assert_create_quickvote_succeeds ElectionStruct.new ({
+ assert_create_quickvote_succeeds QuickVoteStruct.new ({
:name => "foobar",
:description => "test \x01\x02\x03\x04\x05\x06\x07\x08",
:candidate_names => ["Apple", "Orange", "Banana", "Pineapple"]})
end
def test_quickvote_proper_results
- assert_create_quickvote_succeeds ElectionStruct.new({
+ assert_create_quickvote_succeeds QuickVoteStruct.new({
:name => "favdev",
:description => "Who is your favorite developer?",
:candidate_names => ["mako", "jdong", "justin"]})