forked from sshirokov/gogogo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[webservice] Moved app into a module
- Loading branch information
Showing
3 changed files
with
60 additions
and
53 deletions.
There are no files selected for viewing
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import json | ||
|
||
import bottle | ||
|
||
from gogogo.game import Game, GameError | ||
from gogogo.server.app import app | ||
from gogogo.server.filters import with_game | ||
|
||
|
||
routes = { | ||
'root': { | ||
'GET': [{'/': 'home'}] | ||
}, | ||
'game': { | ||
'GET': [{'/game/{game}/': 'Load game'}], | ||
'POST': [{'/game/create/': 'Create a new game'}], | ||
}, | ||
} | ||
|
||
@app.post('/game/:game#[0-9a-f]+#/player/create/', name='game-player-create') | ||
@with_game | ||
def register_player(game): | ||
try: data = json.loads(bottle.request.body.read()) | ||
except ValueError: raise bottle.HTTPResponse({'message': "JSON seems invalid"}, 400) | ||
print "I got data:", data | ||
print "For game:", game | ||
|
||
@app.get('/game/:game#[0-9a-f]+#/branch/', name='game-branch-index') | ||
@with_game | ||
def branches(game): | ||
return {'message': '', | ||
'data': game.branches()} | ||
|
||
@app.post('/game/:game#[0-9a-f]+#/branch/create/', name='game-branche-create') | ||
@with_game | ||
def create_branch(game): | ||
pass | ||
|
||
@app.get('/game/:game#[0-9a-f]+#/branch/:branch/', name='game-branch') | ||
@with_game | ||
def game(game, branch): | ||
pass | ||
|
||
@app.get('/game/:game#[0-9a-f]+#/', name='game-index') | ||
@with_game | ||
def game(game): | ||
return {'message': '', | ||
'turn': game.board.player_turn(), | ||
'data': game.board.take_snapshot()} | ||
|
||
@app.post('/game/create/', name='game-create') | ||
def new_game(): | ||
game = Game(create=True) | ||
bottle.redirect(app.get_url('game-index', name=game.name)) | ||
|
||
@app.get('/', name='index') | ||
def index(): | ||
return {'message': '', | ||
'data': routes} |