Skip to content
Snippets Groups Projects
Commit b530e910 authored by François Sarradin's avatar François Sarradin
Browse files

Allow GET and POST questions

parent eacfe8d1
No related branches found
No related tags found
No related merge requests found
......@@ -10,26 +10,6 @@ module ExtremeStartup
end
end
def ask(player)
url = player.url + '?q=' + URI.escape(self.to_s)
puts "GET: " + url
begin
response = get(url)
if (response.success?) then
self.answer = response.to_s
else
@problem = "error_response"
end
rescue => exception
puts exception
@problem = "no_server_response"
end
end
def get(url)
HTTParty.get(url)
end
def result
if @answer && self.answered_correctly?(answer)
"correct"
......@@ -47,11 +27,11 @@ module ExtremeStartup
else 20
end
end
def was_answered_correctly
result == "correct"
end
def was_answered_wrongly
result == "wrong"
end
......@@ -85,7 +65,51 @@ module ExtremeStartup
end
end
class BinaryMathsQuestion < Question
class GetQuestion < Question
def ask(player)
url = player.url + '?q=' + URI.escape(self.to_s)
puts "GET: " + url
begin
response = get(url)
if (response.success?) then
self.answer = response.to_s
else
@problem = "error_response"
end
rescue => exception
puts exception
@problem = "no_server_response"
end
end
def get(url)
HTTParty.get(url)
end
end
class PostQuestion < Question
def ask(player)
url = player.url + '?q=' + URI.escape(self.to_s)
puts "Post: " + url
begin
response = post(url, {data: self.get_data})
if (response.success?) then
self.answer = response.to_s
else
@problem = "error_response"
end
rescue => exception
puts exception
@problem = "no_server_response"
end
end
def post(url, data)
HTTParty.post(url, data)
end
end
class BinaryMathsQuestion < GetQuestion
def initialize(player, *numbers)
if numbers.any?
@n1, @n2 = *numbers
......@@ -95,7 +119,7 @@ module ExtremeStartup
end
end
class TernaryMathsQuestion < Question
class TernaryMathsQuestion < GetQuestion
def initialize(player, *numbers)
if numbers.any?
@n1, @n2, @n3 = *numbers
......@@ -105,7 +129,7 @@ module ExtremeStartup
end
end
class SelectFromListOfNumbersQuestion < Question
class SelectFromListOfNumbersQuestion < GetQuestion
def initialize(player, *numbers)
if numbers.any?
@numbers = *numbers
......@@ -312,7 +336,7 @@ module ExtremeStartup
end
end
class GeneralKnowledgeQuestion < Question
class GeneralKnowledgeQuestion < GetQuestion
class << self
def question_bank
[
......@@ -341,7 +365,7 @@ module ExtremeStartup
end
require 'yaml'
class AnagramQuestion < Question
class AnagramQuestion < GetQuestion
def as_text
possible_words = [@anagram["correct"]] + @anagram["incorrect"]
%Q{which of the following is an anagram of "#{@anagram["anagram"]}": #{possible_words.shuffle.join(", ")}}
......@@ -362,7 +386,7 @@ module ExtremeStartup
end
end
class ScrabbleQuestion < Question
class ScrabbleQuestion < GetQuestion
def as_text
"what is the english scrabble score of #{@word}"
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment