-
Notifications
You must be signed in to change notification settings - Fork 0
API Doc
Alan Luo edited this page Sep 14, 2020
·
13 revisions
https://expanding-nim.iltc.app
POST /sessions.json
Name | Type | Required | Description |
---|---|---|---|
name | String | Yes | Player A's name |
stones | Integer | Yes | Number of stones to start |
curl -H "Content-Type: application/json" \
-d '{"name": "Alan", "stones": 100}' \
-X POST "https://expanding-nim.iltc.app/sessions.json"
{
"status": "success",
"game_status": "wait_for_b_join",
"session_id": 10,
"token": "1436b2d1c6d981b693508da9ef78bd2d"
}
- The player who creates a new session will always be the first player (
Player A
) in the game. - The
token
will only be shown once. If you lost it, you need to start a new session.
POST /sessions/join.json
Name | Type | Required | Description |
---|---|---|---|
id | Integer | Yes | The id of the session that you want to join. |
name | String | Yes | Player B's name |
curl -H "Content-Type: application/json" \
-d '{"id": 10, "name": "Bob"}' \
-X POST "https://expanding-nim.iltc.app/sessions/join.json"
{
"status": "success",
"game_status": "wait_for_a_move",
"session_id": 10,
"token": "519c718c979c7b2fd2dbca26e2496735"
}
GET /sessions/[session-id]/status.json?token=[token]
Name | Type | Required | Description |
---|---|---|---|
session-id | Integer | Yes | The id of the session that you want to check status. |
token | String | Yes | The token you received when creating or joining a session. |
curl -H "Content-Type: application/json" \
-X GET "https://expanding-nim.iltc.app/sessions/10/status.json?token=519c718c979c7b2fd2dbca26e2496735"
If it is not your turn:
{
"status": "success",
"game_status": "wait_for_a_move",
"your_turn": false,
"message": "It's not your turn yet. Please wait for other player. Please don't refresh too frequently. Status: Wait for Player A's Move"
}
If it is your turn:
{
"status": "success",
"game_status": "wait_for_a_move",
"your_turn": true,
"message": "It's your turn now. Please make a move.",
"stones_left": 100,
"reset": false,
"current_max": 0,
"accept_max_value": 3,
"reset_left": 4,
"start_time": "2020-09-12T14:36:22.618Z",
"time_left": 120
}
- Please do not request this endpoint too frequently, as the backend server may think you are making a DDOS attack.
- The clock will not start until you made a request to
/sessions/[session-id]/status.json?token=[token]
and receiveyour_turn = true
. - For now, nothing will happen when
time_left
is 0 or negative. During the class, the game will end and the other player will win if youtime_left
reaches 0 first.
POST /sessions/[session-id]/move.json?token=[token]
Name | Type | Required | Location | Description |
---|---|---|---|---|
session-id | Integer | Yes | URL | The id of the session that you want to check status. |
token | String | Yes | URL | The token you received when creating or joining a session. |
stones | Integer | Yes | Body | The number of stones you want to remove. |
reset | String | No | Body | Whether or not you want to impose reset. Accept values are yes or no (default). |
curl -H "Content-Type: application/json" \
-d '{"stones": 3, "reset": "no"}' \
-X POST "https://expanding-nim.iltc.app/sessions/10/move.json?token=519c718c979c7b2fd2dbca26e2496735"
{
"status": "success"
}
- Please make sure you requested
/sessions/[session-id]/status.json?token=[token]
and receivedyour_turn = true
before requesting this endpoint. Otherwise, the clock will not function correctly. - For now, you can request this endpoint from anywhere (your laptop,
linserv1
, etc.). During the class, requests to this endpoint must come fromlinserv1
, and other IPs will be blocked.