Skip to content

Commit

Permalink
feat: add Hubs Beta (box/box-openapi#453) (#220)
Browse files Browse the repository at this point in the history
Co-authored-by: box-sdk-build <[email protected]>
  • Loading branch information
box-sdk-build and box-sdk-build authored Sep 6, 2024
1 parent b77b8c5 commit 546f487
Show file tree
Hide file tree
Showing 19 changed files with 675 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "2994c4a", "specHash": "739d87b", "version": "0.4.0" }
{ "engineHash": "2994c4a", "specHash": "6ca858e", "version": "0.4.0" }
172 changes: 172 additions & 0 deletions BoxSdkGen.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Sources/Client/BoxClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class BoxClient {

public let trashedFiles: TrashedFilesManager

public let appItemAssociations: AppItemAssociationsManager

public let downloads: DownloadsManager

public let uploads: UploadsManager
Expand Down Expand Up @@ -149,6 +151,7 @@ public class BoxClient {
self.authorization = AuthorizationManager(auth: self.auth, networkSession: self.networkSession)
self.files = FilesManager(auth: self.auth, networkSession: self.networkSession)
self.trashedFiles = TrashedFilesManager(auth: self.auth, networkSession: self.networkSession)
self.appItemAssociations = AppItemAssociationsManager(auth: self.auth, networkSession: self.networkSession)
self.downloads = DownloadsManager(auth: self.auth, networkSession: self.networkSession)
self.uploads = UploadsManager(auth: self.auth, networkSession: self.networkSession)
self.chunkedUploads = ChunkedUploadsManager(auth: self.auth, networkSession: self.networkSession)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import Foundation

public class AppItemAssociationsManager {
public let auth: Authentication?

public let networkSession: NetworkSession

public init(auth: Authentication? = nil, networkSession: NetworkSession = NetworkSession()) {
self.auth = auth
self.networkSession = networkSession
}

/// **This is a beta feature, which means that its availability might be limited.**
/// Returns all app items the file is associated with. This includes app items
/// associated with ancestors of the file. Assuming the context user has access
/// to the file, the type/ids are revealed even if the context user does not
/// have **View** permission on the app item.
///
/// - Parameters:
/// - fileId: The unique identifier that represents a file.
///
/// The ID for any file can be determined
/// by visiting a file in the web application
/// and copying the ID from the URL. For example,
/// for the URL `https://*.app.box.com/files/123`
/// the `file_id` is `123`.
/// Example: "12345"
/// - queryParams: Query parameters of getFileAppItemAssociations method
/// - headers: Headers of getFileAppItemAssociations method
/// - Returns: The `AppItemAssociations`.
/// - Throws: The `GeneralError`.
public func getFileAppItemAssociations(fileId: String, queryParams: GetFileAppItemAssociationsQueryParams = GetFileAppItemAssociationsQueryParams(), headers: GetFileAppItemAssociationsHeaders = GetFileAppItemAssociationsHeaders()) async throws -> AppItemAssociations {
let queryParamsMap: [String: String] = Utils.Dictionary.prepareParams(map: ["limit": Utils.Strings.toString(value: queryParams.limit), "marker": Utils.Strings.toString(value: queryParams.marker), "application_type": Utils.Strings.toString(value: queryParams.applicationType)])
let headersMap: [String: String] = Utils.Dictionary.prepareParams(map: Utils.Dictionary.merge([:], headers.extraHeaders))
let response: FetchResponse = try await NetworkClient.shared.fetch(options: FetchOptions(url: "\(self.networkSession.baseUrls.baseUrl)\("/2.0/files/")\(fileId)\("/app_item_associations")", method: "GET", params: queryParamsMap, headers: headersMap, responseFormat: "json", auth: self.auth, networkSession: self.networkSession))
return try AppItemAssociations.deserialize(from: response.data)
}

/// **This is a beta feature, which means that its availability might be limited.**
/// Returns all app items the folder is associated with. This includes app items
/// associated with ancestors of the folder. Assuming the context user has access
/// to the folder, the type/ids are revealed even if the context user does not
/// have **View** permission on the app item.
///
/// - Parameters:
/// - folderId: The unique identifier that represent a folder.
///
/// The ID for any folder can be determined
/// by visiting this folder in the web application
/// and copying the ID from the URL. For example,
/// for the URL `https://*.app.box.com/folder/123`
/// the `folder_id` is `123`.
///
/// The root folder of a Box account is
/// always represented by the ID `0`.
/// Example: "12345"
/// - queryParams: Query parameters of getFolderAppItemAssociations method
/// - headers: Headers of getFolderAppItemAssociations method
/// - Returns: The `AppItemAssociations`.
/// - Throws: The `GeneralError`.
public func getFolderAppItemAssociations(folderId: String, queryParams: GetFolderAppItemAssociationsQueryParams = GetFolderAppItemAssociationsQueryParams(), headers: GetFolderAppItemAssociationsHeaders = GetFolderAppItemAssociationsHeaders()) async throws -> AppItemAssociations {
let queryParamsMap: [String: String] = Utils.Dictionary.prepareParams(map: ["limit": Utils.Strings.toString(value: queryParams.limit), "marker": Utils.Strings.toString(value: queryParams.marker), "application_type": Utils.Strings.toString(value: queryParams.applicationType)])
let headersMap: [String: String] = Utils.Dictionary.prepareParams(map: Utils.Dictionary.merge([:], headers.extraHeaders))
let response: FetchResponse = try await NetworkClient.shared.fetch(options: FetchOptions(url: "\(self.networkSession.baseUrls.baseUrl)\("/2.0/folders/")\(folderId)\("/app_item_associations")", method: "GET", params: queryParamsMap, headers: headersMap, responseFormat: "json", auth: self.auth, networkSession: self.networkSession))
return try AppItemAssociations.deserialize(from: response.data)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Foundation

public class GetFileAppItemAssociationsHeaders {
/// Extra headers that will be included in the HTTP request.
public let extraHeaders: [String: String?]?

/// Initializer for a GetFileAppItemAssociationsHeaders.
///
/// - Parameters:
/// - extraHeaders: Extra headers that will be included in the HTTP request.
public init(extraHeaders: [String: String?]? = [:]) {
self.extraHeaders = extraHeaders
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Foundation

public class GetFileAppItemAssociationsQueryParams {
/// The maximum number of items to return per page.
public let limit: Int64?

/// Defines the position marker at which to begin returning results. This is
/// used when paginating using marker-based pagination.
///
/// This requires `usemarker` to be set to `true`.
public let marker: String?

/// If given, only return app items for this application type
public let applicationType: String?

/// Initializer for a GetFileAppItemAssociationsQueryParams.
///
/// - Parameters:
/// - limit: The maximum number of items to return per page.
/// - marker: Defines the position marker at which to begin returning results. This is
/// used when paginating using marker-based pagination.
///
/// This requires `usemarker` to be set to `true`.
/// - applicationType: If given, only return app items for this application type
public init(limit: Int64? = nil, marker: String? = nil, applicationType: String? = nil) {
self.limit = limit
self.marker = marker
self.applicationType = applicationType
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Foundation

public class GetFolderAppItemAssociationsHeaders {
/// Extra headers that will be included in the HTTP request.
public let extraHeaders: [String: String?]?

/// Initializer for a GetFolderAppItemAssociationsHeaders.
///
/// - Parameters:
/// - extraHeaders: Extra headers that will be included in the HTTP request.
public init(extraHeaders: [String: String?]? = [:]) {
self.extraHeaders = extraHeaders
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Foundation

public class GetFolderAppItemAssociationsQueryParams {
/// The maximum number of items to return per page.
public let limit: Int64?

/// Defines the position marker at which to begin returning results. This is
/// used when paginating using marker-based pagination.
///
/// This requires `usemarker` to be set to `true`.
public let marker: String?

/// If given, returns only app items for this application type
public let applicationType: String?

/// Initializer for a GetFolderAppItemAssociationsQueryParams.
///
/// - Parameters:
/// - limit: The maximum number of items to return per page.
/// - marker: Defines the position marker at which to begin returning results. This is
/// used when paginating using marker-based pagination.
///
/// This requires `usemarker` to be set to `true`.
/// - applicationType: If given, returns only app items for this application type
public init(limit: Int64? = nil, marker: String? = nil, applicationType: String? = nil) {
self.limit = limit
self.marker = marker
self.applicationType = applicationType
}

}
48 changes: 48 additions & 0 deletions Sources/Schemas/AppItem/AppItem.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Foundation

/// An app item represents an content object owned by an application. It can
/// group files and folders together from different paths. That set can be shared
/// via a collaboration.
public class AppItem: Codable {
private enum CodingKeys: String, CodingKey {
case id
case applicationType = "application_type"
case type
}

/// The unique identifier for this app item.
public let id: String

/// The type of the app that owns this app item.
public let applicationType: String

/// `app_item`
public let type: AppItemTypeField

/// Initializer for a AppItem.
///
/// - Parameters:
/// - id: The unique identifier for this app item.
/// - applicationType: The type of the app that owns this app item.
/// - type: `app_item`
public init(id: String, applicationType: String, type: AppItemTypeField = AppItemTypeField.appItem) {
self.id = id
self.applicationType = applicationType
self.type = type
}

required public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decode(String.self, forKey: .id)
applicationType = try container.decode(String.self, forKey: .applicationType)
type = try container.decode(AppItemTypeField.self, forKey: .type)
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(applicationType, forKey: .applicationType)
try container.encode(type, forKey: .type)
}

}
5 changes: 5 additions & 0 deletions Sources/Schemas/AppItem/AppItemTypeField.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

public enum AppItemTypeField: String, CodableStringEnum {
case appItem = "app_item"
}
54 changes: 54 additions & 0 deletions Sources/Schemas/AppItemAssociation/AppItemAssociation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import Foundation

/// An app item association represents an association between a file or
/// folder and an app item. Associations between a folder and an app item
/// cascade down to all descendants of the folder.
public class AppItemAssociation: Codable {
private enum CodingKeys: String, CodingKey {
case id
case appItem = "app_item"
case item
case type
}

/// The unique identifier for this app item association.
public let id: String

public let appItem: AppItem

public let item: FileBaseOrFolderBaseOrWebLinkBase

/// `app_item_association`
public let type: AppItemAssociationTypeField

/// Initializer for a AppItemAssociation.
///
/// - Parameters:
/// - id: The unique identifier for this app item association.
/// - appItem:
/// - item:
/// - type: `app_item_association`
public init(id: String, appItem: AppItem, item: FileBaseOrFolderBaseOrWebLinkBase, type: AppItemAssociationTypeField = AppItemAssociationTypeField.appItemAssociation) {
self.id = id
self.appItem = appItem
self.item = item
self.type = type
}

required public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decode(String.self, forKey: .id)
appItem = try container.decode(AppItem.self, forKey: .appItem)
item = try container.decode(FileBaseOrFolderBaseOrWebLinkBase.self, forKey: .item)
type = try container.decode(AppItemAssociationTypeField.self, forKey: .type)
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(appItem, forKey: .appItem)
try container.encode(item, forKey: .item)
try container.encode(type, forKey: .type)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

public enum AppItemAssociationTypeField: String, CodableStringEnum {
case appItemAssociation = "app_item_association"
}
57 changes: 57 additions & 0 deletions Sources/Schemas/AppItemAssociations/AppItemAssociations.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import Foundation

/// A list of app item associations
public class AppItemAssociations: Codable {
private enum CodingKeys: String, CodingKey {
case limit
case nextMarker = "next_marker"
case prevMarker = "prev_marker"
case entries
}

/// The limit that was used for these entries. This will be the same as the
/// `limit` query parameter unless that value exceeded the maximum value
/// allowed. The maximum value varies by API.
public let limit: Int64?

/// The marker for the start of the next page of results.
public let nextMarker: String?

/// The marker for the start of the previous page of results.
public let prevMarker: String?

public let entries: [AppItemAssociation]?

/// Initializer for a AppItemAssociations.
///
/// - Parameters:
/// - limit: The limit that was used for these entries. This will be the same as the
/// `limit` query parameter unless that value exceeded the maximum value
/// allowed. The maximum value varies by API.
/// - nextMarker: The marker for the start of the next page of results.
/// - prevMarker: The marker for the start of the previous page of results.
/// - entries:
public init(limit: Int64? = nil, nextMarker: String? = nil, prevMarker: String? = nil, entries: [AppItemAssociation]? = nil) {
self.limit = limit
self.nextMarker = nextMarker
self.prevMarker = prevMarker
self.entries = entries
}

required public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
limit = try container.decodeIfPresent(Int64.self, forKey: .limit)
nextMarker = try container.decodeIfPresent(String.self, forKey: .nextMarker)
prevMarker = try container.decodeIfPresent(String.self, forKey: .prevMarker)
entries = try container.decodeIfPresent([AppItemAssociation].self, forKey: .entries)
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(limit, forKey: .limit)
try container.encodeIfPresent(nextMarker, forKey: .nextMarker)
try container.encodeIfPresent(prevMarker, forKey: .prevMarker)
try container.encodeIfPresent(entries, forKey: .entries)
}

}
Loading

0 comments on commit 546f487

Please sign in to comment.