Ideal Postcodes Ruby SDK
ideal_postcodes calls the Ideal Postcodes UK address API from Ruby 3.3 or later, with one method per operation and no runtime dependencies.
Use the ak_test key for limited testing. It is capped at 5 requests per day. A new account comes with a free test balance for fuller testing.
gem install ideal_postcodes
require "ideal_postcodes"
client = IdealPostcodes::Client.new(api_key: "ak_test")
response = client.find_address(query: "9 Malyons Road")
response.result.hits.each { |hit| puts hit.suggestion }
Each API operation is one method on the client, named from its operation ID, such as postcodes or find_address. Path parameters are positional and everything else is a keyword argument. Every method returns an object built from the API response.
Data sources
UK addresses come from Royal Mail's Postcode Address File (PAF) and Ordnance Survey AddressBase, depending on the datasets on your key. Each address carries a dataset field naming its source, such as paf or abp. Its native record holds the raw fields from that source.
Features
- No dependencies. The SDK sends requests with Net::HTTP and parses them with the standard library's JSON. To use another HTTP client, pass your own transport.
- Generated from the OpenAPI spec. Every response is an object with one reader per field. Every dataset's native record has its own class, from
PafAddresstoUspsAddress. - Every current API operation. Address search, postcode lookup, UPRN lookup, autocomplete, address cleanse, places, email and phone validation, plus key, licensee and configuration management. Each one has its own reference page.
- RBS signatures. The gem ships a signature for every method and reader, for Steep, Ruby LSP and other tools that read RBS.
Coding agents
- Agent skill.
npx skills add ideal-postcodes/skillsinstalls theideal-postcodes-ruby-sdkskill, built from these pages. - Endpoints. Every operation, grouped by API area, with its parameters, response class and a tested example.
- Markdown pages. Add
.mdto any page URL for plain markdown, such as/docs/sdks/ruby/errors.md. - llms.txt. An index of every page on this site.
- OpenAPI spec. The API contract the SDK is generated from.
- Build with AI. Every asset for AI agents.
Authentication
Pass your API key to IdealPostcodes::Client.new as api_key:. Key, licensee and configuration operations also need a Management Key, passed as management_key:. Keep the Management Key on your server. See setup.
Errors
An HTTP error raises IdealPostcodes::ApiError with the HTTP status and the API error code and message. A failed connection raises IdealPostcodes::TransportError. Both inherit from IdealPostcodes::Error, so one rescue covers the SDK. See error handling.
Upgrading from 2.x
Version 3 is a new client. The old IdealPostcodes.api_key = setting and module methods such as IdealPostcodes::Postcode.lookup are gone: create a client and call its methods instead. Responses are objects with readers, not hashes, though to_h returns the hash and [] reads a field by its API name. AuthenticationError, TokenExhaustedError and the other 2.x error classes give way to one IdealPostcodes::ApiError, whose code says which error the API returned. Version 3 needs Ruby 3.3 or later.