Skip to content

jnozzi/TootSDK

 
 

Repository files navigation

TootSDK

Cross-platform Swift library for the Mastodon API

Swift 5.7 Platforms BSD 3-clause Build Status

TootSDK is a framework for Mastodon and the Fediverse, for iOS. It provides a toolkit for authorizing a user with an instance, and interacting with their posts.

TootSDK is a community developed SDK for Mastodon and the Fediverse. It is designed to work with all major servers (Mastodon, Pleroma, PixelFed etc).

You can use TootSDK to build a client for Apple operating systems, or Linux with Vapor.

overview of how TootSDK integrates with fedi platforms

Why make TootSDK?

When app developers build apps for Mastodon and the Fediverse, every developer ends up having to solved the same set of problems when it comes to the API and data model.

Konstantin and Dave decided to share this effort. TootSDK is a shared Swift Package that any client app can be built on.

Key Principles ⚙️

  • Async/Await based. All asynchronous functions are defined as Async ones that you can use with Async/Await code
  • Internal consistency and standardization of model property names
  • Standardization across all supported Fediverse APIs
  • Platform agnostic (TootSDK shouldn't care if it's on iOS, macOS or Linux!)

Project Status 📈

  • Mastodon - In progress
  • Pleroma - In progress
  • Pixelfed - To do
  • Writefreely - To do

Our roadmap shows where we want to take TootSDK. Our project board shows our current backlog of work, and what is in flight.

Please don't hesitate to open an issue or create a PR for features you need 🙏

Quick start 🏁

It's easy to get started with TootSDK.

  • Add TootSDK to your project via Swift Package Manager: https://github.com/TootSDK/TootSDK

  • Instantiate with an instanceURL and accessToken:

  let instanceURL = URL(string: "social.yourinstance.com")
  let client = try await TootClient(connect: instanceURL, accessToken: "USERACCESSTOKEN")

Signing in (for macOS and iOS):

  • Instantiate your client without a token:
let client = try await TootClient(connect: url)
let client = try await TootClient(connect: url)

guard let accessToken = try await client.presentSignIn(callbackURI: callbackURI) else {
    // handle failed sign in
    return
}

That's it 🎉!

We recommend keeping the accessToken somewhere secure, for example the Keychain.

Signing in (all platforms):

  • Instantiate your client without a token:
let client = try await TootClient(connect: instanceURL)
  • Retrieve an authorization URL to present to the user (so they can sign in)
let authURL = client.createAuthorizeURL(callbackURI: "myapp://someurl")
  • Present the the authorization URL as a web page
  • Let the user sign in, and wait for the callbackURI to be called
  • When that callbackURI is called, give it back to the client to collect the token
let accessToken = client.collectToken(returnUrl: url, callbackURI: callbackURI)

We recommend keeping the accessToken somewhere secure, for example the Keychain.

Accessing a user's home feedfeed

let posts = try await client.data.stream(.timeLineHome)

Further Documentation 📖

  • Reference documentation is available here
  • Example apps:
    • swiftui-toot - a SwiftUI app that shows authorization, a user's feed, posting and account operations
    • swiftyadmin - a command line utility to interact with and control a server using TootSDK
    • vaportoot - a web app in Vapor, that shows how to sign in and view a user's feed

Contributing

Code of Conduct and Contributing rules 🧑‍⚖️

  • Our guide to contributing is available here: CONTRIBUTING.md.
  • All contributions, pull requests, and issues are expected to adhere to our community code of conduct: CODE_OF_CONDUCT.md.

Key contributors ⚡️

License 📃

TootSDK is licensed with the BSD-3-Clause license, more information here: LICENSE.MD

This is a permissive license which allows for any type of use, provided the copyright notice is included.

Acknowledgements 🙏

About

Cross-platform Swift library for the Mastodon and the fediverse

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 99.9%
  • Shell 0.1%