Skip to content

Instantly share code, notes, and snippets.

@jhamon
Created June 23, 2014 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhamon/b3e847ac7f17b4593291 to your computer and use it in GitHub Desktop.
Save jhamon/b3e847ac7f17b4593291 to your computer and use it in GitHub Desktop.
Finding the average number of students per section with the Clever API.
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