def handle_exceptions(exc): """ Re-format exceptions to JSON if accept requires that. """ format = response_format(app, request) if format == 'json': body = {'status': exc.code, 'name': exc.name, 'description': exc.get_description(request.environ)} return jsonify(body, status=exc.code, headers=exc.get_headers(request.environ)) return exc
def handle_invalid(exc): format = response_format(app, request) if format == 'json': body = {'status': 400, 'name': 'Invalid Data', 'description': unicode(exc), 'errors': exc.unpack_errors()} return jsonify(body, status=400) return Response(repr(exc.unpack_errors()), status=400, mimetype='text/plain')
def handle_invalid(exc): format = response_format(app, request) if format == 'json': body = { 'status': 400, 'name': 'Invalid Data', 'description': unicode(exc), 'errors': exc.unpack_errors() } return jsonify(body, status=400) return Response(repr(exc.unpack_errors()), status=400, mimetype='text/plain')
def handle_exceptions(exc): """ Re-format exceptions to JSON if accept requires that. """ format = response_format(app, request) if format == 'json': body = { 'status': exc.code, 'name': exc.name, 'description': exc.get_description(request.environ) } return jsonify(body, status=exc.code, headers=exc.get_headers(request.environ)) return exc
def index(owner): """ List all the datasets of a particular user. """ result = logic.dataset.list_by_owner(owner) return jsonify(list(result))
def update(owner, resource): """ Update the data of the resource. """ data = request_content(request) resource = logic.resource.update(owner, resource, data) return jsonify(resource)
def get(owner, resource): """ Get a JSON representation of the resource. """ resource = logic.resource.find(owner, resource) return jsonify(resource)
def stream(type, id): """ Get the latest events on the given event stream. """ events = logic.event.latest_by_stream(type, id) events = Pager(events, '.stream', request.args, limit=50, type=type, id=id) return jsonify(events)
def update(owner, dataset): """ Update the data of the dataset. """ data = request_content(request) dataset = logic.dataset.update(owner, dataset, data) return jsonify(dataset)
def resources_get(owner, dataset): """ Get a JSON representation of the resources in this dataset. """ resources = logic.dataset.list_resources(owner, dataset) return jsonify(resources)
def get(owner, dataset): """ Get a JSON representation of the dataset. """ dataset = logic.dataset.find(owner, dataset) return jsonify(dataset)
def get(account): """ Get a JSON representation of the account. """ account = logic.account.find(account) return jsonify(account)
def update(account): """ Update the data of the account profile. """ data = request_content(request) account = logic.account.update(account, data) return jsonify(account)
def get(event): """ Get a JSON representation of the event. """ event = logic.event.find(event) return jsonify(event)
def index(owner): """ List all the resources of a particular user. """ result = logic.resource.list_by_owner(owner) return jsonify(list(result))
def apiroot(): return jsonify({ 'api': 'ok', 'version': 1, 'site_id': app.config.get('SITE_ID', 'datahub.local') })
def apiroot(): return jsonify({'api': 'ok', 'version': 1, 'site_id': app.config.get('SITE_ID', 'datahub.local') })