Giter Site home page Giter Site logo

city-state's Introduction

City-State Ruby Gem

The city-state gem offers a straightforward way to retrieve lists of states for any given country and cities for any state. It's built on the MaxMind database, making it a reliable source for such data.

Compatibility

This branch (main) is compatible with Ruby 3 and higher. If you are using Ruby 2, please refer to the v0 branch.

Ruby 3 and Higher

  • This is the primary development branch.
  • New features and improvements will be added here.
  • Ensure you have Ruby 3 or higher to use the versions from this branch.

Ruby 2 Support

  • For Ruby 2 support, please refer to the v0 branch.
  • The v0 branch is in maintenance mode, which means it will only receive bug fixes and will not get any new features.

Installation

Add the gem to your Gemfile:

gem 'city-state'

Then, run:

$ bundle install

Listing States:

Retrieve a list of states for a specified country:

CS.states(:US)

Note: The gem is case-insensitive. You can use variations like :US, :us, :Us, "us", and "US".

Listing Cities:

Retrieve a list of cities for a specified state and country:

CS.cities(:AK, :US)

You can also specify the country, though it's optional. The gem remembers the last country you used:

CS.states(:BR)

CS.cities(:TO)  # This will use Brazil (BR) as the country

Miscellaneous Notes:

  • The country is an optional argument. The gem always uses the last country that you used.

Listing Countries:

CS.countries

Missing cities and wrong names

To add missing cities or to rename wrong ones, create these files in your project folder: db/cities-lookup.yml and db/states-lookup.yml and db/countries-lookup.yml:

Renaming a country - US to America:

# db/countries-lookup.yml
US: "America"

Renaming a state - California to Something Else:

# db/states-lookup.yml
US:
  CA: Something Else

Renaming a city:

# db/cities-lookup.yml
US:
  CA:
    "Burbank": "Bur Bank"

Adding a missing city:

# db/cities-lookup.yml
US:
  CA:
    "My Town": "My Town"

Suppressing a city (set it as a blank line):

# db/cities-lookup.yml
US:
  CA:
    "Burbank": ""

To use a different file instead of db\cities-lookup.yml:

CS.set_cities_lookup_file('new-city-names.yml')

CS.set_states_lookup_file('new-state-names.yml')

CS.set_countries_lookup_file('new-country-names.yml')

Updating MaxMind database

MaxMind update their databases weekly on Tuesdays.

Since Dec 30, 2019, MaxMind requires a license key (for free) to get download updates.

To get the license key:

  1. Sign up for a MaxMind account: https://www.maxmind.com/en/geolite2/signup
  2. Create a license key: https://www.maxmind.com/en/accounts/current/license-key
  3. There's no need to download anything.

To update:

CS.set_license_key('MY_KEY')

CS.update

Note: Replace MY_KEY with your actual license key.

Manually setting a database file:

You can use an alternative database file instead of downloading from MaxMind servers:

CS.set_maxmind_zip_url('/home/daniel/GeoLite2-City-CSV_20200324.zip')

CS.update

or

CS.set_maxmind_zip_url('https://example.com/GeoLite2-City-CSV_20200324.zip')

CS.update

The file has to be a ZIP file. And it has to contain a CVS file named GeoLite2-City-Locations-en.csv. This file must be in MaxMind's GeoLite2 City's format.

Changelog

See CHANGELOG.md

How this gem was created

https://learnwithdaniel.com/2015/02/citystate-list-of-countries-cities-and-states-ruby/

CityState License

city-state is a open source project by Daniel Loureiro with a MIT license. Also, it uses MaxMind open source database.

MaxMind License

Database and Contents Copyright (c) 2020 MaxMind, Inc. This work is licensed under the Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/.

city-state's People

Contributors

devkumarvdb avatar loureirorg avatar minimul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

city-state's Issues

Renaming a city or Delete city

Hello, I have a problem with the gem. I want to rename and delete some city, becouse these are wrong, but when I try this the gem doesnt work, I created the file city-loockup.yml but this didnt work is so frustrating becouse the gem is so good. I had not problem change the state or the countries, is possible to rename, add or delete. But I cant with the cities.

CO: NAR: "Anganoy": "" "Buga": "" "Cartago": "" "Chaparral": "" "Girardot": "" "Imues": "La Union" "Alban": "Alban" "Aldana": "Aldana" "Ancuya": "Ancuya"

For example sometimes the cities Anganoy, Buga, Cartago, Chaparral and Girardot are delete but sometimes dont. And never I can created the cities Alban, Aldana, Ancuya.

CS.cities :ny, :us gets wrong data.

NY seems to have some issue getting correct city list.

Result:

