def devices_create(): new_device = Device.create(request.remote_addr, request.user_agent) response = jsonate(new_device.to_dict()) response.status_code = 201 response.headers['Location'] = url_for( 'devices_get', device_id=new_device.id) return response
def players_get(game_id, player_id): get_game_or_abort(game_id) player = Player.query.get(player_id) if not player: abort(404, 'Player not found') response = jsonate(player.to_dict()) return response
def games_create(): current_game = Game.current() if current_game: abort(403, 'Game %s is in progress' % current_game.id) new_game = Game() db.session.add(new_game) db.session.commit() response = jsonate(new_game.to_dict()) response.status_code = 201 response.headers['Location'] = url_for('games_get', game_id=new_game.id) return response
def players_create(game_id): game = get_game_or_abort(game_id) if game.ended_at is not None: abort(403, 'Cannot join a player to a finished game') device_id = request.json.get('deviceId', None) if not device_id: abort(403, 'Must supply deviceId') device = Device.query.get(device_id) if not device: abort(403, 'Device %s not found' % device_id) clan = request.json.get('clan', random.choice(config['clans'])) territory = request.json.get('territory', None) player = Player.create(game.id, device.id, clan, territory) response = jsonate(player.to_dict()) response.status_code = 201 response.headers['Location'] = url_for( 'players_get', game_id=game.id, player_id=player.id) return response
def devices_get(device_id): device = Device.query.get(device_id) if not device: abort(404, 'Device not found') response = jsonate(device.to_dict()) return response
def devices_index(): response = jsonate([d.to_dict() for d in Device.query.all()]) return response
def players_index(game_id): get_game_or_abort(game_id) response = jsonate([p.to_dict() for p in Player.query.all()]) return response
def game_current(): game = Game.current() return jsonate(game.to_dict())
def games_get(game_id): game = get_game_or_abort(game_id) return jsonate(game.to_dict())
def games_index(): response = jsonate([g.to_dict() for g in Game.query.all()]) return response