Skip to content

Instantly share code, notes, and snippets.

@yosriady
Created October 25, 2014 14:04
Show Gist options
  • Select an option

  • Save yosriady/44c84b358b03da47de50 to your computer and use it in GitHub Desktop.

Select an option

Save yosriady/44c84b358b03da47de50 to your computer and use it in GitHub Desktop.
require 'net/https'
require 'json'
uri = URI('https://api.clever.com/v1.1/districts/4fd43cc56d11340000000005/sections?limit=1000000000')
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)
data = JSON.parse(response.body)
total_students = data["data"].inject(0){|result, element| result + element["data"]["students"].size}
total_sections = data["data"].size
average = total_students.to_f / total_sections
p average
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment