Example #1
0
def get_item_from_namespace_nid(namespace,
                                nid,
                                format=None,
                                include_history=False):
    namespace = item_module.clean_id(namespace)
    nid = item_module.clean_id(nid)

    include_history = request.args.get("include_history",
                                       0) in ["1", "true", "True"]
    register = request.args.get("register", 0) in ["1", "true", "True"]
    callback_name = request.args.get("callback", None)
    api_key = request.values.get('key')

    debug_message = ""
    if register:
        try:
            api_user.register_item((namespace, nid), api_key, myredis, mydao)
        except api_user.ItemAlreadyRegisteredToThisKey:
            debug_message = u"ItemAlreadyRegisteredToThisKey for key {api_key}".format(
                api_key=api_key)
            logger.debug(debug_message)
        except api_user.ApiLimitExceededException:
            debug_message = u"ApiLimitExceededException for key {api_key}".format(
                api_key=api_key)
            logger.debug(debug_message)

    tiid = item_module.get_tiid_by_alias(namespace, nid, mydao)
    if not tiid:
        if not debug_message:
            debug_message = "Item not in database. Call POST to register it"
        # if registration failure, report that info. Else suggest they register.
        abort_custom(404, debug_message)
    return get_item_from_tiid(tiid, format, include_history, callback_name)
Example #2
0
def get_item_from_namespace_nid(namespace, nid, format=None, include_history=False):
    namespace = item_module.clean_id(namespace)
    nid = item_module.clean_id(nid)

    include_history = request.args.get("include_history", 0) in ["1", "true", "True"]
    register = request.args.get("register", 0) in ["1", "true", "True"]
    callback_name = request.args.get("callback", None)
    api_key = request.values.get('key')

    debug_message = ""
    if register:
        try:
            api_user.register_item((namespace, nid), api_key, myredis, mydao)
        except api_user.ItemAlreadyRegisteredToThisKey:
            debug_message = u"ItemAlreadyRegisteredToThisKey for key {api_key}".format(
                api_key=api_key)
            logger.debug(debug_message)
        except api_user.ApiLimitExceededException:
            debug_message = u"ApiLimitExceededException for key {api_key}".format(
                api_key=api_key)
            logger.debug(debug_message)

    tiid = item_module.get_tiid_by_alias(namespace, nid, mydao)
    if not tiid:
        if not debug_message:
            debug_message = "Item not in database. Call POST to register it"
        # if registration failure, report that info. Else suggest they register.
        abort_custom(404, debug_message)
    return get_item_from_tiid(tiid, format, include_history, callback_name)
Example #3
0
def get_alias_strings(aliases):
    alias_strings = []
    for (namespace, nid) in aliases:
        namespace = item_module.clean_id(namespace)
        nid = item_module.clean_id(nid)
        try:
            alias_strings += [namespace + ":" + nid]
        except TypeError:
            # jsonify the biblio dicts
            alias_strings += [namespace + ":" + json.dumps(nid)]
    return alias_strings
Example #4
0
def get_alias_strings(aliases):
    alias_strings = []
    for (namespace, nid) in aliases:
        namespace = item_module.clean_id(namespace)
        nid = item_module.clean_id(nid)
        try:
            alias_strings += [namespace+":"+nid]
        except TypeError:
            # jsonify the biblio dicts
            alias_strings += [namespace+":"+json.dumps(nid)]
    return alias_strings   
Example #5
0
def item_namespace_post(namespace, nid):
    namespace = item_module.clean_id(namespace)
    nid = item_module.clean_id(nid)

    api_key = request.values.get('key')
    try:
        api_user.register_item((namespace, nid), api_key, myredis, mydao)
        response_code = 201 # Created
    except api_user.ItemAlreadyRegisteredToThisKey:
        response_code = 200
    except api_user.ApiLimitExceededException:
        abort_custom(403, "Registration limit exceeded. Contact [email protected] to discuss options.")

    resp = make_response(json.dumps("ok"), response_code)
    return resp
Example #6
0
def item_namespace_post(namespace, nid):
    namespace = item_module.clean_id(namespace)
    nid = item_module.clean_id(nid)

    api_key = request.values.get('key')
    try:
        api_user.register_item((namespace, nid), api_key, myredis, mydao)
        response_code = 201  # Created
    except api_user.ItemAlreadyRegisteredToThisKey:
        response_code = 200
    except api_user.ApiLimitExceededException:
        abort_custom(
            403,
            "Registration limit exceeded. Contact [email protected] to discuss options."
        )

    resp = make_response(json.dumps("ok"), response_code)
    return resp