Skip to content

Commit

Permalink
[webservice] Moved app into a module
Browse files Browse the repository at this point in the history
  • Loading branch information
sshirokov authored and sbryant committed Nov 26, 2010
1 parent c493cc6 commit 48ce720
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 53 deletions.
54 changes: 1 addition & 53 deletions gogogo/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,7 @@

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}

from gogogo.server.app import routes

def run(addr='localhost', port=9090, **kwargs):
bottle.debug(kwargs.pop('debug', False))
Expand Down
File renamed without changes.
59 changes: 59 additions & 0 deletions gogogo/server/app/routes.py
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}

0 comments on commit 48ce720

Please sign in to comment.