Waterloo OpenData Client in Swift. WatSwift supports all OpenData endpoints, and processes all returned data in JSON.
WatSwift can be installed by simply dragging the WatSwift Xcode Project (.xcodeproj
) into your own project, and adding the WatSwift
framework as an embedded framework.
Before you begin to use WatSwift
, set your API key:
WatSwift.apiKey = "------YOUR API KEY--------"
The rest is fairly self explanatory. Each endpoint is categorized by their own struct in WatSwift
. For example, if you wanted to access the current week's menu:
WatSwift.FoodServices.menu { response in
// metadata returned by the API, wrapped in a Metadata struct
let metadata = response.metadata
// Data returned by the API in JSON format.
let data: JSON = response.data
// ...
}
If you wanted to get the atms around the campus:
WatSwift.PointsOfInterest.campusPoi(ofType: .atms) { response in
// ...
}
To make accessing data returned by the OpenData API simple, WatSwift provides a JSON wrapper which allows the you to interact with similarly to a dictionary. Unlike a regular Dictionary, you do not need to lots of option chaining, allowing your code to be much cleaner and easier to read.
Here's an example of how you would access the name of the first food service outlet:
if let outletName = response.data["outlets"][0]["outlet_name"].string {
// outletName
}
The JSON wrapper is courtesy of mattdonnelly's Swifter: a Twitter Framework written in Swift..
You need a valid API key to access the uWaterloo OpenData API; you can get one here.
The Official API Documentation can be found on Waterloo's API Documentation Repo .
WatSwift is licensed under the MIT License. See the LICENSE file for more information.
Waterloo OpenData is licensed under ODL (Open Data License) Agreement