Skip to content
raymond-wells edited this page Feb 17, 2015 · 9 revisions

Official Zerigo DNS Gem

Welcome to the wiki of the Official Zerigo DNS Gem.

Changes from 1.0.0

You can no longer use password in the configuration to set the API key.

ActiveResource is no longer used; these things have changed:

  • #find(:all, ...) becomes #all(...)
  • #save becomes #update(field: "new_value").
  • Any status code not 200-299 or 302 will raise an exception (e.g. 422 errors returned by posting bad data or 404 errors).
  • update/destroy methods called on the class return a Faraday::Response, and will throw exceptions when the operation fails.

Getting Started

Configuring the gem

In your gemfile, put:

gem 'zerigodns', version: '~> 1.1.0'

Before using the gem, you will need to configure it with your account's e-mail address and API key:

require 'zerigodns'

ZerigoDNS.configure do |config|
  config.user = 'you@email.com'
  config.api_key = 'yourtokengoeshere'
end

Basic Operations

Creating a zone

domain = ZerigoDNS::Zone.create(domain: 'yourdomain.com', ns_type: 'pri_sec')

Deleting a zone

domain.destroy

Additionally, you can delete a zone by id:

ZerigoDNS::Zone.destroy(zone_id)

Creating a host record

Assuming domain is a zone

host = ZerigoDNS::Host.create(zone_id: domain.id, hostname: 'www', host_type: 'A', ttl: 86400, data: '10.10.10.10')

Updating a host record

Using update_or_create

Assuming host is a host record.

#                                      hostname type ttl     data
Host.update_or_create(domain, 'www', 'A', 86400, '10.10.10.10')

caveat: The host record updated will be the first host record found by its fully qualified domain name. If multiple records exist, only one will be updated.

Handling multiple host records with the same hostname

If you have mulitple host records with the same hostname, you can narrow them down by locating a specific record by IP address.

hosts = Host.find_all_by_hostname(zone, 'www')
host = hosts.detect{|h| h.data == '10.10.10.10'}
host.update data: '10.10.10.11'

Finding a host record

Using Host.find_all_by_hostname

Assuming domain is a zone

@hosts = Host.find_all_by_hostname(domain, 'www')

You can then search through @hosts to find the desired host record.

Deleting a host record

host.destroy

Also, you can delete a host by id:

ZerigoDNS::Host.destroy(host_id)

Using Zone Templates

You can use zone templates to manage similar configurations on different domains.

Creating a Zone Template

template = ZerigoDNS::ZoneTemplate.create(custom_ns: false, default_ttl: 900, ns_type: 'pri_sec', name: 'my-template')

Creating a Host Template

This will create an ALIAS record which points to the domain's www record. Any @ symbol in the data will be replaced with the actual domain name.

host_template = template.create_host_template(data: 'www.@', hostname: nil, host_type: 'ALIAS')

Creating a domain from a zone template

zone = template.create_zone(domain: 'mydomain.com')

This will create a zone which will automatically sync with changes to the zone template.

Contributing

It's easy, just fork the repository, create a feature branch, then when you are ready, create a pull request. If you are proposing a new feature, feel free to create an issue first so we can give you feedback.

Full Reference

You can find the full documentation on RubyDoc.info.