Last active
August 29, 2015 14:22
-
-
Save LukasGasior1/699439c80d69e3a8d961 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def createGame() = Action.async { request => | |
WS.url(s"$apiUrl/game") | |
.post("") | |
.map { | |
case res if res.status == CREATED => Created(res.body) | |
case _ => InternalServerError | |
} | |
.recover { case _ => InternalServerError } | |
} | |
def startGame(gameId: String, playersCount: Int) = Action.async { request => | |
val players = 1 to playersCount map { n => s"Player$n"} | |
postCommand( | |
url = s"/game/$gameId/start", | |
data = Json.obj("players" -> players)) | |
} | |
def roll(gameId: String, playerId: String) = Action.async { request => | |
postCommand( | |
url = s"/game/$gameId/roll/$playerId", | |
data = Json.obj()) | |
} | |
private def postCommand(url: String, data: JsValue) = { | |
WS.url(s"$apiUrl$url") | |
.post(data) | |
.map { | |
case res if res.status == ACCEPTED => Accepted | |
case res if res.status == BAD_REQUEST => BadRequest(res.body) | |
case res => InternalServerError | |
} | |
.recover { case _ => InternalServerError } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment