Skip to content

Documentation API

Maëlys Bühler edited this page Mar 14, 2024 · 47 revisions

Implémenté

GET /category/iq
Description Get all categories with the IQ of current User
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Failure cases User is not authentificated - 401

Success response exemple: (keys are category id)
{
"1": {
"category_name": "Animals",
"user_iq": 100
},
"2": {
"category_name": "Brain Teasers",
"user_iq": 100
}
}

Implémenté

GET /category/{category_id}/image
Description Get category image
Result Type Image
Authentification mandatory? No
Controller
Parameters -
Failure cases Category doesn't exist - 404

Success response exemple:
return image

GET /rank/global/leaderboard
Description Get the 10 global best best players
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Failure cases User is not authentificated - 401

Success response infos:
JSON array are ordered. The first element of the list is the first player, and it then goes in descending order
The array must contains at maximum 10 entry. If there is less than 10 entry, it means that there is less than 10 players in the database.
Score calculation is still not decided, scores in example may not be representative of real data.

Success response example:
[
{
"user_id":123,
"user_name":"Strogator",
"user_score":1890
},
{
"user_id":3,
"user_name":"Krucksy",
"user_score":1800
},
...
]

GET /rank/global/user
Description Get the position in leaderboard and score of current user
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Failure cases User is not authentificated - 401

Success response example:
{
"user_rank": 45,
"user_score": 1000
}

GET /question/{category_id}/
Description Set the current question for the user, and return the question
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters category_id: ID of the question's category
Failure cases User is not authentificated - 401 Category does not exist - 404

Success response example {
"id":1, "category":1,
"text":"What is the fastest animal in the world?"
}

GET /question/options
Description Get the options for the user's current question
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Failure cases User is not authentificated - 401

Success response example:
{
"question_id":1,
"number_of_options":4,
"options:" {
"234:"the panther",
"432":"the cheetah",
"234":"the jaguar",
"324":"the leopard",
}
}

POST /question
Description add a question to the community category
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Failure cases User is not authentificated - 401

Request body example:
{
"question": "How old is Harry Potter at the beginning of the first book?",
"options": [
"11",
"15",
"He wasn't born"
],
"answer": "1"
}

Success response example: { "question": "How old is Harry Potter at the beginning of the first book?",
"options": [
"11",
"15",
"He wasn't born"
],
"answer": "1"
}

POST /question/answer/option
Description Send answer to current question, as one of the proposed options
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Failure cases User is not authentificated - 401 User did not ask for options - 403

request body example:
{
"answer":"232"
}

success response examples:
{
"user_is_correct":true,
"right_answer":"1",
"answer_sent":"1"
}
or
{
"user_is_correct":false,
"right_answer":"1",
"answer_sent":"he wasn't born"
}

POST /question/answer/text
Description Send answer to current question, as text
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Failure cases User is not authentificated - 401 User already asked for options - 403

Request body example: { "answer":"he wasn't born" }

success response examples:
{
"user_is_correct":true,
"right_answer":"1",
"answer_sent":"1"
}
or
{
"user_is_correct":false,
"right_answer":"1",
"answer_sent":"he wasn't born"
}

GET /rank/{category_id}/leaderboard
Description Get best players in category
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Failure cases User is not authentificated - 401 Category does not exist - 404

Success response example:
[
{
"user_id":123,
"user_name":"Strogator",
"user_iq":150 },
{
"user_id":3,
"user_name":"Krucksy",
"user_iq":136 },
...
]

GET /user_position/{category_id}
Description Get user rank and IQ in category
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Failure cases User is not authentificated - 401 Category does not exist - 404

Success response example:
{
"user_rank": 45,
"user_iq": 108
}

GET /rank/{category_id}/user
Description Get user IQ in category
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Failure cases User is not authentificated - 401 Category does not exist - 404

Success response example:
{
"user_iq": 108
}

POST /user/login
Description Authentificate user
Result Type -
Authentification mandatory? No
Controller
Parameters -
Failure cases Login credentials unvalid - 401
POST /user/register
Description Create new user account
Result Type -
Authentification mandatory? No
Controller
Parameters -
Failure cases Username already taken - 409
GET /coffee
Description Brew a coffee
Result Type -
Authentification mandatory? No
Controller
Parameters -
Failure cases The pot is a teapot - 418
Clone this wiki locally