Created
October 8, 2014 05:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* 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