DRACOON Swift SDK
用于访问 DRACOON REST API 的库
设置
最低要求
Xcode 13
Swift Package Manager
将此行添加到 Package.swift 依赖项部分
.package(name: "crypto_sdk", url: "https://github.com/dracoon/dracoon-swift-sdk", .upToNextMajor(from: "2.6.0"))
Carthage
将SDK添加到您的Cartfile中
github "dracoon/dracoon-swift-sdk.git" ~> 2.6.0
然后运行
carthage update --platform iOS
以创建一个框架或
carthage update --use-xcframeworks --platform iOS
以创建一个xcframework.
CocoaPods
添加到您的Podfile中
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '12.0'
use_frameworks!
target '<Your Target Name>' do
pod 'DRACOON-SDK', '~> 2.6.0'
end
然后运行
pod install
示例
要了解OAuth代码授予流如何与DRACOON SDK协同工作,请查看/Example/oauth2.example中的示例应用程序。使用carthage构建它,并确保先存储您的配置到/Example/oauth2.example/oauth2.example/OAuthConfig.swift中。
// Create authMode
// Use this mode the first time initializing your DracoonClient. authCode is the code from your OAuth2 code flow authorization response.
let authMode = DracoonAuthMode.authorizationCode(clientId: clientId, clientSecret: clientSecret, authorizationCode: authCode)
// If you received your access and refresh tokens use this mode to initialize your DracoonClient.
let token = DracoonTokens(refreshToken: "refreshToken", accessToken: "accessToken", timestamp: Date(), accessTokenValidity: 3600)
let authMode2 = DracoonAuthMode.accessRefreshToken(clientId: "clientId", clientSecret: "clientSecret", tokens: token)
// Create client
let client = DracoonClientImpl(serverUrl: serverUrl, authMode: authMode, getEncryptionPassword: getEncryptionPassword)
// -- Example Requests --
// Nodes
client.nodes.getNodes(parentNodeId: nodeId, limit: nil, offset: nil, completion: { result in
switch result {
case .value(let nodeList):
// ...
case .error(let error):
// ...
}
})
client.nodes.deleteNodes(request: deleteRequest, completion: { result in
if let error = result.error {
// ...
} else {
// ...
}
})
// Account
client.account.getUserAccount(completion: { result in
switch result {
case .error(let error):
// ...
case .value(let user):
// ...
}
})
client.account.setUserKeyPair(password: password, completion: { result in
switch result {
case .error(let error):
// ...
case .value(let keyPair):
// ...
}
})
// Download
client.nodes.downloadFile(nodeId: nodeId, targetUrl: url, callback: callback)
// Upload
client.nodes.uploadFile(uploadId: uploadId, request: createRequest, filePath: filePath, callback: callback, resolutionStrategy: .autorename)
// Shares
client.shares.createDownloadShare(nodeId: idToShare, password: sharePassword, completion: { result in
switch result {
case .error(let error):
// ...
case .value(let share):
// ...
}
})
let request = CreateUploadShareRequest(targetId: self.nodeId, name: self.containerName){$0.expiration = expiration; $0.password = password; $0.notes = notes}
client.shares.requestCreateUploadShare(request: createRequest, completion: { result in
switch result {
case .error(let error):
// ...
case .value(let share):
// ...
}
})
版权和许可
见 LICENSE