Class: WebbyNode::DNS::Record

Inherits:
APIObject show all
Defined in:
lib/webbynode-api/dns.rb

Overview

Represents a single DNS record

Author:

  • Shane Sveller

Since:

  • 0.1.3

Version:

  • 0.1.0

Instance Attribute Summary

Attributes inherited from APIObject

#data, #email, #token

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from APIObject

#auth_get, #auth_post, auth_post, #method_missing

Constructor Details

#initialize(options = {}) ⇒ Record

Returns a new instance of Record.

Raises:

  • (ArgumentError)

Since:

  • 0.1.3



160
161
162
163
164
165
# File 'lib/webbynode-api/dns.rb', line 160

def initialize(options = {})
  raise ArgumentError, ":id is a required argument" unless options[:id]
  super(options)
  @id = options[:id]
  @data = auth_get("/api/xml/records/#{@id}")["hash"]["record"]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class WebbyNode::APIObject

Class Method Details

.create(options = {}) ⇒ Object

Creates a new DNS record

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :email (String)

    E-mail address used for API access

  • :token (String)

    API token used for API access

  • :type (String)

    DNS record type i.e. A, CNAME or MX

  • :data (String)

    DNS record data, typically an IP address

Raises:

  • (ArgumentError)

Since:

  • 0.1.3



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/webbynode-api/dns.rb', line 173

def self.create(options = {})
  raise ArgumentError, ":email and :token are required arguments for API access" unless options[:email] && options[:token]
  raise ArgumentError, ":data and :type are required arguments" unless options[:data] && options[:type]
  valid_types = %w(A CNAME MX)
  raise ArgumentError, "#{options[:type]} is not a valid value for :type" unless valid_types.include?(options[:type])
  @id = options[:id]
  options.delete(:id)
  for key in options.keys
    if %w(type name data aux ttl).include? key.to_s
      options["record[#{key.to_s}]"] = options[key]
      options.delete(key)
    end
  end
  return auth_post("/api/xml/dns/#{@id}/records/new", :query => options)["hash"]["record"]
end