Skip to content

Instantly share code, notes, and snippets.

@denniszhao
Created October 8, 2014 05:11
Show Gist options
  • Save denniszhao/81a05e35f128bf85cd43 to your computer and use it in GitHub Desktop.
Save denniszhao/81a05e35f128bf85cd43 to your computer and use it in GitHub Desktop.
/**
*
* Computes the average number of students per section in the sandbox/demo API.
*
*/
var request = require('request');
// We know that there's only one district in the dummy data from a call
// to the `districts` endpoint, ie
// curl -H 'Authorization: Bearer DEMO_TOKEN' -X GET https://api.clever.com/v1.1/districts
// whose id is 4fd43cc56d11340000000005
var options = {
url: 'https://api.clever.com/v1.1/districts/4fd43cc56d11340000000005/sections',
headers: {
"Authorization": "Bearer DEMO_TOKEN"
}
};
request(options, function onGetSections(error, response, body) {
// Array of data
var data = JSON.parse(body).data,
numSections = data.length - 1,
totalStudents = 0;
// Iterate through all sections, get total
for (var i = 0; i < data.length; i++) {
totalStudents += data[i].data.students.length;
}
console.log(totalStudents / numSections);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment