Module: Myra::DnsRecords

Extended by:
DomainHandler, RequestHandler
Defined in:
lib/myra/actions/dns_records.rb

Constant Summary collapse

PATH =
'/dnsRecords/{domain}'

Class Method Summary collapse

Methods included from RequestHandler

errors, handle

Methods included from DomainHandler

normalize_domain_name, path

Class Method Details

.create(record, domain) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/myra/actions/dns_records.rb', line 13

def self.create(record, domain)
  record = normalize_domain_name(record, domain)
  request = Request.new(path: path(domain), type: :put)
  request.payload = Oj.dump(record.to_hash)
  value = handle request
  DnsRecord.from_hash(value['targetObject'].first)
end

.delete(domain, record) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/myra/actions/dns_records.rb', line 29

def self.delete(domain, record)
  r = normalize_domain_name(record, domain)
  request = Request.new(path: path(domain), type: :delete)
  keys = %w(modified id)
  request.payload = Oj.dump(r.to_hash.select { |k, _| keys.include? k })
  value = handle request
  deleted_record = DnsRecord.from_hash(value['targetObject'].first)
  deleted_record.deleted = true
  deleted_record
end

.list(domain, page = 1) ⇒ Object



8
9
10
11
# File 'lib/myra/actions/dns_records.rb', line 8

def self.list(domain, page = 1)
  values = handle Request.new(path: "#{path(domain)}/#{page}")
  values['list'].map { |record| DnsRecord.from_hash(record) }
end

.update(domain, record) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/myra/actions/dns_records.rb', line 21

def self.update(domain, record)
  record = normalize_domain_name(record, domain)
  request = Request.new(path: path(domain), type: :post)
  request.payload = Oj.dump(record.to_hash)
  value = handle request
  DnsRecord.from_hash(value['targetObject'].first)
end