Skip to content

Instantly share code, notes, and snippets.

@adamdilek
Created December 29, 2011 22:11
Show Gist options
  • Select an option

  • Save adamdilek/1536431 to your computer and use it in GitHub Desktop.

Select an option

Save adamdilek/1536431 to your computer and use it in GitHub Desktop.
Example RUBY Code for Location 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
@cities = get("http://pigon.ws/location/cities")
@cities.each do |city|
puts city['name']
@districts=get("http://pigon.ws/location/districts/?city_id=#{city['id']}")
@districts.each do |district|
puts "--#{district['name']}"
@regions=get("http://pigon.ws/location/regions/?district_id=#{district['id']}")
@regions.each do |region|
puts "----#{region['name']}"
@streets=get("http://pigon.ws/location/streets/?region_id=#{region['id']}")
@streets.each do |street|
puts "-------#{street['name']}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment