Skip to content

yihui-hu/ArenaKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Are.na API Client

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.

Installation

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")

Setup

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)

Usage

Authentication

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)")
}

Fetching User Data

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)")
}

Managing Channels

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)")
}

Example

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()
}

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Unofficial Swift client for the Are.na API.

Resources

License

Stars

10 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages