Created
December 29, 2011 22:11
-
-
Save adamdilek/1536431 to your computer and use it in GitHub Desktop.
Example RUBY Code for Location API
This file contains hidden or 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 '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