CtrlHub

这个 Swift 包是 Ctrl Hub API 的 SDK。

安装

使用你的包管理器添加包,地址为 https://github.com/ctrl-hub/sdk.swift

然后将包导入到你的 bundle 中

import CtrlHub

开始使用

SDK 使用名为 CtrlHubConfig.plist.plist 配置文件来收集连接到平台所需的所有变量。在集成 SDK 时,你应该将此文件添加到你自己的项目的根目录。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>authDomain</key>
    <string>https://auth.ctrl-hub.com</string>
    <key>apiDomain</key>
    <string>https://api.ctrl-hub.com</string>
</dict>
</plist>

要使用 SDK,你需要先导入包,然后才能调用任何方法

import CtrlHub

// Read the configuration from the CtrlHubConfig.plist in your app bundle:
if let configuration = CtrlHub.Config() {
    CtrlHub.config = configuration
} else {
    // there are errors in the config file
}

// Make requests to Ctrl Hub via the SDK:
do {
    let orgs = try await CtrlHub.Organisations.shared.Get()
} catch let error as CtrlHub.APIError {
    // handle the error
}