A logo for ATProtoKit, which contains three stacks of rounded rectangles in an isometric top view. At the top stack, the at symbol is in a thick weight, with clouds as the symbol’s colour. The three stacks are darker shades of blue.

ATProtoKit

一个使用 Swift 编写的、简单直接的 AT 协议和 Bluesky 解决方案。

GitHub code size in bytes GitHub Repo stars

Static Badge GitHub Sponsors


注意

这个 API 库非常不稳定。 会发生变化。 功能不完整。 可能会崩溃。 在项目达到 1.0.0 版本之前,不保证稳定性。

ATProtoKit 是一个易于理解的 API 库,它利用 AT 协议,并具有您期望 Swift 编程语言所具备的类型安全性和易用性。 无论您是构建机器人、服务器应用程序,还是另一个面向用户的 Bluesky 客户端,这个项目都希望能帮助您快速上手。

使用示例

let config = ATProtocolConfiguration(handle: "lucy.bsky.social", appPassword: "hunter2")

Task {
    print("Starting application...")

    do {
        try await config.authenticate()

        let atProto = ATProtoKit(sessionConfiguration: config)
        let atProtoBluesky = ATProtoBluesky(atProtoKitInstance: atProto)

        let postResult = try await atProtoBluesky.createPostRecord(text: "Hello Bluesky!")

        print(postResult)
    } catch {
        print("Error: \(error)")
    }
}

动机

我认为 Bluesky 及其配套的 AT 协议在去中心化和简化用户体验之间取得了完美的平衡。 因此,我希望 Swift 开发人员能够以一种感觉自然的方式使用 AT 协议,无论是在 Apple 平台的客户端,还是在 Linux 的服务器端。 因此,我决定开源这个项目。

功能

注意

并非所有上述功能都已实现; 但是,它们很快就会实现。

安装

您可以使用 Swift Package Manager 下载并将库导入到您的项目中

dependencies: [
    .package(url: "https://github.com/MasterJ93/ATProtoKit.git", from: "0.23.0")
]

然后在 targets

targets: [
    .target(
        // name: ...,
        dependencies: [
            .product(name: "ATProtoKit", package: "atprotokit")
        ]
    )
]

路线图

项目页面尚未完成,但您仍然可以通过其 Projects 页面查看它。

快速开始

如使用示例所示,一切都从 ATProtocolConfiguration 开始,它使用 handle、应用程序密码和 pdsURL 来访问和创建会话

import ATProtoKit

let config = ATProtocolConfiguration(handle: "lucy.bsky.social", appPassword: "hunter2")

默认情况下,ATProtocolConfiguration 符合 https://bsky.social。 但是,如果您使用的是其他分布式服务,则可以指定 URL

let result = ATProtocolConfiguration(handle: "lucy.example.social", appPassword: "hunter2", pdsURL: "https://example.social")

此会话包含您需要的所有元素,例如访问和刷新令牌

Task {
    do {
        // The session object is contained in the `ATProtocolConfiguration` object:
        try await config.authenticate()

        if let session = config.session {
            print("Result (Access Token): \(session.accessToken)")
            print("Result (Refresh Token): \(session.refreshToken)")
        }
    } catch {
        print("Error: \(error)")
    }
}

要求

要在您的应用程序中使用 ATProtoKit,您的应用程序应以特定版本号为目标

对于 Linux,您需要使用 Swift 6.0 或更高版本。 在 Linux 上,最低要求包括

您还可以将此项目用于您使用 Swift 编写并在 Docker 上运行的任何程序。

警告

截至目前,理论上Windows支持是可能的,但尚未测试成功。 对于其他平台(例如 Android),也未对此进行测试,但理论上应该是可能的。 虽然使其完全兼容不是目标,但欢迎就此问题提供贡献和反馈。

提交贡献和反馈

虽然此项目将会发生重大更改,但非常欢迎和鼓励反馈、问题和贡献。 如果您想为这个项目做出贡献,请务必阅读 API 指南贡献者指南,然后再提交 pull request。 任何问题(例如错误报告或反馈)都可以在 问题 选项卡中提交。 最后,如果存在任何安全漏洞,请阅读 SECURITY.md,了解如何报告。

如果您有任何问题,可以在 Bluesky 上询问我 (@cjrriley.com)。 顺便关注我! 我也活跃在 Bluesky API Touchers Discord 服务器上。

许可证

此 Swift 包使用 MIT 许可证。 请查看 LICENSE.md 了解更多详情。

Bluesky 使用的文档文本根据 MIT 许可证获得许可。 请查看 ATPROTO-LICENSE.md 了解更多详情。