Class: DNSimple::Record
- Inherits:
-
Object
- Object
- DNSimple::Record
- Includes:
- HTTParty
- Defined in:
- lib/dnsimple/record.rb
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
-
#initialize(attributes) ⇒ Record
constructor
:nodoc:.
- #save(options = {}) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Record
:nodoc:
20 21 22 23 24 25 |
# File 'lib/dnsimple/record.rb', line 20 def initialize(attributes) attributes.each do |key, value| m = "#{key}=".to_sym self.send(m, value) if self.respond_to?(m) end end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
11 12 13 |
# File 'lib/dnsimple/record.rb', line 11 def content @content end |
#domain ⇒ Object
Returns the value of attribute domain.
7 8 9 |
# File 'lib/dnsimple/record.rb', line 7 def domain @domain end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/dnsimple/record.rb', line 5 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/dnsimple/record.rb', line 9 def name @name end |
#prio ⇒ Object
Returns the value of attribute prio.
17 18 19 |
# File 'lib/dnsimple/record.rb', line 17 def prio @prio end |
#record_type ⇒ Object
Returns the value of attribute record_type.
13 14 15 |
# File 'lib/dnsimple/record.rb', line 13 def record_type @record_type end |
#ttl ⇒ Object
Returns the value of attribute ttl.
15 16 17 |
# File 'lib/dnsimple/record.rb', line 15 def ttl @ttl end |
Class Method Details
.all(domain, options = {}) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/dnsimple/record.rb', line 111 def self.all(domain, ={}) .merge!(DNSimple::Client.) response = self.get("#{DNSimple::Client.base_uri}/domains/#{domain.name}/records", ) pp response if DNSimple::Client.debug? case response.code when 200 response.map { |r| DNSimple::Record.new({:domain => domain}.merge(r["record"])) } when 401 raise DNSimple::AuthenticationFailed, "Authentication failed" else raise DNSimple::Error, "Error listing domains: #{response.code}" end end |
.create(domain, name, record_type, content, options = {}) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/dnsimple/record.rb', line 68 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!(DNSimple::Client.) .merge!({:body => {:record => record_hash}}) response = self.post("#{DNSimple::Client.base_uri}/domains/#{domain.name}/records", ) pp response if DNSimple::Client.debug? case response.code when 201 return DNSimple::Record.new({:domain => domain}.merge(response["record"])) when 401 raise DNSimple::AuthenticationFailed when 406 raise DNSimple::RecordExists.new("#{name}.#{domain.name}", response["errors"]) else raise DNSimple::Error, "Failed to create #{name}.#{domain.name}: #{response["errors"]}" end end |
.find(domain, id, options = {}) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/dnsimple/record.rb', line 93 def self.find(domain, id, ={}) .merge!(DNSimple::Client.) response = self.get("#{DNSimple::Client.base_uri}/domains/#{domain.name}/records/#{id}", ) pp response if DNSimple::Client.debug? case response.code when 200 return DNSimple::Record.new({:domain => domain}.merge(response["record"])) when 401 raise DNSimple::AuthenticationFailed when 404 raise DNSimple::RecordNotFound, "Could not find record #{id} for domain #{domain.name}" else raise DNSimple::Error, "Failed to find domain #{domain.name}/#{id}: #{response["errors"]}" end end |
.resolve(name) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/dnsimple/record.rb', line 60 def self.resolve(name) aliases = { 'priority' => 'prio', 'time-to-live' => 'ttl' } aliases[name] || name end |
Instance Method Details
#delete(options = {}) ⇒ Object Also known as: destroy
54 55 56 57 |
# File 'lib/dnsimple/record.rb', line 54 def delete(={}) .merge!(DNSimple::Client.) self.class.delete("#{DNSimple::Client.base_uri}/domains/#{domain.id}/records/#{id}", ) end |
#fqdn ⇒ Object
27 28 29 |
# File 'lib/dnsimple/record.rb', line 27 def fqdn [name, domain.name].delete_if { |v| v !~ DNSimple::BLANK_REGEX }.join(".") end |
#save(options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dnsimple/record.rb', line 31 def save(={}) record_hash = {} %w(name content ttl prio).each do |attribute| record_hash[DNSimple::Record.resolve(attribute)] = self.send(attribute) end .merge!(DNSimple::Client.) .merge!(:body => {:record => record_hash}) response = self.class.put("#{DNSimple::Client.base_uri}/domains/#{domain.id}/records/#{id}.json", ) pp response if DNSimple::Client.debug? case response.code when 200 return self when 401 raise DNSimple::AuthenticationFailed else raise DNSimple::Error, "Failed to update record: #{response.inspect}" end end |