Exemplo n.º 1
0
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)
Exemplo n.º 2
0
def sync():
    """
    Force sync of all sources
    """
    updated = DirectoryService(get_db()).sync()

    return jsonify({
        'status': 'success',
        'message': '{} updated'.format(updated),
    })
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
def get_sources():
    """
    Lists all sources and their URIs
    """
    return jsonify(DirectoryService(get_db()).get_sources())
Exemplo n.º 5
0
def delete_source(source_id):
    DirectoryService(get_db()).delete_source(source_id)

    return (jsonify({'status': 'deleted'}), 204, None)
Exemplo n.º 6
0
def get_things():
    """ returns all things known to the system """
    return jsonify(DirectoryService(get_db()).get_things())