class CloudParty::Nodes::DNSRecords
Public Class Methods
id_by_name(zone)
click to toggle source
# File lib/cloud_party/nodes/dns_records.rb, line 22 def self.id_by_name(zone) options = { match: 'all', name: zone, order: 'name' } if @options.nil? @options = options else @options.merge!(options) end zone = CloudParty::Responses::Zones.new(:get, '/zones', get('/zones', query: @options), @options).result if zone.is_a?(Array) if zone.size > 1 raise CloudParty::Errors::ResultError.new() else zone.first.fetch(:id, nil) end end end
new(options = {})
click to toggle source
Calls superclass method
# File lib/cloud_party/nodes/dns_records.rb, line 44 def initialize(options = {}) super() @options = options end
Public Instance Methods
add(type, name, content, opts, zone:)
click to toggle source
# File lib/cloud_party/nodes/dns_records.rb, line 57 def add(type, name, content, opts, zone:) zone_id = nil options = { type: type, name: name, content: content } ttl = opts.fetch('ttl', nil) priority = opts.fetch('priority', nil) proxied = opts.fetch('proxied', nil) options.merge!(ttl: ttl) unless ttl.nil? options.merge!(priority: priority) unless priority.nil? options.merge!(proxied: proxied) unless proxied.nil? if zone zone_options = { match: 'all', name: zone, order: 'name' } zone_id = CloudParty::Responses::Zones.new(:get, '/zones', self.class.get('/zones', query: zone_options), @options).result.first.fetch(:id, nil) elsif self.class.class_variable_defined?(:@@zone) zone_id = @@zone else raise CloudParty::Errors::NoDefinedZoneError.new("neither the keyword 'zone:' nor the class variable @@zone ended up being defined.", nil) end CloudParty::Responses::DNSRecords.new( :post, '/zones/:id/dns_records', self.class.post("/zones/#{zone_id}/dns_records", body: options.to_json), @options) end
get(id)
click to toggle source
# File lib/cloud_party/nodes/dns_records.rb, line 53 def get(id) CloudParty::Responses::DNSRecords.new(:get, '/zones/:id/dns_records', self.class.get("/zones/#{@@zone}/dns_records", @options), @options) end
list()
click to toggle source
# File lib/cloud_party/nodes/dns_records.rb, line 49 def list CloudParty::Responses::DNSRecords.new(:get, '/zones/:id/dns_records', self.class.get("/zones/#{@@zone}/dns_records", @options), @options) end
rem(id, zone: nil)
click to toggle source
# File lib/cloud_party/nodes/dns_records.rb, line 89 def rem(id, zone: nil) zone_id = id_by_name(zone) CloudParty::Responses::DNSRecords.new( :delete, '/zones/:id/dns_records/:identifier', self.class.delete("/zones/#{zone_id}/dns_records/#{id}") ) end