Cities Lookup API - Ruby Gem
Cities Lookup is a simple tool for looking up city data. It returns the city name, population, and more.
Installation
Add this line to your application's Gemfile:
gem 'apiverve_citieslookup'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install apiverve_citieslookup
Getting Started
Get your API key at APIVerve
Basic Usage
require 'apiverve_citieslookup'
# Initialize the client
client = APIVerve::Citieslookup::Client.new(api_key: "YOUR_API_KEY")
# Make a request
response = client.execute({
city: "San Francisco",
limit: 1
})
# Print the response
puts response
Error Handling
begin
response = client.execute({ city: "San Francisco", limit: 1 })
puts response["data"]
rescue APIVerve::Citieslookup::ValidationError => e
puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Citieslookup::APIError => e
puts "API error: #{e.}"
puts "Status code: #{e.status_code}"
end
Debug Mode
# Enable debug logging
client = APIVerve::Citieslookup::Client.new(
api_key: "YOUR_API_KEY",
debug: true
)
Example Response
{
"status": "ok",
"error": null,
"data": {
"search": "San Francisco",
"foundCities": [
{
"name": "San Francisco",
"altName": "",
"country": "US",
"countryName": "United States",
"featureCode": "PPLA2",
"population": 874961,
"populationCategory": "major",
"loc": {
"type": "Point",
"coordinates": [
-122.4194,
37.7749
]
}
}
]
}
}
Documentation
For more information, visit the API Documentation.
Support
- Website: https://apiverve.com/marketplace/citieslookup?utm_source=ruby&utm_medium=readme
- Email: hello@apiverve.com
License
This gem is available under the MIT License.