import requests


def get_object(
    token: str,
    url: str = "https://dev-api.aioneers.tech/v1/",
    object: str = "dotTypes",
) -> list:
    """Get JSON object.

    Parameters
    ----------
    token : str
        Token which was returned from the user login.
    url : str = "https://dev-api.aioneers.tech/v1/"
        Url of the API.
    object : str = "dotTypes"
        Object to be extracted from the API.

    Returns
    -------
    list
        List of JSON objects.

    Raises
    ------
    ValueError
        Raises ValueError when the input is not correct.
    """
    url = url.strip("/")
    object = object.lower()

    if object == "metrictypes":
        url += "/metricTypes"
    elif object == "metrics":
        url += "/metrics"
    elif object == "dottypes" or object == "trackingobjecttypes":
        url += "/trackingObjectTypes"
    elif object == "dots" or object == "trackingobjects":
        url += "/trackingObjects"
    elif object == "actions":
        url += "/actions"
    elif object == "actiontemplates":
        url += "/actionTemplates"
    elif object == "measuretemplates":
        url += "/measureTemplates"
    elif object == "measures":
        url += "/measures"
    elif object == "initiativetemplates":
        url += "/initiativeTemplates"
    elif object == "initiatives":
        url += "/initiatives"
    else:
        raise ValueError

    response = requests.request(
        "GET", url, headers={"Authorization": f"Bearer {token}"}
    )
    response.raise_for_status()

    return response.json()["data"]["payload"]