Skip to content

Commit f346676

Browse files
feat(boxsdkgen): Support Hub Document API (box/box-codegen#930) (#1372)
1 parent 213960d commit f346676

18 files changed

Lines changed: 757 additions & 1 deletion

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "02fdae4", "specHash": "c8e3a85", "version": "4.5.0" }
1+
{ "engineHash": "e77f966", "specHash": "c8e3a85", "version": "4.5.0" }

box_sdk_gen/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@
184184

185185
from box_sdk_gen.managers.hub_items import HubItemsManager
186186

187+
from box_sdk_gen.managers.hub_document import HubDocumentManager
188+
187189
from box_sdk_gen.managers.shield_lists import ShieldListsManager
188190

189191
from box_sdk_gen.managers.archives import ArchivesManager
@@ -450,6 +452,9 @@ def __init__(self, auth: Authentication, *, network_session: NetworkSession = No
450452
self.hub_items = HubItemsManager(
451453
auth=self.auth, network_session=self.network_session
452454
)
455+
self.hub_document = HubDocumentManager(
456+
auth=self.auth, network_session=self.network_session
457+
)
453458
self.shield_lists = ShieldListsManager(
454459
auth=self.auth, network_session=self.network_session
455460
)

box_sdk_gen/managers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@
156156

157157
from box_sdk_gen.managers.hub_items import *
158158

159+
from box_sdk_gen.managers.hub_document import *
160+
159161
from box_sdk_gen.managers.shield_lists import *
160162

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

box_sdk_gen/schemas/v2025_r0/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@
7070

7171
from box_sdk_gen.schemas.v2025_r0.hub_create_request_v2025_r0 import *
7272

73+
from box_sdk_gen.schemas.v2025_r0.hub_document_block_v2025_r0 import *
74+
75+
from box_sdk_gen.schemas.v2025_r0.hub_section_title_text_block_v2025_r0 import *
76+
77+
from box_sdk_gen.schemas.v2025_r0.hub_paragraph_text_block_v2025_r0 import *
78+
79+
from box_sdk_gen.schemas.v2025_r0.hub_item_list_block_v2025_r0 import *
80+
81+
from box_sdk_gen.schemas.v2025_r0.hub_divider_block_v2025_r0 import *
82+
83+
from box_sdk_gen.schemas.v2025_r0.hub_callout_box_text_block_v2025_r0 import *
84+
85+
from box_sdk_gen.schemas.v2025_r0.hub_document_block_entry_v2025_r0 import *
86+
87+
from box_sdk_gen.schemas.v2025_r0.hub_document_blocks_v2025_r0 import *
88+
89+
from box_sdk_gen.schemas.v2025_r0.hub_document_page_v2025_r0 import *
90+
91+
from box_sdk_gen.schemas.v2025_r0.hub_document_pages_v2025_r0 import *
92+
7393
from box_sdk_gen.schemas.v2025_r0.hub_item_v2025_r0 import *
7494

7595
from box_sdk_gen.schemas.v2025_r0.hub_items_v2025_r0 import *
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from enum import Enum
2+
3+
from typing import Optional
4+
5+
from box_sdk_gen.schemas.v2025_r0.hub_document_block_v2025_r0 import (
6+
HubDocumentBlockV2025R0,
7+
)
8+
9+
from box_sdk_gen.box.errors import BoxSDKError
10+
11+
12+
class HubCalloutBoxTextBlockV2025R0TypeField(str, Enum):
13+
CALLOUT_BOX = 'callout_box'
14+
15+
16+
class HubCalloutBoxTextBlockV2025R0(HubDocumentBlockV2025R0):
17+
_discriminator = 'type', {'callout_box'}
18+
19+
def __init__(
20+
self,
21+
fragment: str,
22+
id: str,
23+
*,
24+
type: HubCalloutBoxTextBlockV2025R0TypeField = HubCalloutBoxTextBlockV2025R0TypeField.CALLOUT_BOX,
25+
parent_id: Optional[str] = None,
26+
**kwargs
27+
):
28+
"""
29+
:param fragment: Text content of the block. Includes rich text formatting.
30+
:type fragment: str
31+
:param id: The unique identifier for this block.
32+
:type id: str
33+
:param type: The type of this block. The value is always `callout_box`., defaults to HubCalloutBoxTextBlockV2025R0TypeField.CALLOUT_BOX
34+
:type type: HubCalloutBoxTextBlockV2025R0TypeField, optional
35+
:param parent_id: The unique identifier of the parent block. Null for direct children of the page., defaults to None
36+
:type parent_id: Optional[str], optional
37+
"""
38+
super().__init__(id=id, parent_id=parent_id, **kwargs)
39+
self.fragment = fragment
40+
self.type = type
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from enum import Enum
2+
3+
from typing import Optional
4+
5+
from box_sdk_gen.schemas.v2025_r0.hub_document_block_v2025_r0 import (
6+
HubDocumentBlockV2025R0,
7+
)
8+
9+
from box_sdk_gen.box.errors import BoxSDKError
10+
11+
12+
class HubDividerBlockV2025R0TypeField(str, Enum):
13+
DIVIDER = 'divider'
14+
15+
16+
class HubDividerBlockV2025R0(HubDocumentBlockV2025R0):
17+
_discriminator = 'type', {'divider'}
18+
19+
def __init__(
20+
self,
21+
id: str,
22+
*,
23+
type: HubDividerBlockV2025R0TypeField = HubDividerBlockV2025R0TypeField.DIVIDER,
24+
parent_id: Optional[str] = None,
25+
**kwargs
26+
):
27+
"""
28+
:param id: The unique identifier for this block.
29+
:type id: str
30+
:param type: The type of this block. The value is always `divider`., defaults to HubDividerBlockV2025R0TypeField.DIVIDER
31+
:type type: HubDividerBlockV2025R0TypeField, optional
32+
:param parent_id: The unique identifier of the parent block. Null for direct children of the page., defaults to None
33+
:type parent_id: Optional[str], optional
34+
"""
35+
super().__init__(id=id, parent_id=parent_id, **kwargs)
36+
self.type = type
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from typing import Union
2+
3+
from box_sdk_gen.schemas.v2025_r0.hub_paragraph_text_block_v2025_r0 import (
4+
HubParagraphTextBlockV2025R0,
5+
)
6+
7+
from box_sdk_gen.schemas.v2025_r0.hub_section_title_text_block_v2025_r0 import (
8+
HubSectionTitleTextBlockV2025R0,
9+
)
10+
11+
from box_sdk_gen.schemas.v2025_r0.hub_callout_box_text_block_v2025_r0 import (
12+
HubCalloutBoxTextBlockV2025R0,
13+
)
14+
15+
from box_sdk_gen.schemas.v2025_r0.hub_item_list_block_v2025_r0 import (
16+
HubItemListBlockV2025R0,
17+
)
18+
19+
from box_sdk_gen.schemas.v2025_r0.hub_divider_block_v2025_r0 import (
20+
HubDividerBlockV2025R0,
21+
)
22+
23+
from box_sdk_gen.box.errors import BoxSDKError
24+
25+
HubDocumentBlockEntryV2025R0 = Union[
26+
HubParagraphTextBlockV2025R0,
27+
HubSectionTitleTextBlockV2025R0,
28+
HubCalloutBoxTextBlockV2025R0,
29+
HubItemListBlockV2025R0,
30+
HubDividerBlockV2025R0,
31+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from typing import Optional
2+
3+
from box_sdk_gen.internal.base_object import BaseObject
4+
5+
from box_sdk_gen.box.errors import BoxSDKError
6+
7+
8+
class HubDocumentBlockV2025R0(BaseObject):
9+
def __init__(self, id: str, *, parent_id: Optional[str] = None, **kwargs):
10+
"""
11+
:param id: The unique identifier for this block.
12+
:type id: str
13+
:param parent_id: The unique identifier of the parent block. Null for direct children of the page., defaults to None
14+
:type parent_id: Optional[str], optional
15+
"""
16+
super().__init__(**kwargs)
17+
self.id = id
18+
self.parent_id = parent_id

0 commit comments

Comments
 (0)