Normalize a Street Address in Ruby

Cloudmersive
2 min readJun 23, 2021

Normalizing a street address is not an enjoyable task to perform manually, especially if you are pulling the data and inputting it into a spreadsheet or file. By utilizing the following API in Ruby, you can automatically normalize, parse, and validate a structured street address; it will even return the location coordinates as a bonus.

To perform the operation in Ruby, you will first need to add the client to your Gemfile:

gem 'cloudmersive-validate-api-client', '~> 2.1.6'

Then, you can call the function:

# load the gem
require 'cloudmersive-validate-api-client'
# setup authorization
CloudmersiveValidateApiClient.configure do |config|
# Configure API key authorization: Apikey
config.api_key['Apikey'] = 'YOUR API KEY'
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
#config.api_key_prefix['Apikey'] = 'Bearer'
end
api_instance = CloudmersiveValidateApiClient::AddressApi.newinput = CloudmersiveValidateApiClient::ValidateAddressRequest.new # ValidateAddressRequest | Input parse requestbegin
#Normalize a street address
result = api_instance.address_normalize_address(input)
p result
rescue CloudmersiveValidateApiClient::ApiError => e
puts "Exception when calling AddressApi->address_normalize_address: #{e}"
end

This will return objects containing the building type, street number, street, city, state/province, postal code, country name/code, and the latitude and longitude. You can retrieve the API key by registering for a free account on the Cloudmersive website; this will provide you with 800 monthly calls across our library of APIs.

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.