Swiftpack.co - gotranseo/oneroster as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by gotranseo.
gotranseo/oneroster 2.0.3
A Swift library for interacting with the OneRoster API
⭐️ 1
🕓 6 days ago
macOS
.package(url: "https://github.com/gotranseo/oneroster.git", from: "2.0.3")

OneRoster

A Vapor package for interacting with a OneRoster v1.1 JSON IMS API.

What is OneRoster?

OneRoster is a standard developed by IMS Global that specifies how technology providers can communicate with technology repositories of student data. It can be used to auto-populate products when a school subscribes, roster students, and pull grade/demographic information. We built this library to make it easier to interact with.

Installation

OneRoster is available through SPM. To install it, simply add the following to the dependencies array in your Package.swift file:

.package(url: "https://github.com/gotranseo/oneroster.git", from: "2.0.0")

Don't forget to also add it to your target's dependencies:

.product(name: "OneRoster", package: "OneRoster")

Usage

To obtain a client for making OneRoster endpoint requests, call Application.oneRoster(baseURL:) or Request.oneRoster(baseURL:). If you are calling a server which requires OAuth 1 authorization, use, the .oauth1OneRoster(baseURL:clientId:clientSecret:) method. For an OAuth 2 server, use .oauth2OneRoster(baseURL:clientId:clientSecret:):

let imsURL = URL(string: "https://ims-server-here/")!
let noAuthClient = req.oneRoster(baseURL: imsURL)
let oauth1Client = req.oauth1OneRoster(baseURL: imsURL, clientId: "my-client-id", clientSecret: "my-client-secret")
let oauth2Client = req.oauth2OneRoster(baseURL: imsURL, clientId: "my-client-id", clientSecret: "my-client-secret")

Due to the way OneRoster's API is specified, we are forced to have two different request methods: .request(_:as:filter:) for requesting single entities, and request(_:as:offset:limit:filter:) for requesting arrays of entities. For example, to call the getAllSchools endpoint:

let data = try client.request(.getAllSchools, as: OneRoster.SchoolsResponse.self, limit: 100, offset: 0)

To call a single-entity endpoint, such as getSchool:

let school = try client.request(.getSchool(id: "1"), as: OneRoster.SchoolResponse.self)

Enjoy!

GitHub

link
Stars: 1
Last commit: 6 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Package infrastructure and testing fixes (#6)
6 days ago

What's Changed

  • Added SPDX license header to all source files.
  • Removed many many unnecessary instances of import Foundation.
  • Added updating of OS packages to the Dockerfile.
  • Add soundness check and API breakage check scripts.
  • Retooled soundness script to do fancy rules-based stuff for license header checks, just for fun.
  • Added real testing to the GH Actions workflow.
  • Added derivation notice and derivation source license headers as required by Apache 2.0.
  • Enable back-deployment workarounds for concurrency so tests run on macOS Big Sur.
  • Properly fix handling of percent-encoding in filter strings.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics