2020-09-15 11:22:28 +00:00
|
|
|
import flask
|
2020-09-15 15:44:12 +00:00
|
|
|
import json
|
2020-09-15 11:22:28 +00:00
|
|
|
import teal.marshmallow
|
2020-09-16 15:40:16 +00:00
|
|
|
import pkg_resources
|
2020-09-15 11:22:28 +00:00
|
|
|
|
|
|
|
from typing import Callable, Iterable, Tuple
|
|
|
|
from flask import make_response, g
|
2020-09-15 15:44:12 +00:00
|
|
|
from teal.resource import Resource, View
|
|
|
|
|
|
|
|
|
|
|
|
class VersionView(View):
|
|
|
|
def get(self, *args, **kwargs):
|
|
|
|
"""Get version."""
|
2020-09-16 15:40:16 +00:00
|
|
|
|
|
|
|
v = "{}".format(pkg_resources.require('ereuse-devicehub')[0].version)
|
2020-09-15 15:44:12 +00:00
|
|
|
return json.dumps({'devicehub': v})
|
2020-09-15 11:22:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
class VersionDef(Resource):
|
|
|
|
__type__ = 'Version'
|
|
|
|
SCHEMA = None
|
|
|
|
VIEW = None # We do not want to create default / documents endpoint
|
|
|
|
AUTH = False
|
|
|
|
|
|
|
|
def __init__(self, app,
|
|
|
|
import_name=__name__,
|
2020-09-15 15:44:12 +00:00
|
|
|
static_folder='static',
|
2020-09-15 11:22:28 +00:00
|
|
|
static_url_path=None,
|
2020-09-15 15:44:12 +00:00
|
|
|
template_folder='templates',
|
2020-09-15 11:22:28 +00:00
|
|
|
url_prefix=None,
|
|
|
|
subdomain=None,
|
|
|
|
url_defaults=None,
|
|
|
|
root_path=None,
|
|
|
|
cli_commands: Iterable[Tuple[Callable, str or None]] = tuple()):
|
2020-09-15 15:44:12 +00:00
|
|
|
super().__init__(app, import_name, static_folder, static_url_path, template_folder,
|
2020-09-15 11:22:28 +00:00
|
|
|
url_prefix, subdomain, url_defaults, root_path, cli_commands)
|
|
|
|
|
2020-09-15 15:44:12 +00:00
|
|
|
d = {'devicehub': '0.1.0a'}
|
|
|
|
get = {'GET'}
|
2020-09-15 11:22:28 +00:00
|
|
|
|
2020-09-16 15:40:16 +00:00
|
|
|
version_view = VersionView.as_view('VersionView', definition=self)
|
2020-09-15 15:44:12 +00:00
|
|
|
self.add_url_rule('/', defaults=d, view_func=version_view, methods=get)
|