semble-api 0.0.1__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.
@@ -0,0 +1,344 @@
1
+ """network.cosmik.card.* — urls and notes in libraries."""
2
+
3
+ from typing import Any
4
+
5
+ from semble._utils import drop_none
6
+ from semble.resources._base import AsyncResource, SyncResource
7
+ from semble.types import (
8
+ AddURLResponse,
9
+ LibraryEntry,
10
+ NoteCard,
11
+ Page,
12
+ SortOrder,
13
+ URLCard,
14
+ URLMetadataResponse,
15
+ URLType,
16
+ )
17
+
18
+
19
+ class Cards(SyncResource):
20
+ def add_url(
21
+ self,
22
+ url: str,
23
+ *,
24
+ note: str | None = None,
25
+ collection_ids: list[str] | None = None,
26
+ via_card_id: str | None = None,
27
+ ) -> AddURLResponse:
28
+ """add a url to your library, optionally with a note and collections."""
29
+ body = drop_none(
30
+ url=url, note=note, collectionIds=collection_ids, viaCardId=via_card_id
31
+ )
32
+ return self._client.post(
33
+ "network.cosmik.card.addUrl", body, cast_to=AddURLResponse
34
+ )
35
+
36
+ def update_url_associations(
37
+ self,
38
+ card_id: str,
39
+ *,
40
+ note: str | None = None,
41
+ via_card_id: str | None = None,
42
+ add_to_collections: list[str] | None = None,
43
+ remove_from_collections: list[str] | None = None,
44
+ ) -> None:
45
+ body = drop_none(
46
+ cardId=card_id,
47
+ note=note,
48
+ viaCardId=via_card_id,
49
+ addToCollections=add_to_collections,
50
+ removeFromCollections=remove_from_collections,
51
+ )
52
+ self._client.post("network.cosmik.card.updateUrlAssociations", body)
53
+
54
+ def list_mine(
55
+ self,
56
+ *,
57
+ page: int | None = None,
58
+ limit: int | None = None,
59
+ sort_by: str | None = None,
60
+ sort_order: SortOrder | None = None,
61
+ url_type: URLType | None = None,
62
+ uncollected: bool | None = None,
63
+ ) -> Page[URLCard]:
64
+ params = drop_none(
65
+ page=page,
66
+ limit=limit,
67
+ sortBy=sort_by,
68
+ sortOrder=sort_order,
69
+ urlType=url_type,
70
+ uncollected=uncollected,
71
+ )
72
+ return self._client.get(
73
+ "network.cosmik.card.listMine", params, cast_to=Page[URLCard]
74
+ )
75
+
76
+ def list_by_user(
77
+ self,
78
+ identifier: str,
79
+ *,
80
+ page: int | None = None,
81
+ limit: int | None = None,
82
+ sort_by: str | None = None,
83
+ sort_order: SortOrder | None = None,
84
+ url_type: URLType | None = None,
85
+ uncollected: bool | None = None,
86
+ ) -> Page[URLCard]:
87
+ params = drop_none(
88
+ identifier=identifier,
89
+ page=page,
90
+ limit=limit,
91
+ sortBy=sort_by,
92
+ sortOrder=sort_order,
93
+ urlType=url_type,
94
+ uncollected=uncollected,
95
+ )
96
+ return self._client.get(
97
+ "network.cosmik.card.listByUser", params, cast_to=Page[URLCard]
98
+ )
99
+
100
+ def search(
101
+ self,
102
+ search_query: str,
103
+ *,
104
+ page: int | None = None,
105
+ limit: int | None = None,
106
+ sort_by: str | None = None,
107
+ sort_order: SortOrder | None = None,
108
+ url_type: URLType | None = None,
109
+ ) -> Page[URLCard]:
110
+ params = drop_none(
111
+ searchQuery=search_query,
112
+ page=page,
113
+ limit=limit,
114
+ sortBy=sort_by,
115
+ sortOrder=sort_order,
116
+ urlType=url_type,
117
+ )
118
+ return self._client.get(
119
+ "network.cosmik.card.search", params, cast_to=Page[URLCard]
120
+ )
121
+
122
+ def get(self, card_id: str) -> URLCard:
123
+ return self._client.get(
124
+ "network.cosmik.card.get", {"cardId": card_id}, cast_to=URLCard
125
+ )
126
+
127
+ def get_url_metadata(
128
+ self, url: str, *, include_stats: bool | None = None
129
+ ) -> URLMetadataResponse:
130
+ params = drop_none(url=url, includeStats=include_stats)
131
+ return self._client.get(
132
+ "network.cosmik.card.getUrlMetadata", params, cast_to=URLMetadataResponse
133
+ )
134
+
135
+ def get_library_status(self, url: str) -> dict[str, Any]:
136
+ return self._client.get("network.cosmik.card.getLibraryStatus", {"url": url})
137
+
138
+ def get_libraries_for_url(
139
+ self,
140
+ url: str,
141
+ *,
142
+ page: int | None = None,
143
+ limit: int | None = None,
144
+ sort_by: str | None = None,
145
+ sort_order: SortOrder | None = None,
146
+ ) -> Page[LibraryEntry]:
147
+ params = drop_none(
148
+ url=url, page=page, limit=limit, sortBy=sort_by, sortOrder=sort_order
149
+ )
150
+ return self._client.get(
151
+ "network.cosmik.card.getLibrariesForUrl", params, cast_to=Page[LibraryEntry]
152
+ )
153
+
154
+ def get_note_cards_for_url(
155
+ self,
156
+ url: str,
157
+ *,
158
+ page: int | None = None,
159
+ limit: int | None = None,
160
+ sort_by: str | None = None,
161
+ sort_order: SortOrder | None = None,
162
+ ) -> Page[NoteCard]:
163
+ params = drop_none(
164
+ url=url, page=page, limit=limit, sortBy=sort_by, sortOrder=sort_order
165
+ )
166
+ return self._client.get(
167
+ "network.cosmik.card.getNoteCardsForUrl", params, cast_to=Page[NoteCard]
168
+ )
169
+
170
+ def update_note(self, card_id: str, note: str) -> None:
171
+ """update a note card's text. `card_id` must be a note card id
172
+ (e.g. `AddURLResponse.note_card_id`), not a url card id."""
173
+ self._client.post(
174
+ "network.cosmik.card.updateNote", {"cardId": card_id, "note": note}
175
+ )
176
+
177
+ def remove_from_library(self, card_id: str) -> None:
178
+ self._client.post("network.cosmik.card.removeFromLibrary", {"cardId": card_id})
179
+
180
+
181
+ class AsyncCards(AsyncResource):
182
+ async def add_url(
183
+ self,
184
+ url: str,
185
+ *,
186
+ note: str | None = None,
187
+ collection_ids: list[str] | None = None,
188
+ via_card_id: str | None = None,
189
+ ) -> AddURLResponse:
190
+ """add a url to your library, optionally with a note and collections."""
191
+ body = drop_none(
192
+ url=url, note=note, collectionIds=collection_ids, viaCardId=via_card_id
193
+ )
194
+ return await self._client.post(
195
+ "network.cosmik.card.addUrl", body, cast_to=AddURLResponse
196
+ )
197
+
198
+ async def update_url_associations(
199
+ self,
200
+ card_id: str,
201
+ *,
202
+ note: str | None = None,
203
+ via_card_id: str | None = None,
204
+ add_to_collections: list[str] | None = None,
205
+ remove_from_collections: list[str] | None = None,
206
+ ) -> None:
207
+ body = drop_none(
208
+ cardId=card_id,
209
+ note=note,
210
+ viaCardId=via_card_id,
211
+ addToCollections=add_to_collections,
212
+ removeFromCollections=remove_from_collections,
213
+ )
214
+ await self._client.post("network.cosmik.card.updateUrlAssociations", body)
215
+
216
+ async def list_mine(
217
+ self,
218
+ *,
219
+ page: int | None = None,
220
+ limit: int | None = None,
221
+ sort_by: str | None = None,
222
+ sort_order: SortOrder | None = None,
223
+ url_type: URLType | None = None,
224
+ uncollected: bool | None = None,
225
+ ) -> Page[URLCard]:
226
+ params = drop_none(
227
+ page=page,
228
+ limit=limit,
229
+ sortBy=sort_by,
230
+ sortOrder=sort_order,
231
+ urlType=url_type,
232
+ uncollected=uncollected,
233
+ )
234
+ return await self._client.get(
235
+ "network.cosmik.card.listMine", params, cast_to=Page[URLCard]
236
+ )
237
+
238
+ async def list_by_user(
239
+ self,
240
+ identifier: str,
241
+ *,
242
+ page: int | None = None,
243
+ limit: int | None = None,
244
+ sort_by: str | None = None,
245
+ sort_order: SortOrder | None = None,
246
+ url_type: URLType | None = None,
247
+ uncollected: bool | None = None,
248
+ ) -> Page[URLCard]:
249
+ params = drop_none(
250
+ identifier=identifier,
251
+ page=page,
252
+ limit=limit,
253
+ sortBy=sort_by,
254
+ sortOrder=sort_order,
255
+ urlType=url_type,
256
+ uncollected=uncollected,
257
+ )
258
+ return await self._client.get(
259
+ "network.cosmik.card.listByUser", params, cast_to=Page[URLCard]
260
+ )
261
+
262
+ async def search(
263
+ self,
264
+ search_query: str,
265
+ *,
266
+ page: int | None = None,
267
+ limit: int | None = None,
268
+ sort_by: str | None = None,
269
+ sort_order: SortOrder | None = None,
270
+ url_type: URLType | None = None,
271
+ ) -> Page[URLCard]:
272
+ params = drop_none(
273
+ searchQuery=search_query,
274
+ page=page,
275
+ limit=limit,
276
+ sortBy=sort_by,
277
+ sortOrder=sort_order,
278
+ urlType=url_type,
279
+ )
280
+ return await self._client.get(
281
+ "network.cosmik.card.search", params, cast_to=Page[URLCard]
282
+ )
283
+
284
+ async def get(self, card_id: str) -> URLCard:
285
+ return await self._client.get(
286
+ "network.cosmik.card.get", {"cardId": card_id}, cast_to=URLCard
287
+ )
288
+
289
+ async def get_url_metadata(
290
+ self, url: str, *, include_stats: bool | None = None
291
+ ) -> URLMetadataResponse:
292
+ params = drop_none(url=url, includeStats=include_stats)
293
+ return await self._client.get(
294
+ "network.cosmik.card.getUrlMetadata", params, cast_to=URLMetadataResponse
295
+ )
296
+
297
+ async def get_library_status(self, url: str) -> dict[str, Any]:
298
+ return await self._client.get(
299
+ "network.cosmik.card.getLibraryStatus", {"url": url}
300
+ )
301
+
302
+ async def get_libraries_for_url(
303
+ self,
304
+ url: str,
305
+ *,
306
+ page: int | None = None,
307
+ limit: int | None = None,
308
+ sort_by: str | None = None,
309
+ sort_order: SortOrder | None = None,
310
+ ) -> Page[LibraryEntry]:
311
+ params = drop_none(
312
+ url=url, page=page, limit=limit, sortBy=sort_by, sortOrder=sort_order
313
+ )
314
+ return await self._client.get(
315
+ "network.cosmik.card.getLibrariesForUrl", params, cast_to=Page[LibraryEntry]
316
+ )
317
+
318
+ async def get_note_cards_for_url(
319
+ self,
320
+ url: str,
321
+ *,
322
+ page: int | None = None,
323
+ limit: int | None = None,
324
+ sort_by: str | None = None,
325
+ sort_order: SortOrder | None = None,
326
+ ) -> Page[NoteCard]:
327
+ params = drop_none(
328
+ url=url, page=page, limit=limit, sortBy=sort_by, sortOrder=sort_order
329
+ )
330
+ return await self._client.get(
331
+ "network.cosmik.card.getNoteCardsForUrl", params, cast_to=Page[NoteCard]
332
+ )
333
+
334
+ async def update_note(self, card_id: str, note: str) -> None:
335
+ """update a note card's text. `card_id` must be a note card id
336
+ (e.g. `AddURLResponse.note_card_id`), not a url card id."""
337
+ await self._client.post(
338
+ "network.cosmik.card.updateNote", {"cardId": card_id, "note": note}
339
+ )
340
+
341
+ async def remove_from_library(self, card_id: str) -> None:
342
+ await self._client.post(
343
+ "network.cosmik.card.removeFromLibrary", {"cardId": card_id}
344
+ )