Class: DNSimple::Record
Constant Summary collapse
- Aliases =
{ 'priority' => 'prio', 'time-to-live' => 'ttl' }
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#prio ⇒ Object
Returns the value of attribute prio.
-
#record_type ⇒ Object
Returns the value of attribute record_type.
-
#ttl ⇒ Object
Returns the value of attribute ttl.
Class Method Summary collapse
- .all(domain, options = {}) ⇒ Object
- .create(domain, name, record_type, content, options = {}) ⇒ Object
- .find(domain, id, options = {}) ⇒ Object
- .resolve(name) ⇒ Object
Instance Method Summary collapse
- #delete(options = {}) ⇒ Object (also: #destroy)
- #fqdn ⇒ Object
- #save(options = {}) ⇒ Object
Methods inherited from Base
Constructor Details
This class inherits a constructor from DNSimple::Base
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
15 16 17 |
# File 'lib/dnsimple/record.rb', line 15 def content @content end |
#domain ⇒ Object
Returns the value of attribute domain.
11 12 13 |
# File 'lib/dnsimple/record.rb', line 11 def domain @domain end |
#id ⇒ Object
Returns the value of attribute id.
9 10 11 |
# File 'lib/dnsimple/record.rb', line 9 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/dnsimple/record.rb', line 13 def name @name end |
#prio ⇒ Object
Returns the value of attribute prio.
21 22 23 |
# File 'lib/dnsimple/record.rb', line 21 def prio @prio end |
#record_type ⇒ Object
Returns the value of attribute record_type.
17 18 19 |
# File 'lib/dnsimple/record.rb', line 17 def record_type @record_type end |
#ttl ⇒ Object
Returns the value of attribute ttl.
19 20 21 |
# File 'lib/dnsimple/record.rb', line 19 def ttl @ttl end |
Class Method Details
.all(domain, options = {}) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/dnsimple/record.rb', line 87 def self.all(domain, ={}) response = DNSimple::Client.get("domains/#{domain.name}/records", ) case response.code when 200 response.map { |r| new({:domain => domain}.merge(r["record"])) } else raise RequestError.new("Error listing records", response) end end |
.create(domain, name, record_type, content, options = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/dnsimple/record.rb', line 54 def self.create(domain, name, record_type, content, ={}) record_hash = {:name => name, :record_type => record_type, :content => content} record_hash[:ttl] = .delete(:ttl) || 3600 record_hash[:prio] = .delete(:priority) record_hash[:prio] = .delete(:prio) || '' .merge!({:body => {:record => record_hash}}) response = DNSimple::Client.post("domains/#{domain.name}/records", ) case response.code when 201 new({:domain => domain}.merge(response["record"])) when 406 raise RecordExists, "Record #{name}.#{domain.name} already exists" else raise RequestError.new("Error creating record", response) end end |
.find(domain, id, options = {}) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/dnsimple/record.rb', line 74 def self.find(domain, id, ={}) response = DNSimple::Client.get("domains/#{domain.name}/records/#{id}", ) case response.code when 200 new({:domain => domain}.merge(response["record"])) when 404 raise RecordNotFound, "Could not find record #{id} for domain #{domain.name}" else raise RequestError.new("Error finding record", response) end end |
Instance Method Details
#delete(options = {}) ⇒ Object Also known as: destroy
45 46 47 |
# File 'lib/dnsimple/record.rb', line 45 def delete(={}) DNSimple::Client.delete("domains/#{domain.id}/records/#{id}", ) end |
#fqdn ⇒ Object
23 24 25 |
# File 'lib/dnsimple/record.rb', line 23 def fqdn [name, domain.name].delete_if { |v| v !~ DNSimple::BLANK_REGEX }.join(".") end |
#save(options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dnsimple/record.rb', line 27 def save(={}) record_hash = {} %w(name content ttl prio).each do |attribute| record_hash[DNSimple::Record.resolve(attribute)] = self.send(attribute) end .merge!(:body => {:record => record_hash}) response = DNSimple::Client.put("domains/#{domain.id}/records/#{id}", ) case response.code when 200 self else raise RequestError.new("Error updating record", response) end end |