-
Notifications
You must be signed in to change notification settings - Fork 221
Expand file tree
/
Copy pathhub_document.py
More file actions
187 lines (155 loc) · 7.13 KB
/
hub_document.py
File metadata and controls
187 lines (155 loc) · 7.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
from typing import Optional
from typing import Dict
from box_sdk_gen.internal.utils import to_string
from box_sdk_gen.serialization.json import deserialize
from box_sdk_gen.networking.fetch_options import ResponseFormat
from box_sdk_gen.schemas.v2025_r0.hub_document_pages_v2025_r0 import (
HubDocumentPagesV2025R0,
)
from box_sdk_gen.schemas.v2025_r0.client_error_v2025_r0 import ClientErrorV2025R0
from box_sdk_gen.parameters.v2025_r0.box_version_header_v2025_r0 import (
BoxVersionHeaderV2025R0,
)
from box_sdk_gen.schemas.v2025_r0.hub_document_blocks_v2025_r0 import (
HubDocumentBlocksV2025R0,
)
from box_sdk_gen.box.errors import BoxSDKError
from box_sdk_gen.networking.auth import Authentication
from box_sdk_gen.networking.network import NetworkSession
from box_sdk_gen.networking.fetch_options import FetchOptions
from box_sdk_gen.networking.fetch_response import FetchResponse
from box_sdk_gen.internal.utils import prepare_params
from box_sdk_gen.internal.utils import to_string
from box_sdk_gen.internal.utils import ByteStream
from box_sdk_gen.serialization.json import sd_to_json
from box_sdk_gen.serialization.json import SerializedData
class HubDocumentManager:
def __init__(
self,
*,
auth: Optional[Authentication] = None,
network_session: NetworkSession = None
):
if network_session is None:
network_session = NetworkSession()
self.auth = auth
self.network_session = network_session
def get_hub_document_pages_v2025_r0(
self,
hub_id: str,
*,
marker: Optional[str] = None,
limit: Optional[int] = None,
box_version: BoxVersionHeaderV2025R0 = BoxVersionHeaderV2025R0._2025_0,
extra_headers: Optional[Dict[str, Optional[str]]] = None
) -> HubDocumentPagesV2025R0:
"""
Retrieves a list of Hub Document Pages for the specified hub.
Includes both root-level pages and sub pages.
:param hub_id: The unique identifier that represent a hub.
The ID for any hub can be determined
by visiting this hub in the web application
and copying the ID from the URL. For example,
for the URL `https://*.app.box.com/hubs/123`
the `hub_id` is `123`.
:type hub_id: str
:param marker: Defines the position marker at which to begin returning results. This is
used when paginating using marker-based pagination., defaults to None
:type marker: Optional[str], optional
:param limit: The maximum number of items to return per page., defaults to None
:type limit: Optional[int], optional
:param box_version: Version header., defaults to BoxVersionHeaderV2025R0._2025_0
:type box_version: BoxVersionHeaderV2025R0, optional
:param extra_headers: Extra headers that will be included in the HTTP request., defaults to None
:type extra_headers: Optional[Dict[str, Optional[str]]], optional
"""
if extra_headers is None:
extra_headers = {}
query_params_map: Dict[str, str] = prepare_params(
{
'hub_id': to_string(hub_id),
'marker': to_string(marker),
'limit': to_string(limit),
}
)
headers_map: Dict[str, str] = prepare_params(
{'box-version': to_string(box_version), **extra_headers}
)
response: FetchResponse = self.network_session.network_client.fetch(
FetchOptions(
url=''.join(
[self.network_session.base_urls.base_url, '/2.0/hub_document_pages']
),
method='GET',
params=query_params_map,
headers=headers_map,
response_format=ResponseFormat.JSON,
auth=self.auth,
network_session=self.network_session,
)
)
return deserialize(response.data, HubDocumentPagesV2025R0)
def get_hub_document_blocks_v2025_r0(
self,
hub_id: str,
page_id: str,
*,
marker: Optional[str] = None,
limit: Optional[int] = None,
box_version: BoxVersionHeaderV2025R0 = BoxVersionHeaderV2025R0._2025_0,
extra_headers: Optional[Dict[str, Optional[str]]] = None
) -> HubDocumentBlocksV2025R0:
"""
Retrieves a sorted list of all Hub Document Blocks on a specified page in the hub document, excluding items.
Blocks are hierarchically organized by their `parent_id`.
Blocks are sorted in order based on user specification in the user interface.
The response will only include content blocks that belong to the specified page. This will not include sub pages or sub page content blocks.
:param hub_id: The unique identifier that represent a hub.
The ID for any hub can be determined
by visiting this hub in the web application
and copying the ID from the URL. For example,
for the URL `https://*.app.box.com/hubs/123`
the `hub_id` is `123`.
:type hub_id: str
:param page_id: The unique identifier of a page within the Box Hub.
:type page_id: str
:param marker: Defines the position marker at which to begin returning results. This is
used when paginating using marker-based pagination., defaults to None
:type marker: Optional[str], optional
:param limit: The maximum number of items to return per page., defaults to None
:type limit: Optional[int], optional
:param box_version: Version header., defaults to BoxVersionHeaderV2025R0._2025_0
:type box_version: BoxVersionHeaderV2025R0, optional
:param extra_headers: Extra headers that will be included in the HTTP request., defaults to None
:type extra_headers: Optional[Dict[str, Optional[str]]], optional
"""
if extra_headers is None:
extra_headers = {}
query_params_map: Dict[str, str] = prepare_params(
{
'hub_id': to_string(hub_id),
'page_id': to_string(page_id),
'marker': to_string(marker),
'limit': to_string(limit),
}
)
headers_map: Dict[str, str] = prepare_params(
{'box-version': to_string(box_version), **extra_headers}
)
response: FetchResponse = self.network_session.network_client.fetch(
FetchOptions(
url=''.join(
[
self.network_session.base_urls.base_url,
'/2.0/hub_document_blocks',
]
),
method='GET',
params=query_params_map,
headers=headers_map,
response_format=ResponseFormat.JSON,
auth=self.auth,
network_session=self.network_session,
)
)
return deserialize(response.data, HubDocumentBlocksV2025R0)