ZIP Demographics API - Ruby Gem
ZIP Demographics provides detailed demographic data for any US ZIP code including population, income, education, housing, employment, and racial composition from the US Census American Community Survey.
Installation
Add this line to your application's Gemfile:
gem 'apiverve_zipdemographics'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install apiverve_zipdemographics
Getting Started
Get your API key at APIVerve
Basic Usage
require 'apiverve_zipdemographics'
# Initialize the client
client = APIVerve::Zipdemographics::Client.new(api_key: "YOUR_API_KEY")
# Make a request
response = client.execute({ zip: "90210" })
# Print the response
puts response
Error Handling
begin
response = client.execute({ zip: "90210" })
puts response["data"]
rescue APIVerve::Zipdemographics::ValidationError => e
puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Zipdemographics::APIError => e
puts "API error: #{e.}"
puts "Status code: #{e.status_code}"
end
Debug Mode
# Enable debug logging
client = APIVerve::Zipdemographics::Client.new(
api_key: "YOUR_API_KEY",
debug: true
)
Example Response
{
"status": "ok",
"error": null,
"data": {
"zip": "90210",
"name": "ZCTA5 90210",
"acsYear": 2022,
"population": {
"total": 21741,
"male": 10234,
"female": 11507,
"medianAge": 45.3
},
"income": {
"medianHousehold": 153891,
"perCapita": 98234
},
"housing": {
"medianHomeValue": 2875000,
"medianRent": 3250,
"totalUnits": 10234,
"homeOwnershipRate": 63.2
},
"education": {
"collegeEducatedPct": 72.4
},
"employment": {
"laborForce": 11234,
"unemploymentRate": 3.8
},
"race": {
"white": {
"count": 16892,
"percent": 77.7
},
"asian": {
"count": 2345,
"percent": 10.8
}
},
"formatted": {
"medianHouseholdIncome": "$153,891",
"perCapitaIncome": "$98,234",
"medianHomeValue": "$2,875,000",
"medianRent": "$3,250"
}
}
}
Documentation
For more information, visit the API Documentation.
Support
- Website: https://apiverve.com/marketplace/zipdemographics?utm_source=ruby&utm_medium=readme
- Email: hello@apiverve.com
License
This gem is available under the MIT License.