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:) ⇒ CloudParty::Responses::DNSRecords
Add a new DNS record to the specified zone.
- #batch(records, zone: nil) ⇒ Object
- #get(zone, id) ⇒ Object
-
#initialize(options = {}) ⇒ DNSRecords
constructor
A new instance of DNSRecords.
-
#list(zone, opts) ⇒ CloudParty::Responses::DNSRecords
Retrieve a list of DNS records for the given zone.
- #rem(id, zone: nil) ⇒ Object
- #search(zone, query) ⇒ Object
- #update(id, type, name, content, opts, zone: nil) ⇒ Object
Methods included from Context
Constructor Details
#initialize(options = {}) ⇒ DNSRecords
Returns a new instance of DNSRecords.
46 47 48 49 |
# File 'lib/cloud_party/nodes/dns_records.rb', line 46 def initialize( = {}) super() @options = end |
Class Method Details
.zone_id_by_name(zone) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cloud_party/nodes/dns_records.rb', line 24 def self.zone_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:) ⇒ CloudParty::Responses::DNSRecords
Add a new DNS record to the specified zone
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/cloud_party/nodes/dns_records.rb', line 162 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? zone_id = zone_id_by_name(zone) CloudParty::Responses::DNSRecords.new( :post, '/zones/:id/dns_records', self.class.post("/zones/#{zone_id}/dns_records", body: .to_json), @options) end |
#batch(records, zone: nil) ⇒ Object
195 196 197 |
# File 'lib/cloud_party/nodes/dns_records.rb', line 195 def batch(records, zone: nil) zone_id = zone_id_by_name(zone) end |
#get(zone, id) ⇒ Object
144 145 146 147 |
# File 'lib/cloud_party/nodes/dns_records.rb', line 144 def get(zone, id) zone_id = DNSRecords.zone_id_by_name(zone) CloudParty::Responses::DNSRecords.new(:get, '/zones/:id/dns_records', self.class.get("/zones/#{zone_id}/dns_records", @options), @options) end |
#list(zone, opts) ⇒ CloudParty::Responses::DNSRecords
Retrieve a list of DNS records for the given zone
Example: Hello, world Example: ello, worl Example: o, world Example: Hello, world Example: Hello, w Example: 127.0.0.1 Example: 7.0.0. Example: .0.1 Example: 127.0.0.1 Example: 127.0. Allowed values: asc, desc Default: asc Example: desc Allowed values: any, all Default: all Example: any Example: www.example.com Example: w.example. Example: .example.com Example: www.example.com Example: www.example Allowed values: type, name, content, ttl, proxied Default: type Example: name >= 1 Default: 1 >= 1 <= 5000000 Default: 100 Default: false Example: true Example: www.cloudflare.com Example: important Example: important Example: greeting:ello, world Example: greeting:ello, world Example: greeting:ello, world Example: greeting:ello, world Allowed values: A, AAAA, CAA, CERT, CNAME, DNSKEY, DS, HTTPS, LOC, MX, NAPTR, NS, OPENPGPKEY, PTR, SMIMEA, SRV, SSHFP, SVCB, TLSA, TXT, URI Default: A Example: A
133 134 135 136 137 |
# File 'lib/cloud_party/nodes/dns_records.rb', line 133 def list(zone, opts) zone_id = DNSRecords.zone_id_by_name(zone) CloudParty::Responses::DNSRecords.new(:get, '/zones/:id/dns_records', self.class.get("/zones/#{zone_id}/dns_records", query: opts), @options) end |
#rem(id, zone: nil) ⇒ Object
182 183 184 185 186 187 188 189 |
# File 'lib/cloud_party/nodes/dns_records.rb', line 182 def rem(id, zone: nil) zone_id = zone_id_by_name(zone) CloudParty::Responses::DNSRecords.new( :delete, '/zones/:id/dns_records/:identifier', self.class.delete("/zones/#{zone_id}/dns_records/#{id}") ) end |
#search(zone, query) ⇒ Object
139 140 141 142 |
# File 'lib/cloud_party/nodes/dns_records.rb', line 139 def search(zone, query) zone_id = DNSRecords.zone_id_by_name(zone) CloudParty::Responses::DNSRecords.new(:get, '/zones/:id/dns_records', self.class.get("/zones/#{zone_id}/dns_records", @options), @options) end |
#update(id, type, name, content, opts, zone: nil) ⇒ Object
190 191 192 193 |
# File 'lib/cloud_party/nodes/dns_records.rb', line 190 def update(id, type, name, content, opts, zone: nil) zone_id = zone_id_by_name(zone) end |