# Apply all known migrations to bring the database schema up to date
migrate_api.upgrade(db_uri, repo, migrate_api.version(repo))
-from imoo import views
+from imoo import views, api
def create_app():
app = Flask(__name__)
# Enable routes
app.register_blueprint(views.blueprint, url_prefix="")
+ app.register_blueprint(api.blueprint, url_prefix="/api")
# Return configured app
return app
--- /dev/null
+from flask import Blueprint
+from flask.ext.restful import Api, Resource, marshal, marshal_with, fields
+
+blueprint = Blueprint('api', 'api')
+api = Api(blueprint)
+
+user_fields = {
+ 'id': fields.Integer,
+ 'username': fields.String,
+ }
+
+chatnetwork_fields = {
+ 'id': fields.Integer,
+ 'user_id': fields.Integer,
+ 'network': fields.Integer, # TODO: map this to/from ChatNetworkAccount.chatnetworks
+ 'username': fields.String,
+ }
+
+class UserResource(Resource):
+ @marshal_with(user_fields)
+ def get(self, user_id):
+ user = models.User.query.get_or_404(user_id)
+ return user
+
+class ChatNetworkAccountResource(Resource):
+ @marshal_with(chatnetwork_fields)
+ def get(self, account_id):
+ cna = models.ChatNetworkAccount.query.get_or_404(account_id)
+ return cna
+
+api.add_resource(UserResource, '/users/<string:user_id>')
+api.add_resource(ChatNetworkAccountResource, '/accounts/<string:account_id>')