GeoList is a very simple ruby gem to get a list of all countries, cities and suburbs.
gem 'geolist', '~> 0.1.0'
GeoList.countries
# [{:name=>"Australia", :alpha2=>"AU", :alpha3=>"AUS"}, ...]
GeoList.cities('Australia')
# => ["Adak", "Akhiok", "Akiachak", "Akiak", "Akutan", "Alakanuk", ...]
GeoList.suburbs('Hong Kong')
# ["Aberdeen", "Causeway Bay", "Central District","Cha Kwo Ling", "Chai Wan Kok", "Chek Chue", ...]
- GeoList.get: list of countries (equivalent to
GeoList.countries
) - GeoList.get(country): list of cities (equivalent to
GeoList.cities(country)
) - GeoList.get(country, city): list of suburbs (equivalent to
GeoList.suburbs(city)
)
GeoList.update_data
# Will update data file to the latest version (using MaxMind free databases)
# Can be added to migration or in some scheduler
# Database is updated weekly, every Tuesday.