Created
June 23, 2014 18:17
-
-
Save jhamon/b3e847ac7f17b4593291 to your computer and use it in GitHub Desktop.
Finding the average number of students per section with the Clever API.
This file contains 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
require 'net/https' | |
require 'json' | |
uri = URI('https://api.clever.com/v1.1/sections?limit=379') | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_PEER | |
request = Net::HTTP::Get.new(uri.request_uri) | |
request.add_field 'Authorization', 'Bearer DEMO_TOKEN' | |
response = http.request(request) | |
total_students = 0 | |
parsed_section_data = JSON.parse(response.body)["data"] | |
parsed_section_data.each do |section| | |
total_students += section["data"]["students"].length | |
end | |
puts "Average students per section: #{ total_students.fdiv(parsed_section_data.length) }" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment