Unofficial Are.na API client for Swift.
This Swift package provides a client for interacting with the Are.na API. It allows you to authenticate, fetch user data, and manage channels and blocks.
Important
This package is still work-in-progress, only implementing a subset of the official Are.na API functionality.
You can add this package to your project using Swift Package Manager. Add the following line to your Package.swift dependencies:
.package(url: "https://github.com/yihui-hu/ArenaKit.git", from: "1.0.0")To use the ArenaAPIClient, you need to configure it with your Are.na API credentials. You can do this in your app's launch code:
import ArenaKit
let config = ArenaAPIConfig(
clientId: "YOUR_CLIENT_ID",
clientSecret: "YOUR_CLIENT_SECRET",
redirectScheme: "YOUR_REDIRECT_SCHEME"
)
ArenaAPIClient.setup(config: config)To authenticate and obtain an access token, you can use the exchangeCode method:
let code = "AUTHORIZATION_CODE_FROM_OAUTH"
do {
let token = try await ArenaAPIClient.shared.exchangeCode(code)
print("Access Token: \(token.access_token)")
} catch {
print("Error exchanging code: \(error)")
}You can fetch the authenticated user's profile using:
do {
let user = try await ArenaAPIClient.shared.getCurrentUser()
print("User: \(user.username)")
} catch {
print("Error fetching user: \(error)")
}To fetch channels for a specific user:
do {
let channels = try await ArenaAPIClient.shared.getUserChannels(userId: user.id)
print("Channels: \(channels.channels)")
} catch {
print("Error fetching channels: \(error)")
}Here is a simple example of how to use the ArenaAPIClient:
import ArenaKit
func main() async {
let config = ArenaAPIConfig(
clientId: "YOUR_CLIENT_ID",
clientSecret: "YOUR_CLIENT_SECRET",
redirectScheme: "YOUR_REDIRECT_SCHEME"
)
ArenaAPIClient.setup(config: config)
do {
let user = try await ArenaAPIClient.shared.getCurrentUser()
print("Authenticated as: \(user.username)")
} catch {
print("Failed to fetch user: \(error)")
}
}
Task {
await main()
}This project is licensed under the MIT License. See the LICENSE file for details.