Skip to content

Latest commit

 

History

History

ruby

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

Zip Codes Lookup API - Ruby Gem

Zip Codes Lookup finds all postal codes within a US city or resolves a five-digit ZIP code to its city and state. Paid plans add the IANA time zone, geographic coordinates and the distance from the ZIP to a second ZIP.

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",
  distanceTo: "64106"
})

# Print the response
puts response

Error Handling

begin
  response = client.execute({ zip: "64082", distanceTo: "64106" })
  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",
    "timezone": "America/Chicago",
    "distance": {
      "zipcode": "64106",
      "city": "Kansas City",
      "state_abbr": "MO",
      "miles": 19.94,
      "kilometers": 32.09
    }
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.