Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ippon-extreme-startup
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
François SARRADIN
ippon-extreme-startup
Commits
b530e910
Commit
b530e910
authored
7 years ago
by
François Sarradin
Browse files
Options
Downloads
Patches
Plain Diff
Allow GET and POST questions
parent
eacfe8d1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/extreme_startup/question_factory.rb
+52
-28
52 additions, 28 deletions
lib/extreme_startup/question_factory.rb
with
52 additions
and
28 deletions
lib/extreme_startup/question_factory.rb
+
52
−
28
View file @
b530e910
...
...
@@ -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
<
Get
Question
def
initialize
(
player
,
*
numbers
)
if
numbers
.
any?
@n1
,
@n2
,
@n3
=
*
numbers
...
...
@@ -105,7 +129,7 @@ module ExtremeStartup
end
end
class
SelectFromListOfNumbersQuestion
<
Question
class
SelectFromListOfNumbersQuestion
<
Get
Question
def
initialize
(
player
,
*
numbers
)
if
numbers
.
any?
@numbers
=
*
numbers
...
...
@@ -312,7 +336,7 @@ module ExtremeStartup
end
end
class
GeneralKnowledgeQuestion
<
Question
class
GeneralKnowledgeQuestion
<
Get
Question
class
<<
self
def
question_bank
[
...
...
@@ -341,7 +365,7 @@ module ExtremeStartup
end
require
'yaml'
class
AnagramQuestion
<
Question
class
AnagramQuestion
<
Get
Question
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
<
Get
Question
def
as_text
"what is the english scrabble score of
#{
@word
}
"
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment