Status and settings members can be accessed via URI

This commit is contained in:
Joel Collins 2019-11-21 15:53:22 +00:00
parent de73ae4e0a
commit dc99a12985
4 changed files with 80 additions and 6 deletions

View file

@ -4,8 +4,9 @@ Read-only status of the microscope, and attached hardware info
from openflexure_microscope.api.views import MicroscopeView
from openflexure_microscope.api.utilities import blueprint_for_module
from openflexure_microscope.utilities import get_by_path
from flask import Blueprint, jsonify
from flask import Blueprint, jsonify, abort
class StatusAPI(MicroscopeView):
@ -58,6 +59,19 @@ class StatusAPI(MicroscopeView):
return jsonify(self.microscope.status)
class NestedStatusAPI(MicroscopeView):
def get(self, route):
keys = route.split("/")
try:
value = get_by_path(self.microscope.status, keys)
except KeyError:
return abort(404)
return jsonify(value)
def construct_blueprint(microscope_obj):
blueprint = blueprint_for_module(__name__)
@ -66,4 +80,9 @@ def construct_blueprint(microscope_obj):
"/", view_func=StatusAPI.as_view("status", microscope=microscope_obj)
)
blueprint.add_url_rule(
"/<path:route>",
view_func=NestedStatusAPI.as_view("nested_status", microscope=microscope_obj),
)
return blueprint