Class: CloudflareClient::Zone::DNS

Inherits:
Base show all
Defined in:
lib/cloudflare_client/zone/dns.rb

Constant Summary collapse

VALID_TYPES =
['A', 'AAAA', 'CNAME', 'TXT', 'SRV', 'LOC', 'MX', 'NS', 'SPF', 'read only'].freeze

Constants inherited from CloudflareClient::Zone

VALID_ZONE_STATUSES

Constants inherited from CloudflareClient

API_BASE, POSSIBLE_API_SETTINGS, VALID_BUNDLE_METHODS, VALID_DIRECTIONS, VALID_MATCHES, VERSION

Instance Attribute Summary

Attributes inherited from Base

#zone_id

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods inherited from CloudflareClient::Zone

#create_zone, #delete_zone, #edit_zone, #purge_zone_cache, #update_zone_settings, #zone, #zone_activation_check, #zone_setting, #zone_settings, #zones

Methods inherited from CloudflareClient

#initialize

Constructor Details

This class inherits a constructor from CloudflareClient::Zone::Base

Instance Method Details

#create(name:, type:, content:, ttl: nil, proxied: nil) ⇒ Object

Create a dns record



9
10
11
12
13
14
15
# File 'lib/cloudflare_client/zone/dns.rb', line 9

def create(name:, type:, content:, ttl: nil, proxied: nil)
  raise ("type must be one of #{VALID_TYPES.flatten}") unless VALID_TYPES.include?(type)
  data = {name: name, type: type, content: content}
  data[:ttl] = ttl unless ttl.nil?
  data[:proxied] = proxied unless proxied.nil?
  cf_post(path: "/zones/#{zone_id}/dns_records", data: data)
end

#delete(id:) ⇒ Object

delete a dns record id is required. ttl and proxied are optional



53
54
55
56
# File 'lib/cloudflare_client/zone/dns.rb', line 53

def delete(id:)
  id_check('id', id)
  cf_delete(path: "/zones/#{zone_id}/dns_records/#{id}")
end

#list(name: nil, content: nil, per_page: 50, page_no: 1, order: 'type', match: 'all', type: nil) ⇒ Object

list/search for dns records in a given zone



19
20
21
22
23
24
25
26
# File 'lib/cloudflare_client/zone/dns.rb', line 19

def list(name: nil, content: nil, per_page: 50, page_no: 1, order: 'type', match: 'all', type: nil)
  raise('match must be either all | any') unless %w[all any].include?(match)
  params           = {per_page: per_page, page: page_no, order: order}
  params[:name]    = name unless name.nil?
  params[:content] = content unless content.nil?
  params[:type]    = type unless type.nil?
  cf_get(path: "/zones/#{zone_id}/dns_records", params: params)
end

#show(id:) ⇒ Object

details for a given dns_record



30
31
32
33
# File 'lib/cloudflare_client/zone/dns.rb', line 30

def show(id:)
  id_check('dns record id', id)
  cf_get(path: "/zones/#{zone_id}/dns_records/#{id}")
end

#update(id:, type:, name:, content:, ttl: nil, proxied: nil) ⇒ Object

update a dns record. zone_id, id, type, and name are all required. ttl and proxied are optional



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cloudflare_client/zone/dns.rb', line 38

def update(id:, type:, name:, content:, ttl: nil, proxied: nil)
  id_check('dns record id', id)
  id_check('dns record type', type)
  id_check('dns record name', name)
  id_check('dns record content', content)
  raise('must suply type, name, and content') if (type.nil? || name.nil? || content.nil?)
  data           = {type: type, name: name, content: content}
  data[:ttl]     = ttl unless ttl.nil?
  data[:proxied] = proxied unless proxied.nil?
  cf_put(path: "/zones/#{zone_id}/dns_records/#{id}", data: data)
end