Der Code wurde testgetrieben entwickelt: Die Unit-Tests sind mit Hilfe des RSpec Frameworks geschrieben, die Acceptance Tests mit Cucumber und Faraday.
Hier nun der Stand der API – den aktuellen Stand gibt es immer hier.
# API
A request is always a JSON Object with the given types (`lobby_id`, `game_state` etc.) as the key and a value as described in the section **Data Types**. A section of an URL beginning with colons has to be replaced by a value in the form described in the section **Data Types**. The response section of the routes always describes the success and failure case, each with the according Status Code and the body (if there is any). A failure will always have a body as JSON object with a key `failure` and a String value with the description of the error.
## Data Types
We define a number of data types which are represented via JSON.
### Identifier
`id`, `lobby_id`, `player_id`, `vertex_a_id` and `vertex_b_id` are all represented as Strings. Only use IDs provided by the server.
### Geo Position
`lat` and `long` are both represented as Strings (and are the String representation of a Java `Double`).
### Name
`player_name` and `lobby_name` are represented as Strings and may only contain upper- and lowercase letters and numbers.
### Lobby Arrays
`lobbies` is an array, each element has the following attributes:
* `id`
* `lobby_name`
### Player
`player` is a JSON Object with the following attributes:
* `id` (as described above)
* `lat` (as described above)
* `lon` (as described above)
### Vertex
`vertex` is a JSON Object with the following attributes:
* `id` (as described above)
* `lat` (as described above)
* `lon` (as described above)
* `carrier`: Either "" (if carried by no one) or a `player\_id` (as described above)
### Game State
`game_state` is a JSON Object with the following attributes:
* `vertices` is an Array, each element is a `vertex` (as described above)
* `players` is an Array, each element is a `player` (as described above)
* `is_finished` is a Boolean
### Game Statistics
`game_statistics` is a JSON Object with the IDs of all players as keys, each has an object with the following keys as its value:
* `distance`: Number
* `different_vertices_touched`: Number
* `total_vertices_touched`: Number
### Game
`game` is a JSON Object with the following attributes:
* `vertices` is an Array, each element has the following attributes:
* `id` (as described above)
* `lat` (as described above)
* `lon` (as described above)
* `portable`: Either true or false
* `carrier`: Either "" (if carried by no one) or a `player\_id` (as described above)
* `edges` is an Array, each element has the following attributes:
* `vertex_a_id` (as described above)
* `vertex_b_id` (as described above)
* `color`: A String
* `players` is an Array, each element has the following attributes:
* `id` (as described above)
* `player_name` (as described above)
* `lat` (as described above)
* `lon` (as described above)
* `is_started` is a Boolean
### Player Statistics
`player_statistics` is a JSON Object with the following attributes:
* `distance`: Number
* `different_vertices_touched`: Number
* `total_vertices_touched`: Number
### Graph
`graph` is a JSON Object with the following attributes:
* `vertices` is an Array, each element has the following attributes:
* `id` (as described above)
* `lat` (as described above)
* `lon` (as described above)
* `portable`: Either true or false
* `edges` is an Array, each element has the following attributes:
* `vertex_a_id` (as described above)
* `vertex_b_id` (as described above)
* `color`: A String
## Routes
We define a number of routes to post to and get information from the server.
### POST: `/update`
Updates the position of the player and the vertex he or she carries.
#### Request
* player
* vertex
#### Response
* Success: 204
* Failure: 500
### GET: `/currentGameState/:lobby_id`
Get the current game state for the given lobby.
Example:
```
curl -X GET -H "Content-Type: application/json" http://localhost:9292/currentGameState/1212ffa11
```
#### Response
* Success: 200, body: GameState
* Failure (e.g. game was not started yet): 500
### POST: `/finishGame`
Marks the game as finished.
#### Request
* lobby\_id
#### Response
* Success: 204
* Failure: 500
### GET: `/game/:lobby_id`
Get all information about a game (including players, edges).
#### Response
* Success: 200, body: Game
* Failure: 500
### POST: `/lobby`
Create a new lobby with a given name
#### Request
* lobby_name
#### Response
* Success: 201, body: lobby\_id
* Failure (e.g. Lobby with this name already exists): 500
### POST: `/player`
Create a new player with a given name.
#### Request
* player_name
#### Response
* Success: 201, body: player\_id
* Failure (e.g. A player with this name already exists): 500
### POST: `/joinLobby`
Let a player with a certain ID join a certain lobby.
#### Request
* lobby\_id
* player\_id
#### Response
* Success: 204
* Failure (e.g. Lobby does not exist): 500
### GET: `/lobbies`
Get all available lobbies.
#### Response
* Success: 200, body: lobbies
* Failure: 500
### POST: `/game`
Start a game for a certain lobby with a given graph.
#### Request
* lobby\_id
* graph
#### Response
* Success: 204
* Failure (e.g. the game was already started): 500
### POST: `/leaveLobby`
Remove a player from a certain lobby.
#### Request
* lobby\_id
* player\_id
#### Response
* Success: 204
* Failure: 500
Keine Kommentare:
Kommentar veröffentlichen