projectal.entities.folder

 1from projectal.entity import Entity
 2from projectal.linkers import *
 3from projectal import api
 4
 5
 6class Folder(Entity, FileLinker, FolderLinker, NoteLinker, TagLinker):
 7    """
 8    Implementation of the [Folder](https://projectal.com/docs/latest/#tag/Folder) API.
 9    """
10
11    _path = "folder"
12    _name = "folder"
13    _links = [FileLinker, FolderLinker, NoteLinker, TagLinker]
14
15    def __init__(self, data):
16        super().__init__(data)
17
18        # TODO: override linker definition here due to differences in list name vs other file linkers.
19        # Remove if/when API is changed to address this.
20        class CustomFile(BaseLinker):
21            _link_name = "file"
22            _link_key = "files"
23
24        self._add_link_def(CustomFile)
25
26    @classmethod
27    def create(cls, entity):
28        payload = entity
29        endpoint = "/api/folder/add"
30        response = api.post(endpoint, payload)
31        entity["uuId"] = response["jobClue"]["uuId"]
32        return cls(entity)
33
34    @classmethod
35    def get(cls, uuId, links=None):
36        """Get the File entity. No file data is included."""
37        link_set = cls._get_linkset(links)
38        url = "/api/folder/get?uuId={}".format(uuId)
39        if link_set:
40            url += "&links=" + ",".join(link_set)
41        return cls(api.get(url))
42
43    @classmethod
44    def update(cls, entity):
45        payload = entity
46        api.put("/api/folder/update", payload)
47        return True
48
49    @classmethod
50    def delete(cls, uuId):
51        api.delete("/api/folder/delete/{}".format(uuId))
52        return True
53
54    @classmethod
55    def list(cls, expand=True):
56        """Return all folders as a list"""
57        folders = api.get("/api/folder/list")
58        return [cls(f) for f in folders]
 7class Folder(Entity, FileLinker, FolderLinker, NoteLinker, TagLinker):
 8    """
 9    Implementation of the [Folder](https://projectal.com/docs/latest/#tag/Folder) API.
10    """
11
12    _path = "folder"
13    _name = "folder"
14    _links = [FileLinker, FolderLinker, NoteLinker, TagLinker]
15
16    def __init__(self, data):
17        super().__init__(data)
18
19        # TODO: override linker definition here due to differences in list name vs other file linkers.
20        # Remove if/when API is changed to address this.
21        class CustomFile(BaseLinker):
22            _link_name = "file"
23            _link_key = "files"
24
25        self._add_link_def(CustomFile)
26
27    @classmethod
28    def create(cls, entity):
29        payload = entity
30        endpoint = "/api/folder/add"
31        response = api.post(endpoint, payload)
32        entity["uuId"] = response["jobClue"]["uuId"]
33        return cls(entity)
34
35    @classmethod
36    def get(cls, uuId, links=None):
37        """Get the File entity. No file data is included."""
38        link_set = cls._get_linkset(links)
39        url = "/api/folder/get?uuId={}".format(uuId)
40        if link_set:
41            url += "&links=" + ",".join(link_set)
42        return cls(api.get(url))
43
44    @classmethod
45    def update(cls, entity):
46        payload = entity
47        api.put("/api/folder/update", payload)
48        return True
49
50    @classmethod
51    def delete(cls, uuId):
52        api.delete("/api/folder/delete/{}".format(uuId))
53        return True
54
55    @classmethod
56    def list(cls, expand=True):
57        """Return all folders as a list"""
58        folders = api.get("/api/folder/list")
59        return [cls(f) for f in folders]

Implementation of the Folder API.

@classmethod
def create(cls, entity):
27    @classmethod
28    def create(cls, entity):
29        payload = entity
30        endpoint = "/api/folder/add"
31        response = api.post(endpoint, payload)
32        entity["uuId"] = response["jobClue"]["uuId"]
33        return cls(entity)

Create one or more entities of the same type. The entity type is determined by the subclass calling this method.

entities: Can be a dict to create a single entity, or a list of dicts to create many entities in bulk.

params: Optional URL parameters that may apply to the entity's API (e.g: ?holder=1234).

'batch_linking': Enabled by default, batches any link updates required into composite API requests. If disabled a request will be executed for each link update. Recommended to leave enabled to increase performance.

If input was a dict, returns an entity subclass. If input was a list of dicts, returns a list of entity subclasses.

# Example usage:
projectal.Customer.create({'name': 'NewCustomer'})
# returns Customer object
@classmethod
def get(cls, uuId, links=None):
35    @classmethod
36    def get(cls, uuId, links=None):
37        """Get the File entity. No file data is included."""
38        link_set = cls._get_linkset(links)
39        url = "/api/folder/get?uuId={}".format(uuId)
40        if link_set:
41            url += "&links=" + ",".join(link_set)
42        return cls(api.get(url))

Get the File entity. No file data is included.

@classmethod
def update(cls, entity):
44    @classmethod
45    def update(cls, entity):
46        payload = entity
47        api.put("/api/folder/update", payload)
48        return True

Save one or more entities of the same type. The entity type is determined by the subclass calling this method. Only the fields that have been modifier will be sent to the server as part of the request.

entities: Can be a dict to update a single entity, or a list of dicts to update many entities in bulk.

'batch_linking': Enabled by default, batches any link updates required into composite API requests. If disabled a request will be executed for each link update. Recommended to leave enabled to increase performance.

Returns True if all entities update successfully.

# Example usage:
rebate = projectal.Rebate.create({'name': 'Rebate2022', 'rebate': 0.2})
rebate['name'] = 'Rebate2024'
projectal.Rebate.update(rebate)
# Returns True. New rebate name has been saved.
@classmethod
def delete(cls, uuId):
50    @classmethod
51    def delete(cls, uuId):
52        api.delete("/api/folder/delete/{}".format(uuId))
53        return True

Delete one or more entities of the same type. The entity type is determined by the subclass calling this method.

entities: See Entity.get() for expected formats.

# Example usage:
ids = ['1b21e445-f29a...', '1b21e445-f29a...', '1b21e445-f29a...']
projectal.Customer.delete(ids)
@classmethod
def list(cls, expand=True):
55    @classmethod
56    def list(cls, expand=True):
57        """Return all folders as a list"""
58        folders = api.get("/api/folder/list")
59        return [cls(f) for f in folders]

Return all folders as a list