projectal.profile API documentation

# projectal.profile

Projectal profiles serve as an all-purpose key-value store for clients to store any kind of data that interests them, targeting a specific entity uuId (similar to metadata in other systems).

Writes always override the old dictionary entirely, so be sure to always include the whole data instead of updating only the values you have changed.

Notes on implementation: Each profile has its own uuId. The profile API allows you to create an unlimited list of profiles for the key combination; this library abstracts away that concept and enforces only a single dictionary with get/set functions for that key combination. This assumption may not hold if that key combination is modified externally.

View Source

     1"""
     2Projectal profiles serve as an all-purpose key-value store for clients
     3to store any kind of data that interests them, targeting a specific
     4entity uuId (similar to metadata in other systems).
     5
     6Writes always override the old dictionary entirely, so be sure to
     7always include the whole data instead of updating only the values
     8you have changed.
     9
    10Notes on implementation:
    11Each profile has its own uuId. The profile API allows you to create
    12an unlimited list of profiles for the key combination; this library
    13abstracts away that concept and enforces only a single dictionary
    14with get/set functions for that key combination. This assumption
    15may not hold if that key combination is modified externally.
    16"""
    17
    18from projectal import api
    19
    20
    21def get(category_key, folder_key, uuId):
    22    profiles = __profile_list(category_key, folder_key, uuId)
    23    if len(profiles) > 0:
    24        return profiles[0]
    25    else:
    26        # Create on first access (new profile has a uuId)
    27        profile = {}
    28        response = __profile_add(category_key, folder_key, uuId, {})
    29        profile["uuId"] = response[0]["uuId"]
    30        return profile
    31
    32
    33def set(category_key, folder_key, uuId, payload):
    34    # Get the first profile and save to it. If one doesn't exist, create it.
    35    profiles = __profile_list(category_key, folder_key, uuId)
    36    if len(profiles) > 0:
    37        payload["uuId"] = profiles[0]["uuId"]
    38        return __profile_update(category_key, folder_key, uuId, payload)
    39
    40    # Create and add in one step
    41    response = __profile_add(category_key, folder_key, uuId, payload)
    42    payload["uuId"] = response[0]["uuId"]
    43    return payload
    44
    45
    46def __profile_add(category_key, folder_key, uuId, payload):
    47    endpoint = "/api/profile/{}/{}/{}/add".format(category_key, folder_key, uuId)
    48    return api.__request("post", endpoint, [payload])
    49
    50
    51def __profile_delete(category_key, folder_key, uuId):
    52    endpoint = "/api/profile/{}/{}/{}/delete".format(category_key, folder_key, uuId)
    53    return api.__request("post", endpoint)
    54
    55
    56def __profile_update(category_key, folder_key, uuId, payload):
    57    endpoint = "/api/profile/{}/{}/{}/update".format(category_key, folder_key, uuId)
    58    return api.__request("put", endpoint, [payload])
    59
    60
    61def __profile_list(category_key, folder_key, uuId):
    62    endpoint = "/api/profile/{}/{}/{}/list".format(category_key, folder_key, uuId)
    63    return api.__request("get", endpoint)

def get(category_key, folder_key, uuId): View Source

    22def get(category_key, folder_key, uuId):
    23    profiles = __profile_list(category_key, folder_key, uuId)
    24    if len(profiles) > 0:
    25        return profiles[0]
    26    else:
    27        # Create on first access (new profile has a uuId)
    28        profile = {}
    29        response = __profile_add(category_key, folder_key, uuId, {})
    30        profile["uuId"] = response[0]["uuId"]
    31        return profile

def set(category_key, folder_key, uuId, payload): View Source

    34def set(category_key, folder_key, uuId, payload):
    35    # Get the first profile and save to it. If one doesn't exist, create it.
    36    profiles = __profile_list(category_key, folder_key, uuId)
    37    if len(profiles) > 0:
    38        payload["uuId"] = profiles[0]["uuId"]
    39        return __profile_update(category_key, folder_key, uuId, payload)
    40
    41    # Create and add in one step
    42    response = __profile_add(category_key, folder_key, uuId, payload)
    43    payload["uuId"] = response[0]["uuId"]
    44    return payload