Skip to content

Instantly share code, notes, and snippets.

@adamdilek
Created December 22, 2011 16:40
Show Gist options
  • Save adamdilek/1510934 to your computer and use it in GitHub Desktop.
Save adamdilek/1510934 to your computer and use it in GitHub Desktop.
RUBY Example for University API
require 'rubygems'
require 'json'
require 'net/http'
require 'uri'
def get(base_url)
url="#{base_url}"
response=Net::HTTP.get_response(URI.parse(url))
data=response.body
result=JSON.parse(data)
puts response.code[0]
return result
end
@universites = get("http://pigon.ws/university/list")
@universites.each do |university|
puts university['name']
@faculties=get("http://pigon.ws/university/faculties/?university_id=#{university['id']}")
@faculties.each do |faculty|
puts "--#{faculty['name']}"
@departments=get("http://pigon.ws/university/departments/?faculty_id=#{faculty['id']}")
@departments.each do |department|
puts "----#{department['name']}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment