Skip to content

A promise based client library for the UW Open Data API written in node.

Notifications You must be signed in to change notification settings

a1gemmel/js-uwaterloo-api

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UWAPI

This module is a promise wrapper for the UW OpenData API. It's a browser port from the original node.js wrapper. You probably shouldn't use this in any public application, as doing so would require exposing an OpenData API key to the client. I use this exclusively for a display in my home media server, which is not pubically accessable.

Installation

Simply run

npm install uwapi

in the target project. The value returned by require('uwapi') is a constructor that consumes an api token and returns an object with methods for making queries.

var apiToken = 'blarg';
var uwapi = require('uwapi')(apiToken);
uwapi.buildingsList().then(function(buildings) {
	// Do something
});

Usage

Each endpoint is implemented as a function that returns a promise which resolves to the data payload obtained by the querying the endpoint with the provided parameters. Each endpoint path corresponds to a specific function as found in the REFERENCE.md file. Parameters are expected to be passed in to these functions as an object where the key corresponds to the parameter name. GET parameters can optionally be passed as a second argument.

Example

//A 'normal' endpoint (the bulk of them)

uwapi.buildingsList().then(function(buildings) {
	for(var building in buildings) {
		// Do something here
	}
	return processedBuildings;
}).then(function(processedBuildings) {
	// Do something with processedBuildings
}, function(err) {
	// Handle errors
});


//Endpoints which take GET parameters.

uwapi.foodservicesSearch({}, {'calories.lt': 600}).then(console.log, console.error);
uwapi.poorlyDesignedEndpoint({embededParam1: embededVal}, {getParam1: getVal}).then(console.log, console.error);

Tests

Set the environment variable uwApiToken and run 'npm test'

Changelog

###v1.1.1

  • Updated baseURL to use secured endpoints

###v1.1.0

  • Added optional support for GET parameters (see README.md)
  • Added the foodservicesSearch endpoint
  • Added the resourcesSites endpoint

###1.0.4

  • Allow empty responses to propagate rather than throwing an error

###v1.0.3

  • Make function names more consistent with endpoints

Bugs / Feature Requests

Please email any bugs or feature requests to [email protected]

Contributions

Feel free to fork and issue Pull Requests.

About

A promise based client library for the UW Open Data API written in node.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%