Debian Codegraph @

src/globus_sdk/experimental/transfer_v2/data/bookmark_documents.py

raw
1 from __future__ import annotations
2
3 import logging
4 import typing as t
5 import uuid
6
7 from globus_sdk._missing import MISSING, MissingType
8 from globus_sdk._payload import GlobusPayload
9
10 log = logging.getLogger(__name__)
11
12
13 class BookmarkCreateDocument(GlobusPayload):
14 """
15 Convenience class for constructing a bookmark document to use as the
16 ``data`` parameter to
17 :meth:`~globus_sdk.TransferClientV2.create_bookmark`.
18 """
19
20 def __init__(
21 self,
22 collection: uuid.UUID | str,
23 name: str,
24 path: str,
25 *,
26 pinned: bool | MissingType = MISSING,
27 additional_fields: dict[str, t.Any] | None = None,
28 ) -> None:
29 super().__init__()
30 log.debug("Creating a new BookmarkCreateDocument object")
31
32 relationships = {
33 "collection": {
34 "data": {
35 "type": "Collection",
36 "id": collection,
37 }
38 }
39 }
40
41 attributes = {
42 "name": name,
43 "path": path,
44 "pinned": pinned,
45 }
46
47 if additional_fields is not None:
48 attributes.update(additional_fields)
49
50 self["data"] = {
51 "type": "Bookmark",
52 "attributes": attributes,
53 "relationships": relationships,
54 }
55
56
57 class BookmarkUpdateDocument(GlobusPayload):
58 """
59 Convenience class for constructing a bookmark document to use as the
60 ``data`` parameter to
61 :meth:`~globus_sdk.TransferClientV2.update_bookmark`.
62 """
63
64 def __init__(
65 self,
66 name: str,
67 path: str,
68 *,
69 pinned: bool | MissingType = MISSING,
70 additional_fields: dict[str, t.Any] | None = None,
71 ) -> None:
72 super().__init__()
73 log.debug("Creating a new BookmarkUpdateDocument")
74
75 attributes = {
76 "name": name,
77 "path": path,
78 "pinned": pinned,
79 }
80
81 if additional_fields is not None:
82 attributes.update(additional_fields)
83
84 self["data"] = {
85 "type": "Bookmark",
86 "attributes": attributes,
87 }