pdns-ruby
A simple Ruby client for the PowerDNS HTTP API. Zero dependencies beyond Ruby's standard library.
Installation
gem 'pdns-ruby'Usage
require 'pdns_ruby'
client = PdnsRuby::Client.new(
host: 'http://localhost:8081',
api_key: 'your-api-key'
)Zones
# list all zones
client.zones
# get a zone
zone = client.zone('example.com')
# check if zone exists
client.zone_exists?('example.com')
# create a zone
zone = client.create_zone('example.com', nameservers: ['ns1.example.com', 'ns2.example.com'])
# delete a zone
client.delete_zone('example.com')
# or
zone.delete!Records
zone = client.zone('example.com')
# add/update a record
zone.add_record('www.example.com.', 'A', '1.2.3.4', ttl: 3600)
# add MX record
zone.add_record('example.com.', 'MX', '10 mail.example.com.', ttl: 3600)
# delete a record
zone.delete_record('www.example.com.', 'A')
# get all rrsets
zone.rrsets
# find specific rrset
zone.find_rrset('www.example.com.', 'A')Batch Updates
rrsets = [
PdnsRuby::Rrset.replace(
name: 'www.example.com.',
type: 'A',
ttl: 3600,
records: [{ content: '1.2.3.4' }, { content: '5.6.7.8' }]
),
PdnsRuby::Rrset.delete(
name: 'old.example.com.',
type: 'CNAME'
)
]
client.update_rrsets('example.com', rrsets)Error Handling
begin
client.zone('nonexistent.com')
rescue PdnsRuby::NotFoundError => e
puts "Zone not found"
rescue PdnsRuby::AuthError => e
puts "Invalid API key"
rescue PdnsRuby::ApiError => e
puts "API error: #{e.message}"
endFeatures
- Zero external dependencies — uses only Ruby's
net/httpandjson - Zone management (list, get, create, delete)
- Record management via rrsets (add, update, delete, batch)
- Automatic trailing dot normalization for domain names
- Typed error classes for easy error handling
- Works with PowerDNS 4.x API
License
MIT