Skip to content

Commit e176bef

Browse files
feat: Support Hub Document API (box/box-codegen#930) (#1443)
1 parent 4c35f6f commit e176bef

28 files changed

+1519
-1
lines changed

.codegen.json

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

BoxSdkGen/BoxSdkGen.xcodeproj/project.pbxproj

Lines changed: 372 additions & 0 deletions
Large diffs are not rendered by default.

BoxSdkGen/Sources/Client/BoxClient.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ public class BoxClient {
163163

164164
public let hubItems: HubItemsManager
165165

166+
public let hubDocument: HubDocumentManager
167+
166168
public let shieldLists: ShieldListsManager
167169

168170
public let archives: ArchivesManager
@@ -251,6 +253,7 @@ public class BoxClient {
251253
self.hubs = HubsManager(auth: self.auth, networkSession: self.networkSession)
252254
self.hubCollaborations = HubCollaborationsManager(auth: self.auth, networkSession: self.networkSession)
253255
self.hubItems = HubItemsManager(auth: self.auth, networkSession: self.networkSession)
256+
self.hubDocument = HubDocumentManager(auth: self.auth, networkSession: self.networkSession)
254257
self.shieldLists = ShieldListsManager(auth: self.auth, networkSession: self.networkSession)
255258
self.archives = ArchivesManager(auth: self.auth, networkSession: self.networkSession)
256259
self.externalUsers = ExternalUsersManager(auth: self.auth, networkSession: self.networkSession)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Foundation
2+
3+
public class GetHubDocumentBlocksV2025R0Headers {
4+
/// Version header.
5+
public let boxVersion: BoxVersionHeaderV2025R0
6+
7+
/// Extra headers that will be included in the HTTP request.
8+
public let extraHeaders: [String: String?]?
9+
10+
/// Initializer for a GetHubDocumentBlocksV2025R0Headers.
11+
///
12+
/// - Parameters:
13+
/// - boxVersion: Version header.
14+
/// - extraHeaders: Extra headers that will be included in the HTTP request.
15+
public init(boxVersion: BoxVersionHeaderV2025R0 = BoxVersionHeaderV2025R0._20250, extraHeaders: [String: String?]? = [:]) {
16+
self.boxVersion = boxVersion
17+
self.extraHeaders = extraHeaders
18+
}
19+
20+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import Foundation
2+
3+
public class GetHubDocumentBlocksV2025R0QueryParams {
4+
/// The unique identifier that represent a hub.
5+
///
6+
/// The ID for any hub can be determined
7+
/// by visiting this hub in the web application
8+
/// and copying the ID from the URL. For example,
9+
/// for the URL `https://*.app.box.com/hubs/123`
10+
/// the `hub_id` is `123`.
11+
public let hubId: String
12+
13+
/// The unique identifier of a page within the Box Hub.
14+
public let pageId: String
15+
16+
/// Defines the position marker at which to begin returning results. This is
17+
/// used when paginating using marker-based pagination.
18+
public let marker: String?
19+
20+
/// The maximum number of items to return per page.
21+
public let limit: Int64?
22+
23+
/// Initializer for a GetHubDocumentBlocksV2025R0QueryParams.
24+
///
25+
/// - Parameters:
26+
/// - hubId: The unique identifier that represent a hub.
27+
///
28+
/// The ID for any hub can be determined
29+
/// by visiting this hub in the web application
30+
/// and copying the ID from the URL. For example,
31+
/// for the URL `https://*.app.box.com/hubs/123`
32+
/// the `hub_id` is `123`.
33+
/// - pageId: The unique identifier of a page within the Box Hub.
34+
/// - marker: Defines the position marker at which to begin returning results. This is
35+
/// used when paginating using marker-based pagination.
36+
/// - limit: The maximum number of items to return per page.
37+
public init(hubId: String, pageId: String, marker: String? = nil, limit: Int64? = nil) {
38+
self.hubId = hubId
39+
self.pageId = pageId
40+
self.marker = marker
41+
self.limit = limit
42+
}
43+
44+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Foundation
2+
3+
public class GetHubDocumentPagesV2025R0Headers {
4+
/// Version header.
5+
public let boxVersion: BoxVersionHeaderV2025R0
6+
7+
/// Extra headers that will be included in the HTTP request.
8+
public let extraHeaders: [String: String?]?
9+
10+
/// Initializer for a GetHubDocumentPagesV2025R0Headers.
11+
///
12+
/// - Parameters:
13+
/// - boxVersion: Version header.
14+
/// - extraHeaders: Extra headers that will be included in the HTTP request.
15+
public init(boxVersion: BoxVersionHeaderV2025R0 = BoxVersionHeaderV2025R0._20250, extraHeaders: [String: String?]? = [:]) {
16+
self.boxVersion = boxVersion
17+
self.extraHeaders = extraHeaders
18+
}
19+
20+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import Foundation
2+
3+
public class GetHubDocumentPagesV2025R0QueryParams {
4+
/// The unique identifier that represent a hub.
5+
///
6+
/// The ID for any hub can be determined
7+
/// by visiting this hub in the web application
8+
/// and copying the ID from the URL. For example,
9+
/// for the URL `https://*.app.box.com/hubs/123`
10+
/// the `hub_id` is `123`.
11+
public let hubId: String
12+
13+
/// Defines the position marker at which to begin returning results. This is
14+
/// used when paginating using marker-based pagination.
15+
public let marker: String?
16+
17+
/// The maximum number of items to return per page.
18+
public let limit: Int64?
19+
20+
/// Initializer for a GetHubDocumentPagesV2025R0QueryParams.
21+
///
22+
/// - Parameters:
23+
/// - hubId: The unique identifier that represent a hub.
24+
///
25+
/// The ID for any hub can be determined
26+
/// by visiting this hub in the web application
27+
/// and copying the ID from the URL. For example,
28+
/// for the URL `https://*.app.box.com/hubs/123`
29+
/// the `hub_id` is `123`.
30+
/// - marker: Defines the position marker at which to begin returning results. This is
31+
/// used when paginating using marker-based pagination.
32+
/// - limit: The maximum number of items to return per page.
33+
public init(hubId: String, marker: String? = nil, limit: Int64? = nil) {
34+
self.hubId = hubId
35+
self.marker = marker
36+
self.limit = limit
37+
}
38+
39+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import Foundation
2+
3+
public class HubDocumentManager {
4+
public let auth: Authentication?
5+
6+
public let networkSession: NetworkSession
7+
8+
public init(auth: Authentication? = nil, networkSession: NetworkSession = NetworkSession()) {
9+
self.auth = auth
10+
self.networkSession = networkSession
11+
}
12+
13+
/// Retrieves a list of Hub Document Pages for the specified hub.
14+
/// Includes both root-level pages and sub pages.
15+
///
16+
/// - Parameters:
17+
/// - queryParams: Query parameters of getHubDocumentPagesV2025R0 method
18+
/// - headers: Headers of getHubDocumentPagesV2025R0 method
19+
/// - Returns: The `HubDocumentPagesV2025R0`.
20+
/// - Throws: The `GeneralError`.
21+
public func getHubDocumentPagesV2025R0(queryParams: GetHubDocumentPagesV2025R0QueryParams, headers: GetHubDocumentPagesV2025R0Headers = GetHubDocumentPagesV2025R0Headers()) async throws -> HubDocumentPagesV2025R0 {
22+
let queryParamsMap: [String: String] = Utils.Dictionary.prepareParams(map: ["hub_id": Utils.Strings.toString(value: queryParams.hubId), "marker": Utils.Strings.toString(value: queryParams.marker), "limit": Utils.Strings.toString(value: queryParams.limit)])
23+
let headersMap: [String: String] = Utils.Dictionary.prepareParams(map: Utils.Dictionary.merge(["box-version": Utils.Strings.toString(value: headers.boxVersion)], headers.extraHeaders))
24+
let response: FetchResponse = try await self.networkSession.networkClient.fetch(options: FetchOptions(url: "\(self.networkSession.baseUrls.baseUrl)\("/2.0/hub_document_pages")", method: "GET", params: queryParamsMap, headers: headersMap, responseFormat: ResponseFormat.json, auth: self.auth, networkSession: self.networkSession))
25+
return try HubDocumentPagesV2025R0.deserialize(from: response.data!)
26+
}
27+
28+
/// Retrieves a sorted list of all Hub Document Blocks on a specified page in the hub document, excluding items.
29+
/// Blocks are hierarchically organized by their `parent_id`.
30+
/// Blocks are sorted in order based on user specification in the user interface.
31+
/// The response will only include content blocks that belong to the specified page. This will not include sub pages or sub page content blocks.
32+
///
33+
/// - Parameters:
34+
/// - queryParams: Query parameters of getHubDocumentBlocksV2025R0 method
35+
/// - headers: Headers of getHubDocumentBlocksV2025R0 method
36+
/// - Returns: The `HubDocumentBlocksV2025R0`.
37+
/// - Throws: The `GeneralError`.
38+
public func getHubDocumentBlocksV2025R0(queryParams: GetHubDocumentBlocksV2025R0QueryParams, headers: GetHubDocumentBlocksV2025R0Headers = GetHubDocumentBlocksV2025R0Headers()) async throws -> HubDocumentBlocksV2025R0 {
39+
let queryParamsMap: [String: String] = Utils.Dictionary.prepareParams(map: ["hub_id": Utils.Strings.toString(value: queryParams.hubId), "page_id": Utils.Strings.toString(value: queryParams.pageId), "marker": Utils.Strings.toString(value: queryParams.marker), "limit": Utils.Strings.toString(value: queryParams.limit)])
40+
let headersMap: [String: String] = Utils.Dictionary.prepareParams(map: Utils.Dictionary.merge(["box-version": Utils.Strings.toString(value: headers.boxVersion)], headers.extraHeaders))
41+
let response: FetchResponse = try await self.networkSession.networkClient.fetch(options: FetchOptions(url: "\(self.networkSession.baseUrls.baseUrl)\("/2.0/hub_document_blocks")", method: "GET", params: queryParamsMap, headers: headersMap, responseFormat: ResponseFormat.json, auth: self.auth, networkSession: self.networkSession))
42+
return try HubDocumentBlocksV2025R0.deserialize(from: response.data!)
43+
}
44+
45+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import Foundation
2+
3+
/// A callout box block in the Box Hub Document.
4+
public class HubCalloutBoxTextBlockV2025R0: HubDocumentBlockV2025R0 {
5+
private enum CodingKeys: String, CodingKey {
6+
case fragment
7+
case type
8+
}
9+
10+
/// Internal backing store for rawData. Used to store raw dictionary data associated with the instance.
11+
private var _rawData: [String: Any]?
12+
13+
/// Returns the raw dictionary data associated with the instance. This is a read-only property.
14+
public override var rawData: [String: Any]? {
15+
return _rawData
16+
}
17+
18+
19+
/// Text content of the block. Includes rich text formatting.
20+
public let fragment: String
21+
22+
/// The type of this block. The value is always `callout_box`.
23+
public let type: HubCalloutBoxTextBlockV2025R0TypeField
24+
25+
/// Initializer for a HubCalloutBoxTextBlockV2025R0.
26+
///
27+
/// - Parameters:
28+
/// - id: The unique identifier for this block.
29+
/// - fragment: Text content of the block. Includes rich text formatting.
30+
/// - parentId: The unique identifier of the parent block. Null for direct children of the page.
31+
/// - type: The type of this block. The value is always `callout_box`.
32+
public init(id: String, fragment: String, parentId: TriStateField<String> = nil, type: HubCalloutBoxTextBlockV2025R0TypeField = HubCalloutBoxTextBlockV2025R0TypeField.calloutBox) {
33+
self.fragment = fragment
34+
self.type = type
35+
36+
super.init(id: id, parentId: parentId)
37+
}
38+
39+
required public init(from decoder: Decoder) throws {
40+
let container = try decoder.container(keyedBy: CodingKeys.self)
41+
fragment = try container.decode(String.self, forKey: .fragment)
42+
type = try container.decode(HubCalloutBoxTextBlockV2025R0TypeField.self, forKey: .type)
43+
44+
try super.init(from: decoder)
45+
}
46+
47+
public override func encode(to encoder: Encoder) throws {
48+
var container = encoder.container(keyedBy: CodingKeys.self)
49+
try container.encode(fragment, forKey: .fragment)
50+
try container.encode(type, forKey: .type)
51+
try super.encode(to: encoder)
52+
}
53+
54+
/// Sets the raw JSON data.
55+
///
56+
/// - Parameters:
57+
/// - rawData: A dictionary containing the raw JSON data
58+
override func setRawData(rawData: [String: Any]?) {
59+
self._rawData = rawData
60+
}
61+
62+
/// Gets the raw JSON data
63+
/// - Returns: The `[String: Any]?`.
64+
override func getRawData() -> [String: Any]? {
65+
return self._rawData
66+
}
67+
68+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Foundation
2+
3+
public enum HubCalloutBoxTextBlockV2025R0TypeField: CodableStringEnum {
4+
case calloutBox
5+
case customValue(String)
6+
7+
public init(rawValue value: String) {
8+
switch value.lowercased() {
9+
case "callout_box".lowercased():
10+
self = .calloutBox
11+
default:
12+
self = .customValue(value)
13+
}
14+
}
15+
16+
public var rawValue: String {
17+
switch self {
18+
case .calloutBox:
19+
return "callout_box"
20+
case .customValue(let value):
21+
return value
22+
}
23+
}
24+
25+
}

0 commit comments

Comments
 (0)