From da873de6c8d1c8a937897583d8dc9bf7b638ec48 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Fri, 3 Aug 2018 11:20:40 +0200 Subject: [PATCH 1/2] Add basic endpoint for sending missing info --- thankful_server/main.py | 3 ++- thankful_server/rest/missing.py | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 thankful_server/rest/missing.py diff --git a/thankful_server/main.py b/thankful_server/main.py index 07b23cf..79e1d79 100644 --- a/thankful_server/main.py +++ b/thankful_server/main.py @@ -4,7 +4,7 @@ from flask_restplus import Api from . import __version__ -from .rest import creators, thanks +from .rest import creators, thanks, missing app = Flask(__name__) api = Api(app, version=__version__, title='Thankful Server API', @@ -13,6 +13,7 @@ api.add_namespace(creators.api) api.add_namespace(thanks.api) +api.add_namespace(missing.api) def main() -> None: diff --git a/thankful_server/rest/missing.py b/thankful_server/rest/missing.py new file mode 100644 index 0000000..8b9e584 --- /dev/null +++ b/thankful_server/rest/missing.py @@ -0,0 +1,34 @@ +from sys import version_info + +from flask import request +from flask_restplus import Namespace, Resource, fields + +# Backport +if (3, 5) <= version_info < (3, 7): + from dataclasses import dataclass +elif version_info < (3, 6): + raise Exception("Incompatible Python version") + +api = Namespace('missing', description='For telling us about creators without' + + 'addresses') + +missingModel = api.model('Missing', { + #'creator_url': fields.Url(required=True, description='The creator url,' + + # ' at least for this website'), + 'missing_info': fields.Raw(required=True, description='JSON') + #'donation_amount': fields.Float(required=False, description='The amount' + + # ' that the user wanted to donate'), +}) + + +@api.route('/') +class MissingResource(Resource): + '''omg how many times do i have to document this shit''' + + @api.doc('thank_creator') + @api.param('missing_info', help="The json") + def post(self): + info = request.args["missing_info"] + # TODO: Do fancier logging here + print(info) + return 'thx' \ No newline at end of file From 1c19f0528146a70963184dd95fdec41033f49911 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Fri, 3 Aug 2018 15:58:56 +0200 Subject: [PATCH 2/2] Allow cors --- Pipfile | 1 + thankful_server/main.py | 2 ++ thankful_server/rest/missing.py | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Pipfile b/Pipfile index 743d66a..ad6f9ff 100644 --- a/Pipfile +++ b/Pipfile @@ -6,6 +6,7 @@ name = "pypi" [packages] flask-restplus = "*" dataclasses = "*" +flask-cors = "*" [dev-packages] pytest = "*" diff --git a/thankful_server/main.py b/thankful_server/main.py index 79e1d79..da6d115 100644 --- a/thankful_server/main.py +++ b/thankful_server/main.py @@ -2,11 +2,13 @@ from flask import Flask from flask_restplus import Api +from flask_cors import CORS from . import __version__ from .rest import creators, thanks, missing app = Flask(__name__) +CORS(app) api = Api(app, version=__version__, title='Thankful Server API', description='An API for getting information about creators') # TODO: Do some fancy stuff with blueprints to handle versions diff --git a/thankful_server/rest/missing.py b/thankful_server/rest/missing.py index 8b9e584..b80cfaf 100644 --- a/thankful_server/rest/missing.py +++ b/thankful_server/rest/missing.py @@ -23,7 +23,7 @@ @api.route('/') class MissingResource(Resource): - '''omg how many times do i have to document this shit''' + '''beep boop documentation''' @api.doc('thank_creator') @api.param('missing_info', help="The json")