![]() |
||
---|---|---|
.github/workflows | ||
Sources/Octokot | ||
Tests/OctokotTests | ||
.gitignore | ||
LICENSE | ||
Makefile | ||
Package.swift | ||
README.md |
README.md
🐱 Octokot
Swift toolkit for the GitHub API
Instalation
Add dependency to Package.swift
...
.package(url: "https://github.com/Alexander-Ignition/Octokot", branch: "main"),
... and your target
.target(name: "ExampleApp", dependencies: ["Octokot"]),
Usage
Import the library and you can create an instance of the GitHub API. It is a wrapper over the GitHub REST API
import Octokot
let github = GitHubAPI()
Most methods are similar to urls from REST API.
You can call them using swift @dynamicMemberLookup
...
let repo = try await github.repos.apple.swift()
... or you can use them via subscript
.
let repo = try await github.repos["server-swift"]["async-http-client"]()
Authentication
Personal Access Token
Create a Personal Access Token after which you can set it in the configuration and use the methods for which authentication is required.
var configuration = GitHubAPI.Configuration.default
configuration.accessToken = .string("<personal_access_token>")
let github = GitHubAPI(configuration: configuration)
let user = try await github.user()
Personal Access Token can be in base 64 encoded strings for this case there is a second method in the configuration.
configuration.accessToken = .base64EncodedString("<base64_encoded_personal_access_token>")