>> CS.cities :ny, :us
=> ["Accord", "Acra", "Adams", "Addison", "Afton", "Akron", "Albany", "Albertson", "Albion", "Alden", "Alexander", "Alexandria Bay", "Alfred", "Alfred Station", "Allegany", "Almond", "Alplaus", "Altamont", "Altmar", "Altona", "Amagansett", "Amawalk", "Amenia", "Amherst", "Amityville", "Amsterdam", "Andes", "Andover", "Angelica", "Angola", "Annandale-on-Hudson", "Apalachin", "Aquebogue", "Arcade", "Ardsley", "Argyle", "Arkport", "Armonk", "Arverne", "Ashville", "Astoria", "Athens", "Atlantic Beach", "Attica", "Au Sable Forks", "Auburn", "Aurora", "Austerlitz", "Ava", "Averill Park", "Avoca", "Avon", "Babylon", "Bainbridge", "Baldwin", "Baldwin Place", "Baldwinsville", "Ballston Lake", "Ballston Spa", "Barryville", "Barton", "Batavia", "Bath", "Bay Shore", "Bayport", "Bayside", "Bayville", "Beacon", "Bearsville", "Beaver Dams", "Bedford", "Bedford Hills", "Bellerose", "Bellmore", "Bellport", "Belmont", "Bemus Point", "Bergen", "Berkshire", "Berlin", "Berne", "Bernhards Bay", "Bethpage", "Big Flats", "Binghamton", "Blauvelt", "Blooming Grove", "Bloomingburg", "Blossvale", "Blue Point", "Bohemia", "Boiceville", "Bolivar", "Bolton Landing", "Bombay", "Boonville", "Boston", "Bovina Center", "Bowmansville", "Bradford", "Branchport", "Brant Lake", "Brasher Falls", "Brentwood", "Brewerton", "Brewster", "Briarcliff Manor", "Bridgehampton", "Bridgeport", "Brightwaters", "Broadalbin", "Brockport", "Brocton", "Bronxville", "Brookfield", "Brookhaven", "Brooklyn", "Brooktondale", "Brushton", "Buchanan", "Buffalo", "Burdett", "Burlington Flats", "Burnt Hills", "Burt", "Byron", "Cadyville", "Cairo", "Caledonia", "Callicoon", "Calverton", "Cambria Heights", "Cambridge", "Camden", "Cameron Mills", "Camillus", "Campbell", "Campbell Hall", "Canajoharie", "Canandaigua", "Canastota", "Candor", "Canisteo", "Canton", "Cape Vincent", "Carle Place", "Carmel", "Caroga Lake", "Carthage", "Cassadaga", "Cassville", "Castile", "Castleton-on-Hudson", "Castorland", "Cato", "Catskill", "Cattaraugus", "Cayuga", "Cazenovia", "Cedarhurst", "Celoron", "Center Moriches", "Centereach", "Centerport", "Central Islip", "Central Square", "Central Valley", "Chadwicks", "Champlain", "Chappaqua", "Chatham", "Chaumont", "Chazy", "Chemung", "Chenango Forks", "Cherry Creek", "Cherry Valley", "Chester", "Chestertown", "Chittenango", "Churchville", "Cicero", "Cincinnatus", "Circleville", "Clarence", "Clarence", "Claverack", "Clay", "Clayton", "Cleveland", "Clifton Park", "Clifton Springs", "Climax", "Clinton", "Clinton Corners", "Clintondale", "Clyde", "Clymer", "Cobleskill", "Coeymans", "Cohocton", "Cohoes", "Cold Brook", "Cold Spring", "Cold Spring Harbor", "College Point", "Colton", "Commack", "Comstock", "Conesus", "Congers", "Conklin", "Constantia", "Cooperstown", "Copake", "Copake Falls", "Copenhagen", "Copiague", "Coram", "Corfu", "Corinth", "Corning", "Cornwall-on-Hudson", "Cornwallville", "Corona", "Cortland", "Coxsackie", "Cragsmoor", "Cranberry Lake", "Craryville", "Crompond", "Cropseyville", "Cross River", "Croton Falls", "Croton-on-Hudson", "Crown Point", "Cuba", "Cuddebackville", "Cutchogue", "Dalton", "Dansville", "Darien Center", "De Kalb Junction", "Deansboro", "Deer Park", "Delanson", "Delevan", "Delhi", "Delmar", "Denver", "Depew", "Deposit", "Derby", "Dewittville", "Dexter", "Dickinson Center", "Dobbs Ferry", "Dodgewood", "Dolgeville", "Dover Plains", "Downsville", "Dryden", "Duanesburg", "Dundee", "Dunkirk", "Durham", "Durhamville", "Eagle Bridge", "Earlville", "East Amherst", "East Aurora", "East Berne", "East Branch", "East Chatham", "East Concord", "East Durham", "East Elmhurst", "East Greenbush", "East Hampton", "East Islip", "East Marion", "East Meadow", "East Meredith", "East Moriches", "East Nassau", "East Northport", "East Norwich", "East Otto", "East Pharsalia", "East Quogue", "East Rochester", "East Rockaway", "East Setauket", "East Syracuse", "Eastchester", "Eastport", "Eden", "Edmeston", "Edwards", "Elbridge", "Eldred", "Elizaville", "Elka Park", "Ellenville", "Ellicottville", "Elma", "Elmhurst", "Elmira", "Elmont", "Elmsford", "Endicott", "Erieville", "Erin", "Esopus", "Essex", "Fabius", "Fair Haven", "Fairport", "Falconer", "Fallsburg", "Far Rockaway", "Farmingdale", "Farmington", "Farmingville", "Fayetteville", "Feura Bush", "Fillmore", "Fishers", "Fishers Island", "Fishers Landing", "Fishkill", "Fleischmanns", "Floral Park", "Florida", "Flushing", "Fonda", "Forest Hills", "Fort Ann", "Fort Covington", "Fort Drum", "Fort Edward", "Fort Johnson", "Fort Montgomery", "Fort Plain", "Frankfort", "Franklin", "Franklin Square", "Franklinville", "Fredonia", "Freedom", "Freehold", "Freeport", "Fresh Meadows", "Frewsburg", "Friendship", "Fulton", "Fultonville", "Gainesville", "Galway", "Gansevoort", "Garden City", "Gardiner", "Garnerville", "Garrison", "Gasport", "Geneseo", "Geneva", "Genoa", "Georgetown", "Germantown", "Getzville", "Ghent", "Gilboa", "Glen Cove", "Glen Head", "Glen Oaks", "Glen Spey", "Glenfield", "Glenham", "Glenmont", "Glens Falls", "Glenwood", "Glenwood Landing", "Gloversville", "Goldens Bridge", "Goshen", "Gouverneur", "Gowanda", "Grahamsville", "Grand Island", "Granite Springs", "Granville", "Great Neck", "Great River", "Great Valley", "Greene", "Greenfield Center", "Greenlawn", "Greenport", "Greenvale", "Greenville", "Greenwich", "Greenwood Lake", "Groton", "Groveland", "Guilderland", "Guilford", "Hamburg", "Hamden", "Hamilton", "Hamlin", "Hammondsport", "Hampton Bays", "Hancock", "Hannibal", "Harford", "Harpursville", "Harriman", "Harrison", "Hartsdale", "Hastings", "Hastings-on-Hudson", "Hauppauge", "Haverstraw", "Hawthorne", "Hector", "Hemlock", "Hempstead", "Henrietta", "Hensonville", "Herkimer", "Hermon", "Heuvelton", "Hewlett", "Hicksville", "High Falls", "Highland", "Highland Falls", "Highland Mills", "Hillburn", "Hillsdale", "Hilton", "Hobart", "Hogansburg", "Holbrook", "Holland", "Holland Patent", "Holley", "Hollis", "Holmes", "Holtsville", "Homer", "Honeoye", "Honeoye Falls", "Hoosick", "Hoosick Falls", "Hopewell Junction", "Hornell", "Horseheads", "Houghton", "Howard Beach", "Howells", "Howes Cave", "Hubbardsville", "Hudson", "Hudson Falls", "Huguenot", "Hume", "Hunter", "Huntington", "Huntington Station", "Hurley", "Hurleyville", "Hyde Park", "Ilion", "Indian Lake", "Inlet", "Interlaken", "Inwood", "Irvington", "Island Park", "Islandia", "Islip", "Islip Terrace", "Ithaca", "Jackson Heights", "Jamaica", "Jamesport", "Jamestown", "Jamesville", "Jasper", "Jay", "Jefferson Valley", "Jeffersonville", "Jericho", "Johnson", "Johnson City", "Johnstown", "Jordan", "Jordanville", "Katonah", "Keene Valley", "Keeseville", "Kendall", "Kennedy", "Kerhonkson", "Keuka Park", "Kew Gardens", "Kiamesha Lake", "Kinderhook", "Kings Park", "Kingston", "Kirkville", "Kirkwood", "La Fargeville", "LaFayette", "Lacona", "Lagrangeville", "Lake George", "Lake Grove", "Lake Katrine", "Lake Luzerne", "Lake Peekskill", "Lake Placid", "Lake Pleasant", "Lake View", "Lakeville", "Lakewood", "Lancaster", "Lansing", "Larchmont", "Latham", "Laurel", "Laurens", "Lawrence", "Le Roy", "Lee Center", "Leeds", "Leicester", "Levittown", "Lewis", "Lewiston", "Liberty", "Lily Dale", "Lima", "Lincolndale", "Lindenhurst", "Lindley", "Lisbon", "Lisle", "Little Falls", "Little Neck", "Little Valley", "Liverpool", "Livingston Manor", "Livonia", "Loch Sheldrake", "Locke", "Lockport", "Locust Valley", "Long Beach", "Long Island", "Long Lake", "Lowman", "Lowville", "Lynbrook", "Lyons", "Macedon", "Machias", "Madison", "Madrid", "Mahopac", "Mallory", "Malone", "Malverne", "Mamaroneck", "Manhasset", "Manlius", "Mannsville", "Manorville", "Marathon", "Marcellus", "Marcy", "Margaretville", "Marietta", "Marilla", "Marion", "Marlboro", "Martville", "Maspeth", "Massapequa", "Massapequa Park", "Massena", "Mastic", "Mastic Beach", "Mattituck", "Maybrook", "Mayfield", "Mayville", "Mechanicville", "Medford", "Medina", "Medusa", "Melrose", "Melville", "Merrick", "Mexico", "Middle Grove", "Middle Island", "Middle Village", "Middleburgh", "Middleport", "Middlesex", "Middletown", "Millbrook", "Miller Place", "Millerton", "Millport", "Millwood", "Milton", "Mineola", "Minetto", "Mineville", "Minoa", "Modena", "Mohawk", "Mohegan Lake", "Moira", "Monroe", "Monsey", "Montauk", "Montgomery", "Monticello", "Montour Falls", "Montrose", "Mooers", "Mooers Forks", "Moravia", "Moriah", "Moriches", "Morris", "Morrisonville", "Morrisville", "Mount Kisco", "Mount Morris", "Mount Sinai", "Mount Tremper", "Mount Upton", "Mount Vernon", "Mount Vision", "Mountain Dale", "Mountainville", "Munnsville", "Nanuet", "Naples", "Narrowsburg", "Nassau", "Natural Bridge", "Nedrow", "Nesconset", "Neversink", "New Berlin", "New City", "New Hampton", "New Hartford", "New Hyde Park", "New Lebanon", "New Milford", "New Paltz", "New Rochelle", "New Suffolk", "New Windsor", "New Woodstock", "New York", "New York Mills", "Newark", "Newburgh", "Newcomb", "Newfield", "Newport", "Niagara Falls", "Nichols", "Nicholville", "Norfolk", "North Babylon", "North Bangor", "North Bay", "North Chili", "North Collins", "North Creek", "North Greece", "North Java", "North Rose", "North Salem", "North Tonawanda", "Northport", "Northrup's of West Bloomfield Mobile Home Park", "Northville", "Norwich", "Norwood", "Nunda", "Nyack", "Oak Hill", "Oakdale", "Oakfield", "Oakland Gardens", "Ocean Beach", "Oceanside", "Odessa", "Ogdensburg", "Old Bethpage", "Old Chatham", "Old Forge", "Old Westbury", "Olean", "Olivebridge", "Olmstedville", "Oneida", "Oneonta", "Ontario", "Orangeburg", "Orchard Park", "Oriskany", "Oriskany Falls", "Ossining", "Oswego", "Otego", "Otisville", "Ovid", "Owego", "Oxford", "Oyster Bay", "Ozone Park", "Painted Post", "Palatine Bridge", "Palenville", "Palisades", "Palmyra", "Panama", "Parish", "Patchogue", "Patterson", "Pattersonville", "Paul Smiths", "Pavilion", "Pawling", "Pearl River", "Peconic", "Peekskill", "Pelham", "Penfield", "Penn Yan", "Pennellville", "Perry", "Peru", "Petersburg", "Phelps", "Philadelphia", "Philmont", "Phoenix", "Piermont", "Pine Bush", "Pine City", "Pine Hill", "Pine Plains", "Pine Valley", "Pitcher", "Pittsford", "Plainview", "Plattsburgh", "Pleasant Valley", "Pleasantville", "Poestenkill", "Point Lookout", "Pomona", "Pompey", "Port Byron", "Port Chester", "Port Crane", "Port Ewen", "Port Gibson", "Port Henry", "Port Jefferson", "Port Jefferson Station", "Port Jervis", "Port Washington", "Portageville", "Porter Corners", "Portland", "Portville", "Potsdam", "Pottersville", "Poughkeepsie", "Poughquag", "Pound Ridge", "Prattsburgh", "Prattsville", "Pulaski", "Purchase", "Purdys", "Purling", "Putnam Valley", "Queens Village", "Queensbury", "Quogue", "Randolph", "Ransomville", "Ravena", "Red Creek", "Red Hook", "Redwood", "Rego Park", "Remsen", "Remsenburg", "Rensselaer", "Rexford", "Rhinebeck", "Richfield Springs", "Richford", "Richmond Hill", "Richmondville", "Richville", "Ridge", "Ripley", "Riverhead", "Rochester", "Rock Hill", "Rock Tavern", "Rockaway Park", "Rockville Centre", "Rocky Point", "Rome", "Romulus", "Ronkonkoma", "Roosevelt", "Roscoe", "Rosedale", "Rosendale", "Roslyn", "Roslyn Heights", "Rotterdam Junction", "Round Top", "Rouses Point", "Roxbury", "Rush", "Rushford", "Rushville", "Rye", "Sackets Harbor", "Sag Harbor", "Sagaponack", "Saint Albans", "Saint Bonaventure", "Saint James", "Saint Johnsville", "Saint Regis Falls", "Salamanca", "Salem", "Salisbury Mills", "Salt Point", "Sanborn", "Sandy Creek", "Saranac Lake", "Saratoga Springs", "Saugerties", "Sauquoit", "Savannah", "Sayville", "Scarsdale", "Schaghticoke", "Schenectady", "Schenevus", "Schodack Landing", "Schoharie", "Schroon Lake", "Schuylerville", "Scio", "Scotia", "Scottsville", "Sea Cliff", "Seaford", "Selden", "Selkirk", "Seneca Falls", "Shandaken", "Shelter Island", "Shelter Island Heights", "Shenorock", "Sherburne", "Sheridan", "Sherman", "Sherrill", "Shirley", "Shokan", "Shoreham", "Shortsville", "Shrub Oak", "Sidney", "Sidney Center", "Silver Creek", "Silver Springs", "Sinclairville", "Skaneateles", "Skaneateles Falls", "Slate Hill", "Slaterville Springs", "Slingerlands", "Sloansville", "Sloatsburg", "Smallwood", "Smartville", "Smithtown", "Smithville Flats", "Smyrna", "Sodus", "Somers", "Sound Beach", "South Bethlehem", "South Butler", "South Dayton", "South Fallsburg", "South Glens Falls", "South Jamesport", "South Kortright", "South New Berlin", "South Otselic", "South Ozone Park", "South Plymouth", "South Salem", "Southampton", "Southfields", "Southold", "Sparkill", "Sparrow Bush", "Speculator", "Spencer", "Spencerport", "Spencertown", "Sprakers", "Spring Valley", "Springfield Gardens", "Springville", "Springwater", "Staatsburg", "Stamford", "Stanfordville", "Stanley", "Star Lake", "Staten Island", "Stephentown", "Sterling Forest", "Stillwater", "Stone Ridge", "Stony Brook", "Stony Creek", "Stony Point", "Stormville", "Strykersville", "Stuyvesant", "Stuyvesant Falls", "Suffern", "Sugar Loaf", "Sunnyside", "Sylvan Beach", "Syosset", "Syracuse", "Taberg", "Tappan", "Tarrytown", "The Bronx", "Thiells", "Thornwood", "Ticonderoga", "Tillson", "Tomkins Cove", "Tonawanda", "Treadwell", "Troy", "Trumansburg", "Truxton", "Tuckahoe", "Tully", "Tupper Lake", "Tuxedo Park", "Ulster Park", "Unadilla", "Union Springs", "Uniondale", "Unionville", "Upton", "Utica", "Vails Gate", "Valatie", "Valhalla", "Valley Cottage", "Valley Stream", "Van Etten", "Varysburg", "Verbank", "Vernon", "Vernon Center", "Verona", "Verona Beach", "Verplanck", "Vestal", "Victor", "Victory Mills", "Voorheesville", "Waccabuc", "Wading River", "Walden", "Wallkill", "Walton", "Walworth", "Wanakena", "Wantagh", "Wappingers Falls", "Warners", "Warrensburg", "Warsaw", "Warwick", "Washingtonville", "Wassaic", "Water Mill", "Waterford", "Waterloo", "Waterport", "Watertown", "Waterville", "Watervliet", "Watkins Glen", "Waverly", "Wayland", "Webster", "Weedsport", "Wells", "Wellsburg", "Wellsville", "West Babylon", "West Bloomfield", "West Chazy", "West Cornwall", "West Coxsackie", "West Edmeston", "West Falls", "West Haverstraw", "West Hempstead", "West Henrietta", "West Hurley", "West Islip", "West Leyden", "West Monroe", "West Nyack", "West Point", "West Sand Lake", "West Sayville", "West Somerset", "West Valley", "West Winfield", "Westbrookville", "Westbury", "Westerlo", "Westfield", "Westhampton", "Westhampton Beach", "Westons Mills", "Westport", "Westtown", "White Plains", "Whitehall", "Whitesboro", "Whitestone", "Whitesville", "Whitney Point", "Willet", "Williamson", "Williamstown", "Williston Park", "Willsboro", "Willseyville", "Wilmington", "Wilson", "Windsor", "Wingdale", "Winthrop", "Wolcott", "Woodbourne", "Woodbury", "Woodhaven", "Woodhull", "Woodmere", "Woodridge", "Woodside", "Woodstock", "Worcester", "Wurtsboro", "Wyandanch", "Wynantskill", "Wyoming", "Yaphank", "Yonkers", "York", "Yorktown Heights", "Youngstown", "Youngsville", "Yulan"]

