Zip Codes Lookup API - Ruby Gem

Zip Codes Lookup is a simple tool for looking up the zip codes of a city. It returns the zip codes of the city.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_zipcodes'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_zipcodes

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_zipcodes'

# Initialize the client
client = APIVerve::Zipcodes::Client.new(api_key: "YOUR_API_KEY")

# Make a request
response = client.execute({ zip: "64082" })

# Print the response
puts response

Error Handling

begin
  response = client.execute({ zip: "64082" })
  puts response["data"]
rescue APIVerve::Zipcodes::ValidationError => e
  puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Zipcodes::APIError => e
  puts "API error: #{e.message}"
  puts "Status code: #{e.status_code}"
end

Debug Mode

# Enable debug logging
client = APIVerve::Zipcodes::Client.new(
  api_key: "YOUR_API_KEY",
  debug: true
)

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "zipcode": "64082",
    "state_abbr": "MO",
    "latitude": "38.850243",
    "longitude": "-94.39570",
    "city": "Lees Summit",
    "state": "Missouri"
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.