Module: GandiV5::LiveDNS::HasZoneRecords
Overview
Methods for handling record related requests in both GandiV5::LiveDNS::Domain and GandiV5::LiveDNS::Zone.
Instance Method Summary collapse
-
#add_record(name, type, ttl, *values) ⇒ String
Add record to this domain.
- #delete_records(name = nil, type = nil) ⇒ nil
- #fetch_records(name = nil, type = nil) ⇒ Array<GandiV5::LiveDNS::RecordSet>
- #fetch_zone_lines(name = nil, type = nil) ⇒ String
-
#replace_records(records: nil, text: nil) ⇒ String
Replace all records for this domain.
-
#replace_records_for(name, records, type: nil, ttl: nil) ⇒ String
The confirmation message from Gandi.
Instance Method Details
#add_record(name, type, ttl, *values) ⇒ String
Add record to this domain.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/gandi_v5/live_dns/has_zone_records.rb', line 59 def add_record(name, type, ttl, *values) GandiV5::LiveDNS.require_valid_record_type type fail ArgumentError, 'ttl must be positive and non-zero' unless ttl.positive? fail ArgumentError, 'there must be at least one value' if values.none? body = { rrset_name: name, rrset_type: type, rrset_ttl: ttl, rrset_values: values }.to_json _response, data = GandiV5.post "#{url}/records", body data['message'] end |
#delete_records ⇒ nil #delete_records(name) ⇒ nil #delete_records(name, type) ⇒ nil
85 86 87 88 89 90 91 92 |
# File 'lib/gandi_v5/live_dns/has_zone_records.rb', line 85 def delete_records(name = nil, type = nil) GandiV5::LiveDNS.require_valid_record_type(type) if type url_ = "#{url}/records" url_ += "/#{CGI.escape name}" if name url_ += "/#{CGI.escape type}" if type GandiV5.delete(url_).last end |
#fetch_records ⇒ Array<GandiV5::LiveDNS::RecordSet> #fetch_records(name) ⇒ Array<GandiV5::LiveDNS::RecordSet> #fetch_records(name, type) ⇒ Array<GandiV5::LiveDNS::RecordSet>
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gandi_v5/live_dns/has_zone_records.rb', line 19 def fetch_records(name = nil, type = nil) GandiV5::LiveDNS.require_valid_record_type type if type url_ = "#{url}/records" url_ += "/#{CGI.escape name}" if name url_ += "/#{CGI.escape type}" if type _response, data = GandiV5.get url_ data = [data] unless data.is_a?(Array) data.map { |item| GandiV5::LiveDNS::RecordSet.from_gandi item } end |
#fetch_zone_lines ⇒ String #fetch_zone_lines(name) ⇒ String #fetch_zone_lines(name, type) ⇒ String
42 43 44 45 46 47 48 49 50 |
# File 'lib/gandi_v5/live_dns/has_zone_records.rb', line 42 def fetch_zone_lines(name = nil, type = nil) GandiV5::LiveDNS.require_valid_record_type type if type url_ = "#{url}/records" url_ += "/#{CGI.escape name}" if name url_ += "/#{CGI.escape type}" if type GandiV5.get(url_, accept: 'text/plain').last end |
#replace_records(records: nil, text: nil) ⇒ String
Replace all records for this domain.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/gandi_v5/live_dns/has_zone_records.rb', line 102 def replace_records(records: nil, text: nil) unless [records, text].count(&:nil?).eql?(1) fail ArgumentError, 'you must pass ONE of records: or text:' end if records body = { items: records.map { |r| r.transform_keys { |k| "rrset_#{k}" } } }.to_json _response, data = GandiV5.put "#{url}/records", body elsif text _response, data = GandiV5.put "#{url}/records", text, 'content-type': 'text/plain' end data['message'] end |
#replace_records_for(name, records, type: nil, ttl: nil) ⇒ String
Returns The confirmation message from Gandi.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/gandi_v5/live_dns/has_zone_records.rb', line 133 def replace_records_for(name, records, type: nil, ttl: nil) fail ArgumentError, 'missing keyword: type' if ttl && type.nil? if type GandiV5::LiveDNS.require_valid_record_type type body = { rrset_values: records, rrset_ttl: ttl } # body[:rrset_ttl] = ttl if ttl _response, data = GandiV5.put "#{url}/records/#{name}/#{type}", body.to_json else body = { items: records.map { |r| r.transform_keys { |k| "rrset_#{k}" } } } _response, data = GandiV5.put "#{url}/records/#{name}", body.to_json end data['message'] end |