basic game creation API
This commit is contained in:
parent
1fa7e43bbe
commit
d74f304330
@ -1,11 +1,11 @@
|
||||
import flask
|
||||
|
||||
from truthseeker import api
|
||||
from truthseeker import routes_api
|
||||
|
||||
app = flask.Flask("truthseeker")
|
||||
|
||||
app.register_blueprint(api.api_routes, url_prefix="/api/v1")
|
||||
app.register_blueprint(routes_api.api_routes, url_prefix="/api/v1")
|
||||
|
||||
@app.route("/")
|
||||
def hello():
|
||||
return "Hello World!"
|
||||
return "Hello World!"
|
||||
|
@ -1,6 +0,0 @@
|
||||
import flask
|
||||
api_routes = flask.Blueprint("api", __name__)
|
||||
|
||||
@api_routes.route("/newGame")
|
||||
def hello():
|
||||
return "Created new game"
|
24
truthseeker/game_api.py
Normal file
24
truthseeker/game_api.py
Normal file
@ -0,0 +1,24 @@
|
||||
import string
|
||||
import random
|
||||
|
||||
game_lists = {}
|
||||
|
||||
def random_string(length):
|
||||
return "".join(random.choice(string.ascii_letters) for _ in range(length))
|
||||
|
||||
class GameInfo:
|
||||
def __init__(self):
|
||||
self.start_token = None
|
||||
|
||||
def create_game():
|
||||
game = GameInfo()
|
||||
game.id = random_string(6)
|
||||
game.start_token = random_string(64)
|
||||
game_lists[game.id] = game
|
||||
return game
|
||||
|
||||
def get_game_info(game_id):
|
||||
if game_id in game_lists:
|
||||
return game_lists[game_id]
|
||||
else:
|
||||
return None
|
21
truthseeker/routes_api.py
Normal file
21
truthseeker/routes_api.py
Normal file
@ -0,0 +1,21 @@
|
||||
import flask
|
||||
|
||||
from truthseeker import game_api
|
||||
|
||||
api_routes = flask.Blueprint("api", __name__)
|
||||
|
||||
@api_routes.route("/createGame")
|
||||
def create_game():
|
||||
return "Created game {}".format(game_api.create_game().id)
|
||||
|
||||
@api_routes.route("/getGameInfo")
|
||||
def get_game_info():
|
||||
gameid = flask.request.args.get("gameid")
|
||||
if gameid == None:
|
||||
return "No 'gameid' argument"
|
||||
game = game_api.get_game_info(gameid)
|
||||
if game == None:
|
||||
return "Game {} does not exist".format(gameid)
|
||||
else:
|
||||
return "Game {} start token : {}".format(gameid, game.start_token)
|
||||
|
Loading…
Reference in New Issue
Block a user