Gem Version Build Status Maintainability Test Coverage

DnsMadeEasy — Ruby Client API (Supporting SDK V2.0)

This is a fully featured REST API client for DnsMadeEasy provider. DME is an excellent provider, and is highly recommended for their ease of use, very solid API, and great customer support. They also offer free DNS failover with business accounts, which is highly recommended for the arrays of load balancers in front of your app.


DnsMadeEasy allows you to fetch, create, update DNS records, as long as you know your API key and the secret.

Setting up Credentials

You can find your API Key and Secret on the Account Settings Page of their UI.

Once you have the key and the secret, you have several choices:

  1. You can directly instantiate a new instance of the Client class, by passing your API key and API secrets as arguments:

      require 'dnsmadeeasy'
      @client =, api_secret)
  2. Or, you can use the DnsMadeEasy.configure method to configure the key/secret pair, and then use DnsMadeEasy namespace to call the methods:

     require 'dnsmadeeasy'
     DnsMadeEasy.configure do |config|
       config.api_key = 'XXXX'
       config.api_secret = 'YYYY'
 #=> ''     
  3. Configuring API keys as above is easy, and can be done using environment variables. Alternatively, it may be convenient to store credentials in a YAML file.

 * If filename is not specified, there is default location where this file is searched, which is `~/.dnsmadeeasy/credentials.yml`.
 * If filename is provided, it will be read, and must conform to the following format:

 **Simple Credentials Format**

  # file: ~/.dnsmadeeasy/credentials.yml
      api_key: 2062259f-f666b17-b1fa3b48-042ad4030
      api_secret: 2265bc3-e31ead-95b286312e-c215b6a0

 **Multi-Account Credentials Format**

 Below you see two accounts, with production key and secret being encrypted. See [further below](#encryption) about encrypting your key and secrets.

    - name: development
      default_account: true
        api_key: 12345678-a8f8-4466-ffff-2324aaaa9098
        api_secret: 43009899-abcc-ffcc-eeee-09f809808098
    - name: production
        api_key: "BAhTOh1TeW06OkRhdGE6OldyYXBwZXJT............"
        api_secret: "BAhTOh1TeW06OkRhdGE6OldyYXBwZ............"
        encryption_key: spec/fixtures/sym.key

 You can use the following method to access both simple and multi-account YAML configurations:

 require 'dnsmadeeasy'
 DnsMadeEasy.configure_from_file(file, account = nil, encryption_key = nil)

 # for example:
 DnsMadeEasy.configure_from_file('config/dme.yaml', 'production') #=> [ ... ]

 # or with encrypted key passed as an argument to decrypt YAML values:
  1. Finally, you can use DME.credentials_from_file method that, unlike the method above, uses hash arguments:

     @creds = DnsMadeEasy.credentials_from_file(file: 'my-creds.yml', 
                                             account: 'production', 
                                      encryption_key: 'MY_KEY')
     @creds.api_key    # => ...
     @creds.api_secret # => ...

    Method above simply returns the credentials instance, but does not "save" it as the default credentials like configure_from_file. Therefore, if you need to access multiple accounts at the same time, this method will help you maintain multiple credentials at the same time.

Once you configure the keys, you can also use the shortcut module to save you some typing:

require 'dnsmadeeasy/dme' #=> ''

This has the advantage of being much shorter, but might conflict with existing modules in your Ruby VM. In this case, just do not require dnsmadeeasy/dme and only require dnsmadeeasy, and you'll be fine. Otherwise, using DME is identical to using DnsMadeEasy, assuming you required dnsmadeeasy/dme file.

Which Namespace to Use? What is DME versus DnsMadeEasy?

Since DnsMadeEasy is a bit of a mouthful, we decided to offer (in addition to the standard DnsMadeEasy namespace) the abbreviated module DME that simply forwards all messages to the module DnsMadeEasy. If in your Ruby VM there is no conflicting top-level class DME, then you can require 'dnsmadeeasy/dme' to get all of the DnsMadeEasy client library functionality without having to type the full name once. You can even do require 'dme'.

Whenever you require dme you also import the DnsMadeEasy namespace. The opposite is not true.

So if you DO have a name clash with another top-level module DME, simply do require 'dnsmadeeasy' and none of the DME module namespace will be loaded.

In a nutshell you have three ways to access all methods provided by the DnsMadeEasy::Api::Client class:

  1. Instantiate and use the client class directly,
  2. Use the top-level module DnsMadeEasy with require 'dnsmadeeasy'
  3. Use the shortened top-level module DME with require 'dnsmadeeasy/dme'


Whether or not you are accessing a single account or multiple, it is recommended that you save your credentials (the API key and the secret) encrypted in the above mentioned file ~/.dnsmadeeasy/credentials.yml (or any file of you preference).


  • DO NOT check that file into your repo!
  • If you use encryption, do not check in your key!

The examples that follow assume credentials have already been configured, and so we explore the API.

Using the DME module (or DnsMadeEasy if you prefer) you can access all of your records through the available API method calls, for example:

IRB > require 'dme' #=> true
# Or you can also do
IRB > require 'dnsmadeeasy/dme' #=> true
 ⤷ ["",

# These have been read from the file ~/.dnsmadeeasy/credentials.yml
IRB > DME.api_key
 ⤷ "2062259f-f666b17-b1fa3b48-042ad4030"

IRB > DME.api_secret
 ⤷ "2265bc3-e31ead-95b286312e-c215b6a0"

IRB > DME.domain('').delegateNameServers
 ⤷ #<Hashie::Array ["", "", ""]>

# Let's inspect the Client — after all, all methods are simply delegated to it:
IRB > @client = DME.client
 ⤷ #<DnsMadeEasy::Api::Client:0x00007fb6b416a4c8

Next, let's fetch a particular domain, get it's records and compute the counts for each record type, such as 'A', 'NS', etc.

IRB > records = DME.records_for('')
IRB > [ records.totalPages, records.totalRecords ]
 ⤷ [1, 33]
IRB >{|f| f.type == 'A' }.map(&:name)
 ⤷ ["www", "vpn-us-east1", "vpn-us-east2", "staging", "yourmom"]
IRB > types =
 ⤷ [....]
IRB > require 'awesome_print' 
IRB > ap Hash[types.group_by {|x| x}.map {|k,v| [k,v.count]}]
       "MX" => 2,
      "TXT" => 1,
    "CNAME" => 3,
       "NS" => 22,
        "A" => 5

Return Value Types

All public methods of this library return a Hash-like object, that is actually an instance of the class Hashie::Mash. Hashie::Mash supports the very useful ability to reach deeply nested hash values via a chain of method calls instead of using a train of square brackets. You can always convert it to a regular hash either to_hash or to_h on an instance of a Hashie::Mash to get a pure hash representation.

NOTE: to_hash converts the entire object to a regular hash, including the deeply nested hashes, while to_h only converts the primary object, but not the nested hashes. Here is an example below — in the first instance where we call to_h we are still able to call .value on the nested object, because only the top-level Mash has been converted into a Hash. In the second example, this call fails, because this method does not exist, and the value must be accessed via the square brackets:

IRB > recs.to_h['data'].last.value
IRB > recs.to_hash['data'].last.value
"NoMethodError: undefined method `value` for #<Hash:0x00007fe36fab0f68>"
IRB > recs.to_hash['data'].last['value']

For more information on the actual JSON API, please refer to the following PDF document.

Available Actions

Here is the complete of all methods supported by the DnsMadeEasy::Api::Client:


  • create_domain
  • create_domains
  • delete_domain
  • domain
  • domains
  • get_id_by_domain


  • records_for
  • all
  • base_uri
  • create_a_record
  • create_aaaa_record
  • create_cname_record
  • create_httpred_record
  • create_mx_record
  • create_ns_record
  • create_ptr_record
  • create_record
  • create_spf_record
  • create_srv_record
  • create_txt_record
  • delete_all_records
  • delete_record
  • delete_records
  • find_all
  • find_first
  • find_record_ids


It was mentioned above that the credentials YAML file may contain encrypted values. This facility is provided by the encryption gem Sym.

In order to encrypt your values, you need to perform the following steps:

gem install sym

# let's generate a new key and save it to a file:
sym -g -o my.key

# if you are on Mac OS-X, you can import the key into the KeyChain.
# this creates an entry in the keychain named 'my.key' that can be used later.
sym -g -x my.key

Once you have the key generated, first, make sure to never commit this to any repo!. You can use 1Password for it, or something like that.

Let's encrypt our actual API key:

sym -ck my.key -e -s "${api_key}"
# => prints the encrypted value

# On a mac, you can copy it to clipboard:
sym -ck my.key -e -s "${api_secret}" | pbcopy

Now, you place the encrypted values in the YAML file, and you can save "my.key" as the value against encryption_key: at the same level as the api_key and api_secret in the YAML file. This value can either point to a file path, or be a keychain name, or even a name of an environment variable. For full details, please see sym documentation.

CLI Client

This library offers a simple CLI client dme that maps the command line arguments to method arguments for corresponding actions:

❯ dme --help
  # Execute an API call:
  dme [ --json | --yaml ] operation [ arg1 arg2 ... ]

  # Print suported operations:
  dme op[erations]

  Store your credentials in a YAML file
  /Users/kig/.dnsmadeeasy/credentials.yml as follows:

    api_key: XXXX
    api_secret: YYYY

   dme domain
   dme --json domain
   dme find_all A www
   dme find_first CNAME vpn-west
   dme --yaml find_first CNAME vpn-west

You can run dme operations to see the supported list of operations:

❯ dme op
  Checkout the README and RubyDoc for the arguments to each operation,
  which is basically a method on a DnsMadeEasy::Api::Client instance.

Valid Operations Are:

For example:

❯ dme domains

is equivalent to""). You can use any operation listed above, and output the result in either YAML or JSON (in addition to the default "awesome_print"), for example:

❯ dme --yaml find_all www CNAME
- dynamicDns: false
  failed: false
  gtdLocation: DEFAULT
  hardLink: false
  ttl: 60
  failover: false
  monitor: false
  sourceId: 5861234
  source: 1
  name: www
  id: 43509989
  type: CNAME

Managing Domains

NOTE: below we can be using @client instantiated with given key and secret, or DME or DnsMadeEasy module.

To retrieve all domains:

require 'dnsmadeeasy/dme'

To retreive the id of a domain by the domain name:


To retrieve the full domain record by domain name:


To create a domain:

# Multiple domains can be created by:

To delete a domain:

DME.delete_domain        ('')

Managing Records

To retrieve all records for a given domain name:


To find the record id for a given domain, name, and type:

This finds all of the IDs matching '' type 'A':

DME.find_record_ids      ('', 'woah', 'A')
# => [ 234234, 2342345 ]
# To delete a record by domain name and record id (the record id can be retrieved from `find_record_id`:
DME.delete_record        ('', 123)
# To delete multiple records:
DME.delete_records       ('', [123, 143])
# To delete all records in the domain:
DME.delete_all_records   ('')

To create records of various types:

# The generic method:
DME.create_record        ('', 'woah', 'A', '', { 'ttl' => '60' })

# Specialized methods:
DME.create_a_record      ('', 'woah', '', {})
DME.create_aaaa_record   ('', 'woah', '', {})
DME.create_ptr_record    ('', 'woah', '', {})
DME.create_txt_record    ('', 'woah', '', {})
DME.create_cname_record  ('', 'woah', '', {})
DME.create_ns_record     ('', 'woah', '', {})
DME.create_spf_record    ('', 'woah', '', {})

Specialized Record Types

Below are the method calls for MX, SRV, and HTTPRED types:

# Arguments are: domain_name, name, priority, value, options = {}
DME.create_mx_record     ('', 'woah', 5, '', {})
# Arguments are: domain_name, name, priority, weight, port, value, options = {}
DME.create_srv_record    ('', 'woah', 1, 5, 80, '', {})
# Arguments are: domain_name, name, value, redirectType, 
DME.create_httpred_record('', 'woah', '', 'STANDARD - 302',
                               # description, keywords, title, options = {}
                              'a description', 'keywords', 'a title', {})

To update a record:

DME.update_record('', 123, 'woah', 'A', '',  { 'ttl' => '60' })

To update several records:

    { 'id'   => 123,
      'name' => 'buddy',
      'type' => 'A',
      'value'=> ''
  ], { 'ttl' => '60' })

To get the number of API requests remaining after a call:

#=> 19898

NOTE: Information is not available until an API call has been made

To get the API request total limit after a call:

#=> 2342

NOTE: Information is not available until an API call has been made


Add this line to your application's Gemfile:

gem 'dnsmadeeasy'

And then execute:

$ bundle

Or install it yourself:

$ gem install dnsmadeeasy


After checking out the repo, run bin/setup to install dependencies. Then, run bundle exe rspec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, up date the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to


The current maintainer Konstantin Gredeskoul wishes to thank:

  • Arnoud Vermeer for the original dnsmadeeasy-rest-api gem
  • Andre Arko, Paul Henry, James Hart formerly of Wanelo fame, for bringing the REST API gem up to the level.
  • Phil Cohen, who graciously transferred the ownership of the name of this gem on to the current maintainer.


Bug reports and pull requests are welcome on GitHub at


The gem is available as open source under the terms of the MIT License.