aisberg 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,117 +0,0 @@
1
- from typing import List
2
- from abc import ABC
3
-
4
- from ..models.document import GroupDocument, Collection, CollectionDetails
5
-
6
- from abc import abstractmethod
7
- from ..abstract.modules import SyncModule, AsyncModule
8
- from ..api import endpoints, async_endpoints
9
-
10
-
11
- class AbstractDocumentModule(ABC):
12
- def __init__(self, parent, client):
13
- self._parent = parent
14
- self._client = client
15
-
16
- @abstractmethod
17
- def list(self) -> List[GroupDocument]:
18
- """
19
- Get a list of available collections. Document are grouped by your belonging groups.
20
-
21
- Returns:
22
- List[GroupDocument]: A list of available collections.
23
-
24
- Raises:
25
- ValueError: If no collections are found.
26
- Exception: If there is an error fetching the collections.
27
- """
28
- pass
29
-
30
- @abstractmethod
31
- def get_by_group(self, group_id: str) -> List[Collection]:
32
- """
33
- Get collections by group ID.
34
-
35
- Args:
36
- group_id (str): The ID of the group for which to retrieve collections.
37
-
38
- Returns:
39
- List[Collection]: A list of collections for the specified group.
40
-
41
- Raises:
42
- ValueError: If no collections are found for the specified group ID.
43
- Exception: If there is an error fetching the collections.
44
- """
45
- pass
46
-
47
- @abstractmethod
48
- def details(self, collection_id: str, group_id: str) -> CollectionDetails:
49
- """
50
- Get details of a specific collection.
51
-
52
- Args:
53
- collection_id (str): The ID of the collection to retrieve.
54
- group_id (str): The ID of the group to which the collection belongs.
55
-
56
- Returns:
57
- CollectionDetails: The details of the specified collection.
58
-
59
- Raises:
60
- ValueError: If the specified collection is not found.
61
- """
62
- pass
63
-
64
- @staticmethod
65
- def _get_collections_by_group(
66
- collections: List[GroupDocument], group_id: str
67
- ) -> List[Collection]:
68
- for group in collections:
69
- if group.group == group_id:
70
- return group.collections
71
- raise ValueError("No collections found for group ID")
72
-
73
-
74
- class SyncDocumentModule(SyncModule, AbstractDocumentModule):
75
- def __init__(self, parent, client):
76
- SyncModule.__init__(self, parent, client)
77
- AbstractDocumentModule.__init__(self, parent, client)
78
-
79
- def list(self) -> List[GroupDocument]:
80
- return endpoints.collections(self._client)
81
-
82
- def get_by_group(self, group_id: str) -> List[Collection]:
83
- collections = self.list()
84
- return self._get_collections_by_group(collections, group_id)
85
-
86
- def details(self, collection_id: str, group_id: str) -> CollectionDetails:
87
- points = endpoints.collection(self._client, collection_id, group_id)
88
- if points is None:
89
- raise ValueError("No collection found")
90
- return CollectionDetails(
91
- name=collection_id,
92
- group=group_id,
93
- points=points,
94
- )
95
-
96
-
97
- class AsyncDocumentModule(AsyncModule, AbstractDocumentModule):
98
- def __init__(self, parent, client):
99
- AsyncModule.__init__(self, parent, client)
100
- AbstractDocumentModule.__init__(self, parent, client)
101
-
102
- async def list(self) -> List[GroupDocument]:
103
- return await async_endpoints.collections(self._client)
104
-
105
- async def get_by_group(self, group_id: str) -> List[Collection]:
106
- collections = await self.list()
107
- return self._get_collections_by_group(collections, group_id)
108
-
109
- async def details(self, collection_id: str, group_id: str) -> CollectionDetails:
110
- points = await async_endpoints.collection(self._client, collection_id, group_id)
111
- if points is None:
112
- raise ValueError("No collection found")
113
- return CollectionDetails(
114
- name=collection_id,
115
- group=group_id,
116
- points=points,
117
- )