Class: DNSimple::TemplateRecord
- Inherits:
-
Object
- Object
- DNSimple::TemplateRecord
- Includes:
- HTTParty
- Defined in:
- lib/dnsimple/template_record.rb
Overview
A single record in a template
Instance Attribute Summary collapse
-
#content ⇒ Object
The content for the record.
-
#id ⇒ Object
The id of the template record.
-
#name ⇒ Object
The name the record points to.
-
#prio ⇒ Object
The priority (only for MX records).
-
#record_type ⇒ Object
The record type.
-
#template ⇒ Object
The template the record belongs to.
-
#ttl ⇒ Object
The time-to-live.
Class Method Summary collapse
-
.all(short_name, options = {}) ⇒ Object
Get all of the template records for the template with the given short name.
- .create(short_name, name, record_type, content, options = {}) ⇒ Object
- .find(short_name, id, options = {}) ⇒ Object
Instance Method Summary collapse
- #delete(options = {}) ⇒ Object (also: #destroy)
-
#initialize(attributes) ⇒ TemplateRecord
constructor
:nodoc:.
Constructor Details
#initialize(attributes) ⇒ TemplateRecord
:nodoc:
28 29 30 31 32 33 |
# File 'lib/dnsimple/template_record.rb', line 28 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
The content for the record.
16 17 18 |
# File 'lib/dnsimple/template_record.rb', line 16 def content @content end |
#id ⇒ Object
The id of the template record
7 8 9 |
# File 'lib/dnsimple/template_record.rb', line 7 def id @id end |
#name ⇒ Object
The name the record points to. This may be blank.
13 14 15 |
# File 'lib/dnsimple/template_record.rb', line 13 def name @name end |
#prio ⇒ Object
The priority (only for MX records)
25 26 27 |
# File 'lib/dnsimple/template_record.rb', line 25 def prio @prio end |
#record_type ⇒ Object
The record type
19 20 21 |
# File 'lib/dnsimple/template_record.rb', line 19 def record_type @record_type end |
#template ⇒ Object
The template the record belongs to
10 11 12 |
# File 'lib/dnsimple/template_record.rb', line 10 def template @template end |
#ttl ⇒ Object
The time-to-live
22 23 24 |
# File 'lib/dnsimple/template_record.rb', line 22 def ttl @ttl end |
Class Method Details
.all(short_name, options = {}) ⇒ Object
Get all of the template records for the template with the given short name.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/dnsimple/template_record.rb', line 84 def self.all(short_name, ={}) template = Template.find(short_name) .merge!({:basic_auth => Client.credentials}) response = self.get("#{Client.base_uri}/templates/#{template.id}/template_records.json", ) pp response if Client.debug? case response.code when 200 response.map { |r| TemplateRecord.new({:template => template}.merge(r["dns_template_record"])) } when 401 raise RuntimeError, "Authentication failed" else raise RuntimeError, "Error: #{response.code}" end end |
.create(short_name, name, record_type, content, options = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/dnsimple/template_record.rb', line 41 def self.create(short_name, name, record_type, content, ={}) template = Template.find(short_name) record_hash = {:name => name, :record_type => record_type, :content => content} record_hash[:ttl] = .delete(:ttl) || 3600 record_hash[:prio] = .delete(:prio) || '' .merge!({:query => {:dns_template_record => record_hash}}) .merge!({:basic_auth => Client.credentials}) response = self.post("#{Client.base_uri}/templates/#{template.id}/template_records.json", ) pp response if Client.debug? case response.code when 201 return TemplateRecord.new({:template => template}.merge(response["dns_template_record"])) when 401 raise RuntimeError, "Authentication failed" else raise DNSimple::Error.new("#{name}", response["errors"]) end end |
.find(short_name, id, options = {}) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/dnsimple/template_record.rb', line 65 def self.find(short_name, id, ={}) template = Template.find(short_name) .merge!(:basic_auth => Client.credentials) response = self.get("#{Client.base_uri}/templates/#{template.id}/template_records/#{id}.json", ) pp response if Client.debug? case response.code when 200 return TemplateRecord.new({:template => template}.merge(response["dns_template_record"])) when 401 raise RuntimeError, "Authentication failed" when 404 raise RuntimeError, "Could not find template record #{id} for template #{short_name}" end end |
Instance Method Details
#delete(options = {}) ⇒ Object Also known as: destroy
35 36 37 38 |
# File 'lib/dnsimple/template_record.rb', line 35 def delete(={}) .merge!(:basic_auth => Client.credentials) self.class.delete("#{Client.base_uri}/templates/#{template.id}/template_records/#{id}.json", ) end |