This is the Ruby client for LuaDNS REST API.
Add to Gemfile
gem "luadns", "~> 0.1"
Initialize the client using the account email and API key:
require "luadns"
# Init the client with your email and API key.
client = Luadns::Client.new("joe@example.com", "api_key")
Getting current user:
client.users.me
Working with zones:
# List current zones
client.zones.list_zones
# Create a new zone
client.zones.create_zone({name: "example.dev"})
# Get a zone
client.zones.get_zone(zone_id)
# Update a zone
client.zones.update_zone(zone.id, attributes)
# Delete a zone
client.zones.delete_zone(zone.id)
Working with records:
# List zone records
client.records.list_records
# Create a new record
client.records.create_record(zone, {
name: "example.org.",
type: "TXT",
content: "Hello, world!",
ttl: 3600
})
# Get a record
client.records.get_record(zone, record_id)
# Update a record
client.records.update_record(zone, record.id, {
name: "example.org.",
type: "TXT",
content: "Aloha!",
ttl: 3600
})
# Delete a record
client.records.delete_record(zone, record.id)
The API requests are rate-limited,
the request should be retried later when Luadns::RateLimitError
is raised:
begin
client.list_zones
rescue Luadns::RateLimitError => e
sleep e.reset_in
retry
end
The library can be initialized using ENV variables from a Rails initializer.
Example:
# config/initializers/luadns.rb
Luadns.configure do |config|
config.username = ENV['LUADNS_USERNAME']
config.password = ENV['LUADNS_API_KEY']
end
Be sure to visit the LuadDNS official documentation website for additional information about our API.