Skip to content

Commit

Permalink
Modernize the README
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynne authored Dec 2, 2021
1 parent ac651bb commit f90e2c0
Showing 1 changed file with 16 additions and 40 deletions.
56 changes: 16 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,39 @@ OneRoster is a standard developed by IMS Global that specifies how technology pr

## Installation

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

.package(url: "https://github.com/gotranseo/oneroster.git", from: "0.0.1") Don't forget to also add it to dependencies array.


## Usage

Start by registering the object to your services:
OneRoster is available through SPM. To install it, simply add the following to the `dependencies` array in your `Package.swift` file:

```swift
services.register { container -> OneRosterClient
return OneRosterClient(client: try container.make())
}
.package(url: "https://github.com/gotranseo/oneroster.git", from: "2.0.0")
```

Then, inside of a controller:
Don't forget to also add it to your target's dependencies:

```swift
let client = try req.make(OneRosterClient.self)
.product(name: "OneRoster", package: "OneRoster")
```

Due to the way OneRoster has their API spec we are forced to have two different request method, `requestMultiple` and `requestSingle`. If you are fetching an array of entities, like `getAllSchools`, do this:
## 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:)`:

```swift
let data = try client.requestMultiple(baseUrl: "ims-url-here",
clientId: "my-client-id",
clientSecret: "my-client-secret",
endpoint: .getAllSchools,
limit: 100,
offset: 0,
decoding: OneRoster.SchoolsResponse.self)
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")
```

By default, the function will go through and recursively query all objects. You can disable this by setting the `bypassRecursion` flag:
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:

```swift
let data = try client.requestMultiple(baseUrl: "ims-url-here",
clientId: "my-client-id",
clientSecret: "my-client-secret",
endpoint: .getAllSchools,
limit: 100,
offset: 0,
decoding: OneRoster.SchoolsResponse.self,
bypassRecursion: true)
let data = try client.request(.getAllSchools, as: OneRoster.SchoolsResponse.self, limit: 100, offset: 0)
```

If you just want a single model, do the following:
To call a single-entity endpoint, such as `getSchool`:

```swift
let school = try client.requestSingle(baseUrl: "ims-url-here",
clientId: "my-client-id",
clientSecret: "my-client-secret",
endpoint: .getSchool(id: "1"))

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

The library handles all of the OAuth 1.0 grossness for you so that you can focus on building cool Ed-Tech stuff. Enjoy!

## Copyright
Copyright Slate Solutions, Inc.
Enjoy!

0 comments on commit f90e2c0

Please sign in to comment.