Class: Nifcloud::DNS::Record

Inherits:
Client show all
Defined in:
lib/nifcloud/dns/record.rb

Overview

Class that manages DNS record information

Constant Summary collapse

RECORD_SET_WITH_ID =
'hostedzone/%s/rrset'
RECORD_SET_WITH_PARAMS =
'hostedzone/%s/rrset?%s'

Constants inherited from Client

Client::AUTHORIZATION_HEADER, Client::DATE_HEADER, Client::ENDPOINT, Client::NAMESPACE, Client::VERSION

Constants inherited from Auth

Auth::ALGORITHM

Instance Attribute Summary

Attributes inherited from Auth

#time

Instance Method Summary collapse

Methods inherited from Client

#delete, #get, #post

Methods inherited from Auth

#signature_header

Constructor Details

#initialize(zone_id, access_key: nil, secret_key: nil) ⇒ Record

Returns a new instance of Record.



14
15
16
17
# File 'lib/nifcloud/dns/record.rb', line 14

def initialize(zone_id, access_key: nil, secret_key: nil)
  super(access_key, secret_key)
  @zone_id = zone_id
end

Instance Method Details

#add(name, type, value, ttl: 86_400, comment: '') ⇒ Object



30
31
32
# File 'lib/nifcloud/dns/record.rb', line 30

def add(name, type, value, ttl: 86_400, comment: '')
  post(RECORD_SET_WITH_ID % @zone_id, xml('CREATE', name, type, value, ttl, comment))
end

#del(name, type, value, ttl: 86_400, comment: '') ⇒ Object



34
35
36
# File 'lib/nifcloud/dns/record.rb', line 34

def del(name, type, value, ttl: 86_400, comment: '')
  post(RECORD_SET_WITH_ID % @zone_id, xml('DELETE', name, type, value, ttl, comment))
end

#list(options: nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/nifcloud/dns/record.rb', line 19

def list(options: nil)
  if options.nil? || !options.instance_of?(Hash)
    get(RECORD_SET_WITH_ID % @zone_id)
  else
    list_path = format(RECORD_SET_WITH_PARAMS,
                       @zone_id,
                       options.collect { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&'))
    get(list_path)
  end
end