Skip to content

Commit 320b1a4

Browse files
committed
feat: add get, create collection
1 parent c0ed0e1 commit 320b1a4

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

videodb/client.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import (
44
Optional,
55
Union,
6+
List,
67
)
78

89
from videodb._constants import (
@@ -39,6 +40,33 @@ def get_collection(self, collection_id: Optional[str] = "default") -> Collection
3940
collection_data.get("description"),
4041
)
4142

43+
def get_collections(self) -> List[Collection]:
44+
collections_data = self.get(path=ApiPath.collection)
45+
return [
46+
Collection(
47+
self,
48+
collection.get("id"),
49+
collection.get("name"),
50+
collection.get("description"),
51+
)
52+
for collection in collections_data.get("collections")
53+
]
54+
55+
def create_collection(self, name: str, description: str) -> Collection:
56+
collection_data = self.post(
57+
path=ApiPath.collection,
58+
data={
59+
"name": name,
60+
"description": description,
61+
},
62+
)
63+
return Collection(
64+
self,
65+
collection_data.get("id"),
66+
collection_data.get("name"),
67+
collection_data.get("description"),
68+
)
69+
4270
def upload(
4371
self,
4472
file_path: str = None,

videodb/collection.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ def __init__(self, _connection, id: str, name: str = None, description: str = No
2727
self.name = name
2828
self.description = description
2929

30+
def __repr__(self) -> str:
31+
return (
32+
f"Collection("
33+
f"id={self.id}, "
34+
f"name={self.name}, "
35+
f"description={self.description})"
36+
)
37+
3038
def get_videos(self) -> List[Video]:
3139
videos_data = self._connection.get(path=f"{ApiPath.video}")
3240
return [Video(self._connection, **video) for video in videos_data.get("videos")]

0 commit comments

Comments
 (0)