aboutsummaryrefslogtreecommitdiff
path: root/ihatemoney
diff options
context:
space:
mode:
Diffstat (limited to 'ihatemoney')
-rw-r--r--ihatemoney/api/__init__.py0
-rw-r--r--ihatemoney/api/common.py (renamed from ihatemoney/api.py)26
-rw-r--r--ihatemoney/api/v1/__init__.py5
-rw-r--r--ihatemoney/api/v1/resources.py34
-rw-r--r--ihatemoney/run.py4
5 files changed, 43 insertions, 26 deletions
diff --git a/ihatemoney/api/__init__.py b/ihatemoney/api/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/ihatemoney/api/__init__.py
diff --git a/ihatemoney/api.py b/ihatemoney/api/common.py
index 67c6cc1..728d2a8 100644
--- a/ihatemoney/api.py
+++ b/ihatemoney/api/common.py
@@ -1,7 +1,6 @@
# coding: utf8
-from flask import Blueprint, request, current_app
-from flask_restful import Resource, Api, abort
-from flask_cors import CORS
+from flask import request, current_app
+from flask_restful import Resource, abort
from wtforms.fields.core import BooleanField
from ihatemoney.models import db, Project, Person, Bill
@@ -10,11 +9,6 @@ from werkzeug.security import check_password_hash
from functools import wraps
-api = Blueprint("api", __name__, url_prefix="/api")
-CORS(api)
-restful_api = Api(api)
-
-
def need_auth(f):
"""Check the request for basic authentication for a given project.
@@ -195,19 +189,3 @@ class TokenHandler(Resource):
token = project.generate_token()
return {"token": token}, 200
-
-
-restful_api.add_resource(ProjectsHandler, "/projects")
-restful_api.add_resource(ProjectHandler, "/projects/<string:project_id>")
-restful_api.add_resource(TokenHandler, "/projects/<string:project_id>/token")
-restful_api.add_resource(MembersHandler, "/projects/<string:project_id>/members")
-restful_api.add_resource(
- ProjectStatsHandler, "/projects/<string:project_id>/statistics"
-)
-restful_api.add_resource(
- MemberHandler, "/projects/<string:project_id>/members/<int:member_id>"
-)
-restful_api.add_resource(BillsHandler, "/projects/<string:project_id>/bills")
-restful_api.add_resource(
- BillHandler, "/projects/<string:project_id>/bills/<int:bill_id>"
-)
diff --git a/ihatemoney/api/v1/__init__.py b/ihatemoney/api/v1/__init__.py
new file mode 100644
index 0000000..11afff7
--- /dev/null
+++ b/ihatemoney/api/v1/__init__.py
@@ -0,0 +1,5 @@
+from .resources import api
+
+__all__ = [
+ "api",
+]
diff --git a/ihatemoney/api/v1/resources.py b/ihatemoney/api/v1/resources.py
new file mode 100644
index 0000000..821ba2b
--- /dev/null
+++ b/ihatemoney/api/v1/resources.py
@@ -0,0 +1,34 @@
+# coding: utf8
+from flask import Blueprint
+from flask_restful import Api
+from flask_cors import CORS
+
+from ihatemoney.api.common import (
+ ProjectsHandler,
+ ProjectHandler,
+ TokenHandler,
+ MemberHandler,
+ ProjectStatsHandler,
+ MembersHandler,
+ BillHandler,
+ BillsHandler,
+)
+
+api = Blueprint("api", __name__, url_prefix="/api")
+CORS(api)
+restful_api = Api(api)
+
+restful_api.add_resource(ProjectsHandler, "/projects")
+restful_api.add_resource(ProjectHandler, "/projects/<string:project_id>")
+restful_api.add_resource(TokenHandler, "/projects/<string:project_id>/token")
+restful_api.add_resource(MembersHandler, "/projects/<string:project_id>/members")
+restful_api.add_resource(
+ ProjectStatsHandler, "/projects/<string:project_id>/statistics"
+)
+restful_api.add_resource(
+ MemberHandler, "/projects/<string:project_id>/members/<int:member_id>"
+)
+restful_api.add_resource(BillsHandler, "/projects/<string:project_id>/bills")
+restful_api.add_resource(
+ BillHandler, "/projects/<string:project_id>/bills/<int:bill_id>"
+)
diff --git a/ihatemoney/run.py b/ihatemoney/run.py
index 6d1e032..161761c 100644
--- a/ihatemoney/run.py
+++ b/ihatemoney/run.py
@@ -8,7 +8,7 @@ from flask_mail import Mail
from flask_migrate import Migrate, upgrade, stamp
from werkzeug.middleware.proxy_fix import ProxyFix
-from ihatemoney.api import api
+from ihatemoney.api.v1 import api as apiv1
from ihatemoney.models import db
from ihatemoney.utils import (
IhmJSONEncoder,
@@ -132,7 +132,7 @@ def create_app(
validate_configuration(app)
app.register_blueprint(web_interface)
- app.register_blueprint(api)
+ app.register_blueprint(apiv1)
app.register_error_handler(404, page_not_found)
# Configure the a, root="main"pplication