Created
October 12, 2012 18:09
-
-
Save skout23/3880604 to your computer and use it in GitHub Desktop.
Clever API quickie
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 'json' | |
require 'rest-client' | |
=begin | |
{"data"=> | |
{"district"=>"4fd43cc56d11340000000005", | |
"school"=>"4fee004cca2e43cf27000002", | |
"name"=>"Advanced Literature 1(B)", | |
"teacher"=>"4fee004dca2e43cf270007e8", | |
"sis_id"=>"3494", | |
"grade"=>"8", | |
"section_number"=>"72", | |
"students"=> | |
["4fee004cca2e43cf27000015", | |
"4fee004cca2e43cf270003c5", | |
"4fee004cca2e43cf27000093"], | |
"last_modified"=>"2012-08-07T14:00:09.045Z", | |
"id"=>"50211f69d0b01a522303c219"}, | |
"uri"=>"/v1.1/sections/50211f69d0b01a522303c219"} | |
=end | |
$clever_api = 'DEMO_KEY' | |
json_ip_url = "https://#{$clever_api}@api.getclever.com/v1.1/sections" | |
sections_details = JSON.parse(RestClient.get(json_ip_url)) | |
# because I dont' know the best way to parse the json, lets just make it an array of hashes of hashes. | |
sections = sections_details.first[1] | |
$section_sizes = [] | |
sections.each do |section| | |
section_name = section['data']['name'] | |
section_size = section['data']['students'].size | |
$section_sizes << section_size | |
end | |
puts $section_sizes.inject(:+).to_i/$section_sizes.size.to_i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment