shadone/DiasporaNodeInfo

NodeInfo protocol implementation in Swift

★ 1Forks 0SwiftGitHub ↗Compare
activitypublemmymastodonnodeinfoswiftswift-package

README

Diaspora NodeInfo

Swift versions Platforms Documentation

Implementation of NodeInfo protocol in Swift.

About Node Info

NodeInfo is an effort to create a standardized way of exposing metadata about a server running one of the distributed social networks. The two key goals are being able to get better insights into the user base of distributed social networking and the ability to build tools that allow users to choose the best-fitting software and server for their needs.

So far, integration of this standard exists for the following software:

  • Mastodon
  • Lemmy
  • Misskey
  • PeerTube
  • Pixelfed
  • ...

and others, see full list on official website https://nodeinfo.diaspora.software

Features

Supports the latest NodeInfo versions:

  • 2.0
  • 2.1

These are the most modern and widely used versions of the protocol.

Usage

DiasporaNodeInfo package comes with a library which you could integrate into your app, as well as a command line tool for quering remote server NodeInfo.

// swift-tools-version: 5.9
import PackageDescription

let package = Package(
    name: "Foobar",
    dependencies: [
        .package(url: "https://github.com/shadone/DiasporaNodeInfo.git", from: "2.0.0"),
    ],
    targets: [
        .executableTarget(
            name: "Foobar",
            dependencies: [
                .product(name: "DiasporaNodeInfo", package: "DiasporaNodeInfo"),
            ]
        ),
    ]
)
import DiasporaNodeInfo

let nodeInfo = try await NodeInfoManager().fetch(for: "mastodon.social")
print(nodeInfo.version) // e.g. 2.1

// Version-agnostic convenience accessors work across both schema versions;
// fields a schema version lacks come back nil (homepage is nil on 2.0).
print(nodeInfo.softwareName, nodeInfo.softwareVersion)
print(nodeInfo.openRegistrations)
print(nodeInfo.softwareHomepage ?? "no homepage")

// Payload-only surfaces (metadata, services, the typed protocols arrays;
// raw names are on `protocolNames`) are still reached via the
// schema-specific payload.
if let info = nodeInfo.v2_1 {
    print(info.metadata ?? [:])
}

To use the command line you compile it or run with Mint:

mint run shadone/DiasporaNodeInfo mastodon.social

Contributors

shadone

Issues