Class: DNSimple::TemplateRecord
- 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)
Methods inherited from Base
Constructor Details
This class inherits a constructor from DNSimple::Base
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.
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/dnsimple/template_record.rb', line 67 def self.all(short_name, ={}) template = DNSimple::Template.find(short_name) response = DNSimple::Client.get("/v1/templates/#{template.id}/template_records", ) case response.code when 200 response.map { |r| new({:template => template}.merge(r["dns_template_record"])) } else raise RequestError.new("Error listing template records", response) end end |
.create(short_name, name, record_type, content, options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dnsimple/template_record.rb', line 32 def self.create(short_name, name, record_type, content, ={}) template = DNSimple::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}}) response = DNSimple::Client.post("/v1/templates/#{template.id}/template_records", ) case response.code when 201 new({:template => template}.merge(response["dns_template_record"])) else raise RequestError.new("Error creating template record", response) end end |
.find(short_name, id, options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/dnsimple/template_record.rb', line 51 def self.find(short_name, id, ={}) template = DNSimple::Template.find(short_name) response = DNSimple::Client.get("/v1/templates/#{template.id}/template_records/#{id}", ) case response.code when 200 new({:template => template}.merge(response["dns_template_record"])) when 404 raise RecordNotFound, "Could not find template record #{id} for template #{template.id}" else raise RequestError.new("Error finding template record", response) end end |