def get_thing(thing_id): thing = None try: thing = DirectoryService(get_db()).get_thing(thing_id) except IndexError as e: return (jsonify({'status': 'error', 'message': str(e)}), 404, None) return jsonify(thing)
def sync(): """ Force sync of all sources """ updated = DirectoryService(get_db()).sync() return jsonify({ 'status': 'success', 'message': '{} updated'.format(updated), })
def new_sources(): """ Creates new sources. This takes the uri where descriptions can be found """ failed = list() for source in request.get_json(): try: DirectoryService(get_db()).new_source(source) except HTTPError: failed.append(source) if len(failed) > 0: return (jsonify({ 'status': 'warning', 'message': 'not all created ({})'.format(','.join(failed)), }), 201, None) return (jsonify({'status': 'success'}), 201, None)
def get_sources(): """ Lists all sources and their URIs """ return jsonify(DirectoryService(get_db()).get_sources())
def delete_source(source_id): DirectoryService(get_db()).delete_source(source_id) return (jsonify({'status': 'deleted'}), 204, None)
def get_things(): """ returns all things known to the system """ return jsonify(DirectoryService(get_db()).get_things())