The project is in a healthy, maintained state
A Ruby gem to search postal codes across 100+ countries via the PLZ API. Supports authentication, postal code search, and country listing.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 2.0
~> 13.0
~> 3.0
~> 1.0
~> 3.0
 Project Readme

PostalCodesRubyClient

Ruby-Client-Gem für die PLZ API – Postleitzahlen-Suche über 100+ Länder.

Installation

# Gemfile
gem "postal_codes_ruby_client", path: "../postal_codes_ruby_client"

Oder als lokales Gem:

cd postal_codes_ruby_client
gem build postal_codes_ruby_client.gemspec
gem install postal_codes_ruby_client-0.1.0.gem

Konfiguration

require "postal_codes_ruby_client"

PostalCodesRubyClient.configure do |config|
  config.base_url  = "http://localhost:3000"  # Standard
  config.api_token = "dein_api_token"
  config.timeout   = 30                       # Sekunden (Standard)
end

Verwendung

Client erstellen

# Globale Konfiguration nutzen
client = PostalCodesRubyClient::Client.new

# Oder Token direkt übergeben
client = PostalCodesRubyClient::Client.new(
  api_token: "dein_api_token",
  base_url: "https://api.example.com"
)
# PLZ-Suche (Teilsuche möglich)
results = client.postal_codes.search(q: "803", country: "DE")
results[:results].each do |pc|
  puts "#{pc[:zipcode]} #{pc[:place]} (#{pc[:state]})"
end

# Suche ohne Länderfilter
results = client.postal_codes.search(q: "1010", limit: 10)

# Verfügbare Länder auflisten
countries = client.postal_codes.countries
puts countries[:countries].join(", ")

Fehlerbehandlung

begin
  client.postal_codes.search(q: "803")
rescue PostalCodesRubyClient::AuthenticationError => e
  puts "Nicht autorisiert: #{e.message}"
rescue PostalCodesRubyClient::ValidationError => e
  puts "Validierungsfehler: #{e.errors.join(', ')}"
rescue PostalCodesRubyClient::ApiError => e
  puts "API-Fehler (#{e.status}): #{e.message}"
rescue PostalCodesRubyClient::Error => e
  puts "Fehler: #{e.message}"
end

API-Referenz

Methode Beschreibung
client.postal_codes.search(q:, country:, limit:) PLZ-Suche
client.postal_codes.countries Verfügbare Länder