Class: CloudParty::Nodes::DNSRecords
- Inherits:
-
Object
- Object
- CloudParty::Nodes::DNSRecords
- Includes:
- Context, HTTParty
- Defined in:
- lib/cloud_party/nodes/dns_records.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add(type, name, content, opts, zone:) ⇒ Object
- #get(id) ⇒ Object
-
#initialize(options = {}) ⇒ DNSRecords
constructor
A new instance of DNSRecords.
- #list ⇒ Object
- #rem(id, zone: nil) ⇒ Object
Methods included from Context
Constructor Details
#initialize(options = {}) ⇒ DNSRecords
Returns a new instance of DNSRecords.
43 44 45 46 |
# File 'lib/cloud_party/nodes/dns_records.rb', line 43 def initialize( = {}) super() @options = end |
Class Method Details
.id_by_name(zone) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cloud_party/nodes/dns_records.rb', line 21 def self.id_by_name(zone) = { match: 'all', name: zone, order: 'name' } if @options.nil? @options = else @options.merge!() 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 |
Instance Method Details
#add(type, name, content, opts, zone:) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/cloud_party/nodes/dns_records.rb', line 56 def add(type, name, content, opts, zone:) zone_id = nil = { type: type, name: name, content: content } ttl = opts.fetch('ttl', nil) priority = opts.fetch('priority', nil) proxied = opts.fetch('proxied', nil) .merge!(ttl: ttl) unless ttl.nil? .merge!(priority: priority) unless priority.nil? .merge!(proxied: proxied) unless proxied.nil? if zone = { match: 'all', name: zone, order: 'name' } zone_id = CloudParty::Responses::Zones.new(:get, '/zones', self.class.get('/zones', query: ), @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: .to_json), @options) end |
#get(id) ⇒ Object
52 53 54 |
# File 'lib/cloud_party/nodes/dns_records.rb', line 52 def get(id) CloudParty::Responses::DNSRecords.new(:get, '/zones/:id/dns_records', self.class.get("/zones/#{@@zone}/dns_records", @options), @options) end |
#list ⇒ Object
48 49 50 |
# File 'lib/cloud_party/nodes/dns_records.rb', line 48 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) ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/cloud_party/nodes/dns_records.rb', line 88 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 |