from typing import Mapping


def resolve_to_uri(thingit):
    """Given any of:
- the URI for an ArchivesSpace object
- a dict with a key 'uri' or 'ref' containing said URI
- an object responding to .json() returning such a dict

this method will return a string containing the URI for that resource.
    """
    uri = None
    # if object has .json(), replace with value of .json()
    if callable(getattr(thingit, 'json', None)):
        thingit = thingit.json()
    if isinstance(thingit, str):
        uri = thingit
    elif isinstance(thingit, Mapping):
        uri = thingit.get("uri", thingit.get("ref", None))
    if not uri:
        raise Exception('Could not resolve "{}" to a URI'.format(thingit))
    return uri