Git Product home page Git Product logo

node_uwapi's Introduction

UWAPI

This node module is a wrapper for the UW OpenData API. It is asynchronous but promised based and so presents a cleaner interface than traditional callbacks while still remaining efficient.

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
});

Dependencies

The package depends on kris kowal's Q library implementation of promises which should automatically be installed by npm.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.