Add Code for Telangana(India)

Hi,
Kindly add the code for Telangana (a state in India). As of now in your DB the code is blank.
I request you kindly add the code TG for Telangana.

Permission errors on deploy

This gem seems to want to write files to its own gem directory. Is this normal? In production I get the following error and the Rails application won't boot:

Could not spawn process for application /var/www/spikeatschool/current: The application encountered the following error: Permission denied @ rb_sysopen - /var/www/xxxxxxxxxxxx/shared/bundle/ruby/2.6.0/gems/city-state-0.1.0/lib/db/states.nz (Errno::EACCES)

Is there a way to not have city-state write these files? Perhaps just load them into memory instead?

Unable to update from Rails console, changes lost after closing console

Hi,

I had to update the city-state gem to get the latest data. I ran CS.update from Rails console and checked the results. I got updated data but as soon as I close Rails console on Heroku, the changes were lost.

Am I missing a step here? Please provide some assistance ASAP.

Thank you.

Problem with states and cities, only getting country name with those methods

Hello,
Thanks for the gem, it's really necessary in web development...
But I have a problem with the methods... they only answer me the country name...
This is my development enviroment:
Mac platform
RVM
Ruby 2.1.1
Rails 4.1.6

let me show you the results of my rails console:

2.1.1 :043 > CS.get
     => {:AD=>"Andorra", :AE=>"United Arab Emirates", :AF=>"Afghanistan", :AG=>"Antigua and Barbuda",

Wich is OK!

Then when i try to send the Bolivia code :BO even the US code...

    2.1.1 :044 > CS.get :bo
        => "Bolivia" 
    2.1.1 :045 > CS.get :us
        => "United States" 

OK... lets try the other methods:

2.1.1 :046 > CS.states(:us)
 => "United States" 
2.1.1 :047 > CS.states(:bo)
 => "Bolivia" 

OK... I'll spent some time checking the code and I went to my gem directory and I found this file GeoLite2-City-Locations-en.csv, at the begining i tought maybe this is a permission problem, i changed the cmod to 777 just to test... and the answer is the same...
Then i tryed to get the Cities:

2.1.1 :051 > CS.cities(:bo, :s)
 => [] 

and then i tryed to do the same with US:

CS.cities(:us, :or)
 => [] 
2.1.1 :061 > CS.cities(:us, :nv)
 => [] 

then i try a random State code...

CS.cities(:us, :pa)
TypeError: no implicit conversion of Symbol into Integer
    from /Users/svonborries/.rvm/gems/ruby-2.1.1@seru/gems/city-state-0.0.12/lib/city-state.rb:145:in `[]'
    from /Users/svonborries/.rvm/gems/ruby-2.1.1@seru/gems/city-state-0.0.12/lib/city-state.rb:145:in `cities'
    from (irb):62

Am I missing something??? or maybe it's something related to my SO (Snow Leopard)

Please give me a hand with this... I really want to use yout gem.

Have a great Day,

Sergio,

Capturing Address in MM

I will be working on the following features in Address Module.

  • Design UI
  • Define new relation with defined attributes in Funnel and Stripe
  • Address validation
  • Syncing stripe address to our DB
  • User who didn't provide an address on Stripe will be redirected to the Address page.

Integrate with locale

Hi, the names retrieved by maxmind are always english name I could check that the gem only look up for the english names, would be better if it searches the names based on the locale of the rails application, or even better pass that as an argument in the CScall

Error "Did you mean? exist?"

3.2.0 :002 > CS.countries
/home/valery/.local/share/gem/ruby/3.2.0/gems/city-state-0.1.0/lib/city-state.rb:286:in `countries': undefined
method `exists?' for File:Class (NoMethodError)

    if ! File.exists? COUNTRIES_FN
             ^^^^^^^^
Did you mean?  exist?

Cannot list all existing cities to check if certain city exists or not right away

I just found out that there's no "all cities list" or anything related, and I needed that to check if an city exists.

I would like to list all cities of all countries and all states to check if a certain city exists or not, and for that i would need to iterate all it over. Would be better to have an method available to get all cities or check if a certain city exists or maybe both.

Filtering CS.update

I love your gem. However, ether CS.update downloads all the cities in the world (which is a bit much), or if it doesn't and it's sending a request to out every time I ask for a City.

Would be nice to filter this down, and specify what countries' cities you want to download.

data is not in predictable format

I've noticed an issue with the cities data. It's not in a predictable format. I've been writing a helper to deal with abbreviations but then I noticed that some cities in the datafile have the word 'saint' spelled out, others have 'st' and others have 'st.'

Here are a few examples from: CS.cities(:MO, 'US')

"Saint Albans",
"Saint Ann",
"Saint Clair",
"Saint Elizabeth",
"Saint James",
"Saint Mary",
"Saint Robert",
"Saint Thomas",
"St Louis",
"St. Charles",
"St. Genevieve",
"St. Joseph"

missing city Surat

Hi,

I can't find the city name Surat(in Gujrat, India) in this list.

Can you please look into it and do the needful?

Thanks,
Vikram

Singapore cities are missing but present in MaxMind DB

The CSV pulled from MaxMind shows that several cities are available from Singapore. However those cities do not have a corresponding state which ended up excluded from the search list.

I was wondering if there are existing workarounds with this scenario. Is there a more future-proof way of dealing with a city without a state?

Missing CS.countries

Im getting this error when trying to get the countries:
undefined method `countries' for CS:Module
I noticed that the method is not there anymore.

Missing Irish Cities

Hi all,

I've used the following as a means to generate all Irish cities,

module MyApp
  class Country
    def initialize(country_code)
      @country_code = country_code
    end

    def cities
      cities = []
      state_keys = get_states.keys
      state_keys.each do |state|
        cities << ::CS.cities(state, @country_code)
      end

      cities.flatten.uniq.sort
    end

    private

    def get_states
      ::CS.get(@country_code)
    end
  end
end

However, this does not seem to be complete?

[1] pry(main)> MyApp::Country.new(:ie).cities
=> ["Abbeydorney",
 "Abbeyfeale",
 "Abbeyleix",
 "Achill",
 "Adare",
 "Allenwood",
 "Annacotty",
 "Ardee",
 "Arklow",
 "Artane",
 "Ashbourne",
 "Ashtown",
 "Athboy",
 "Athenry",
 "Athlone",
 "Athy",
 "Bagenalstown",
 "Bailieborough",
 "Balbriggan",
 "Baldoyle",
 "Ballaghaderreen",
 "Ballina",
 "Ballinagleragh",
 "Ballinalee",
 "Ballinasloe",
 "Ballincollig",
 "Ballinhassig",
 "Ballinrobe",
 "Ballitore",
 "Ballsbridge",
 "Ballyboden",
 "Ballybrittas",
 "Ballydesmond",
 "Ballyduff",
 "Ballyfermot",
 "Ballyjamesduff",
 "Ballymacelligott",
 "Ballymahon",
 "Ballymore Eustace",
 "Ballymun",
 "Ballyshannon",
 "Ballyvaghan",
 "Baltinglass",
 "Bandon",
 "Bantry",
 "Barrack",
 "Beaumont",
 "Belgooly",
 "Bettystown",
 "Birr",
 "Blackpool",
 "Blackrock",
 "Blanchardstown",
 "Blarney",
 "Blessington",
 "Boyle",
 "Bray",
 "Bruff",
 "Bruree",
 "Buncrana",
 "Bunratty",
 "Burren",
 "Cabinteely",
 "Cabra",
 "Caher",
 "Cappoquin",
 "Carbury",
 "Carlow",
 "Carndonagh",
 "Carraroe",
 "Carrick",
 "Carrick on Shannon",
 "Carrick-on-Suir",
 "Carrickmacross",
 "Carrickmines",
 "Carrigaline",
 "Carrigallen",
 "Carrigtohill",
 "Cashel",
 "Castlebar",
 "Castleblayney",
 "Castleknock",
 "Cavan",
 "Celbridge",
 "Clane",
 "Clara",
 "Clarecastle",
 "Claregalway",
 "Claremorris",
 "Clogherhead",
 "Clonakilty",
 "Clondalkin",
 "Clonee",
 "Clonmel",
 "Clonsilla",
 "Clontarf",
 "Cobh",
 "Collinstown",
 "Cork",
 "Crumlin",
 "Dalkey",
 "Delgany",
 "Donabate",
 "Donacarney",
 "Donaghmore",
 "Donegal",
 "Donnybrook",
 "Donore",
 "Douglas",
 "Drogheda",
 "Droichead Nua",
 "Dromahair",
 "Dromore West",
 "Drumcondra",
 "Dublin",
 "Duleek",
 "Dunboyne",
 "Dundalk",
 "Dundrum",
 "Dungarvan",
 "Dunglow",
 "Dunlavin",
 "Dunleer",
 "Dunmanway",
 "Dunshaughlin",
 "Dún Laoghaire",
 "Edenderry",
 "Enfield",
 "Ennis",
 "Enniscorthy",
 "Fermoy",
 "Finglas",
 "Firhouse",
 "Foxford",
 "Foxrock",
 "Galway",
 "Garristown",
 "Glasnevin",
 "Glassan",
 "Glenageary",
 "Gorey",
 "Gort",
 "Granard",
 "Greystones",
 "Harold's Cross",
 "Headford",
 "Howth",
 "Islandbridge",
 "Kanturk",
 "Kells",
 "Kenmare",
 "Kilbarrack",
 "Kilbeggan",
 "Kilbride Cross Roads",
 "Kilcock",
 "Kilcoole",
 "Kildalkey",
 "Kildare",
 "Kilfinane",
 "Kilkee",
 "Kilkenny",
 "Kilkishen",
 "Killaloe",
 "Killarney",
 "Killeshin",
 "Killiney",
 "Killucan",
 "Kilmessan",
 "Kiltamagh",
 "Kingswood",
 "Kinnegad",
 "Kinsale",
 "Kinvarra",
 "Lanesborough",
 "Laytown",
 "Leixlip",
 "Leopardstown",
 "Letterkenny",
 "Lifford",
 "Limerick",
 "Listowel",
 "Longford",
 "Longwood",
 "Loughlinstown",
 "Loughrea",
 "Louth",
 "Lucan",
 "Lusk",
 "Macroom",
 "Malahide",
 "Mallow",
 "Marino",
 "Maynooth",
 "Mayo",
 "Midleton",
 "Mitchelstown",
 "Moate",
 "Monaghan",
 "Monamolin",
 "Monkstown",
 "Mornington",
 "Mountshannon",
 "Moville",
 "Mullingar",
 "Multyfarnham",
 "Naas",
 "Naul",
 "Navan",
 "Nenagh",
 "New Quay",
 "New Ross",
 "Newcastle",
 "Newcastle West",
 "Newmarket",
 "Newport",
 "Nohaval",
 "Oranmore",
 "Oughterard",
 "Ovens",
 "Piltown",
 "Portarlington",
 "Porterstown",
 "Portlaoise",
 "Portmarnock",
 "Portumna",
 "Quin",
 "Raheny",
 "Rath Luirc",
 "Rathanna",
 "Rathcoole",
 "Rathfarnham",
 "Rathmines",
 "Rathmore",
 "Ratoath",
 "Rhode",
 "Ringsend",
 "Riverstown",
 "Rochestown",
 "Rochfortbridge",
 "Roscommon",
 "Roscrea",
 "Rush",
 "Saggart",
 "Sallins",
 "Sandycove",
 "Sandyford",
 "Sandymount",
 "Santry",
 "Shankill",
 "Shannon",
 "Sixmilebridge",
 "Skerries",
 "Slane",
 "Sligo",
 "Spiddal",
 "Stepaside",
 "Stillorgan",
 "Streamstown",
 "Summerhill",
 "Sutton",
 "Swinford",
 "Swords",
 "Taghmon",
 "Tallaght",
 "Templeogue",
 "Terenure",
 "Thurles",
 "Tipperary",
 "Tralee",
 "Tramore",
 "Trim",
 "Tuam",
 "Tullamore",
 "Tullow",
 "Virginia",
 "Waterfall",
 "Waterford",
 "Watergrasshill",
 "Westport",
 "Wexford",
 "Wicklow",
 "Youghal"]

For example, the city/town of Oldcastle is missing, and I'm sure there are many more. Appreciate any advice please.

Trying to make this working with simple_form.

I am using Rails 5 and Bootstrap wth single_forn.
I am able to select the country correctly.
But when I am trying to select a state or a city I am getting only "Toshkent Shari" from Uzbekistan and no city no matter which country I selected.
It may be the case I an not using the right paratemetes in the form to be used by the two scripts I developed based on the models shown in this blog.
He are my application relevant files.

application_controller.rb

class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def index
end
def states
render json: CS.states(params[:country]).to_json
end
def cities
render json: CS.cities(params[:state], params[:country]).to_json
end
end

routes.rb

Rails.application.routes.draw do
resources :contacts
root to: "application#index"

get 'states/:country', to: 'application#states'
get 'cities/:state', to: 'application#cities'
end

_form.rb

<%= simple_form_for(@contact) do |f| %>
<%= f.error_notification %>

<%= f.input :name %>
<%= f.input :country, required: true, hint: 'select country', label: 'Country' do %>
  <%= f.select :country,
    CS.countries.map {|r| [r[1], r[0]] },
    include_blank: false
  %>
<% end %>

<%= f.input :state, required: true, hint: 'select state or province', label: 'State or Province' do %>
  <%= f.select :state,
    CS.states(params[:country]).map {|r| [r[1], r[0]] },
    include_blank: false
  %>
<% end %>

<%= f.input :city, required: true, hint: 'select city', label: 'City' do %>
  <%= f.select :city,
    CS.cities(params[:state], params[:country]).map {|r| [r]},
    include_blank: false
  %>
<% end %>

<%= f.input :address %>
<%= f.input :phone %>
<%= f.input :email %>
<%= f.button :submit %>
<% end %> <script> $('#contact_country').change(function () { var input_country = $(this); var states_of_country = $("#contact_state"); if($(this).val() == "") { states_of_country.html(""); } else { $.getJSON('/states/' + $(this).val(), function (data) { //states_of_country.empty(); var opt = 'Select City'; console.log(data); if(data.length == 0){ } else { data.forEach(function(i) { opt += '' + i + ''; states_of_country.html(opt); }); } }); } }); </script> <script> $('#contact_state').change(function () { var input_state = $(this); var cities_of_state = $("#contact_city"); if($(this).val() == "") { cities_of_state.html(""); } else { $.getJSON('/cities/' + $(this).val(), function (data) { // cities_of_state.empty(); var opt = 'Select City'; console.log(data); if(data.length == 0){ } else { data.forEach(function(i) { opt += '' + i + ''; cities_of_state.html(opt); }); } }); } }); </script>

Due to the use of the simple_form the IDs of the elements in the DOM are "contact_country", "contact_state" and "contact_city"

Any help to fix this is much appreciated.

Ability to query cities by country name in addition to country code

Hey! I'm using this gem, going well so far. I needed to query cities with country name as compared to only being able to query cities with country code, so I've written a small method to do that. Take a look if you find it useful and think it should be merged. Thanks.

How to change db data locally?

Hi, We have a request that Spain should use the more popular provinces, rather than the states in this gem. There are more provinces and apparently it is more useful information for what we are doing. We have a similar request for Hong Kong.

Is there some way for me to easily overwrite? I see in the lib/db folder a file called states_replace.yml

Was that put there for this purpose?

Can we have search

Can we have an api for search as well, where we get these things,

- when city name matches with the key word display city, state, country
- when state name alone matches with the key word display state, country
- when country name alone matches with the key word display country

Say, when I search for 'Ind' I expect the following results,

    - "Ananindeua,Para,Brazil"
    - "Olinda,Pernambuco,Brazil"
    - "Gindou,Midi-Pyrenees,France"
    - "India"
    - "Indore,Madhya Pradesh,India"
    - "Windsor,Connecticut,USA"
    - "Indiana,Pennsylvania,USA"
    - "Indiana,USA"

CS.search('Ind')
When no additional parameters is given it would search in all (cities, states and countries).

We can have additional parameters as well like,

CS.search('Ind', :country) will search only in countries
CS.search('Ind', :state) will search only in states
CS.search('Ind', :city) will search only in cities
CS.search('Ind', :country, :state) will search only in states and countries
CS.search('Ind', :country, :city) will search only in cities and countries
CS.search('Ind', :city, :state) will search only in states and cities

Missing cities

Hello guys, I see that we are missing few cities from the database. For example:

Florida
missing : coconut creek, coral springs, margate, just to list a few.

What is the best way to add them?

thanks

Invalid data for GB

This gem returns completely invalid data for GB:

irb(main):001:0> CS.get(:gb)
{:ENG=>"England",
 :KEN=>"Kent",
 :LND=>"City of London",
 :NIR=>"Northern Ireland",
 :SCT=>"Scotland",
 :SOM=>"Somerset",
 :SRY=>"Surrey",
 :WLS=>"Wales"}

It returns a mixture of counties, local government, countries and provinces. It should probably refer to ISO 3166-2:GB, and return the codes for what that considers countries and provinces.

Adding a missing city is not working properly

I'm having an issue while adding a missing city.

The first one is that is raising an error but I opened a PR for that: #66

The second one is that when I add a missing city, if I try to find cities for a state other the one that I added, it does not load the city. It only loads the new city if I call .cities first for the state that I'm adding the missing record.

Example:

  • Add the following file: db/cities-lookup.yml
BR:
  GO:
    "Mutunópolis": "Mutunópolis"

If I load first cities for other state, it does not include this missing city:

bin/rails c
CS.cities(:sp, :br) # loading another state first
CS.cities(:go, :br).include?("Mutunópolis")

#> false

returned false but it should be true.

If I load this state first, it works correctly

bin/rails c
CS.cities(:go, :br).include?("Mutunópolis")

#> true

do u folks have any idea why this is happening? Thanks

Invalid cities are rendered

I tried in my rails console CS.cities(:rj, :in) it renders me ["Ajmer", "Alwar", "Amer", "Amet", "Balana", "Bali", "Banswara", "Barmer", "Beawar", "Bharatpur", "Bhilwara", "Bikaner", "Binavas", "Bundi", "Charu", "Chetan", "Chhabra", "Dipas", "Ganganagar", "Gangapur", "Gangrar", "Jaipur", "Jaisalmer", "Jhalawar", "Jhunjhunun", "Jodhpur", "Kalan", "Kanakpura", "Khan", "Khinwara", "Kishangarh", "Kolayat", "Kota", "Lamba Harisingh", "Mahajan", "Mahatma", "Mandal", "Manna", "Mount Abu", "Nagar", "Nagaur", "Nanda", "Naraina", "Nathdwara", "Pali", "Pilani", "Pitampura", "Pushkar", "Rana", "Roshan", "Shiv", "Sikar", "Sirohi", "Sojat", "Sultan", "Surana", "Suratgarh", "Thali", "Tonk", "Udaipur"]
where as no such cities like chetan, Roshan, Mahatma, Khan etc. are not exist in rajasthan and some name like Shiv, Balana, Bali, Binavas, Dipas etc are small town/village in cities of rajasthan.

Get the list of countries

Hi,
This gem is vey much helpful to me.
But I wanted to know the list of countires. Is there a method to get the complete list of countries so that I can use that.
Because to get the states I need to pass the country code hence to get the country code I need the countries list.
Thank you in Advance.

NoMethodError (undefined method `set_license_key' for CS:Module)

  1. I want to update the db of citie state by following the guide.

MaxMind update their databases weekly on Tuesdays.

Since Dec 30, 2019, MaxMind requires a license key (for free) to get download updates.

To get the license key:

Sign up for a MaxMind account: https://www.maxmind.com/en/geolite2/signup
Create a license key: https://www.maxmind.com/en/accounts/current/license-key
There's no need to download anything.

To update.
CS.set_license_key('MY_KEY')

CS.update

and while doing this getting error of undefined method.
2.6.5 :002 > CS.set_license_key Traceback (most recent call last): 2: from (irb):2 1: from (irb):2:in rescue in irb_binding'
NoMethodError (undefined method set_license_key' for CS:Module)

Not working with ruby 3.2

if ! File.exists? condition throws an error in the Ruby version later or equal 3.2.0

I was running it in Rails 7.0.4 and the Rails Console suggests Did you mean? exist?

Missing US cities

I am not getting any US cities.

[16] pry(main)> CS.cities(:us)
[]

[23] pry(main)> CS.cities(:ms)
[
    [  0] "Abbeville",
    [  1] "Aberdeen",
    [  2] "Ackerman",
    [  3] "Amory",
    [  4] "Anguilla",
    [  5] "Ashland",
    [  6] "Bailey",
    ............

"No such file or directory @ rb_sysopen <url>" when attempting update

When executing CS.update, I receive the following error:

No such file or directory @ rb_sysopen - https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&license_key=redacted&suffix=zip (Errno::ENOENT)    

The update_maxmind method is using OpenURI as just open(), which is an override of Kernel#open, but such use was deprecated in Ruby 2.7.

This was changed in OpenURI in Commit #0c2986a, roughly a year before the current v0.2.0 was released.

The solution here is to either:

  • Require Ruby <= v2.5 and lock dependency on 'open-uri' gem to v0.1.0
  • Or update Line 42 to use URI.open() instead of just open()

States are not listing as it is trying to require /lib/db/states.in

Dear Author,
I have installed the city-state (0.0.11) and tried to load countries and its loading but states are not loading as in my system I am getting the following issue.

Errno::EACCES: Permission denied - /home/bitla-b10/.rvm/gems/ruby-1.9.3-p547/gems/city-state-0.0.11/lib/db/states.in
from /home/bitla-b10/.rvm/gems/ruby-1.9.3-p547/gems/city-state-0.0.11/lib/city-state.rb:104:in `initialize'

It seems its requiring some missed files.

Thanks in Advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.