inspirehep/inspire-dojson

utils: spin out jsonref utils to inspire-utils

Opened this issue · 0 comments

These two guys:

def get_recid_from_ref(ref_obj):
"""Retrieve recid from jsonref reference object.
If no recid can be parsed, returns None.
"""
if not isinstance(ref_obj, dict):
return None
url = ref_obj.get('$ref', '')
return maybe_int(url.split('/')[-1])
and
def get_record_ref(recid, endpoint='record'):
"""Create record jsonref reference object from recid.
None recids will return a None object.
Valid recids will return an object in the form of: {'$ref': url_for_record}
"""
if recid is None:
return None
return {'$ref': absolute_url('/api/{}/{}'.format(endpoint, recid))}
.

The problem is that they depend on absolute_url, so this requires #57 to be fixed.