Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
424 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,22 @@ | ||
module Dnsimple | ||
|
||
# A single record in a template. | ||
class TemplateRecord < Base | ||
|
||
# The id of the template record | ||
attr_accessor :id | ||
|
||
# The template the record belongs to | ||
attr_accessor :template | ||
|
||
# The name the record points to. This may be blank. | ||
attr_accessor :dns_template_id | ||
attr_accessor :name | ||
|
||
# The content for the record. | ||
attr_accessor :type | ||
attr_accessor :content | ||
|
||
# The record type | ||
attr_accessor :record_type | ||
|
||
# The time-to-live | ||
attr_accessor :ttl | ||
|
||
# The priority (only for MX records) | ||
attr_accessor :prio | ||
|
||
def delete(options={}) | ||
Client.delete("v1/templates/#{template.id}/template_records/#{id}", options) | ||
end | ||
alias :destroy :delete | ||
|
||
def self.create(short_name, name, record_type, content, options={}) | ||
template = Template.find(short_name) | ||
|
||
record_hash = {:name => name, :record_type => record_type, :content => content} | ||
record_hash[:ttl] = options.delete(:ttl) || 3600 | ||
record_hash[:prio] = options.delete(:prio) || '' | ||
|
||
options.merge!({:query => {:dns_template_record => record_hash}}) | ||
|
||
response = Client.post("v1/templates/#{template.id}/template_records", options) | ||
|
||
case response.code | ||
when 201 | ||
new({:template => template}.merge(response["dns_template_record"])) | ||
else | ||
raise RequestError.new("Error creating template record", response) | ||
end | ||
end | ||
|
||
def self.find(short_name, id, options={}) | ||
template = Template.find(short_name) | ||
response = Client.get("v1/templates/#{template.id}/template_records/#{id}", options) | ||
|
||
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 | ||
|
||
# Get all of the template records for the template with the | ||
# given short name. | ||
def self.all(short_name, options={}) | ||
template = Template.find(short_name) | ||
response = Client.get("v1/templates/#{template.id}/template_records", options) | ||
|
||
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 | ||
|
||
attr_accessor :priority | ||
attr_accessor :created_at | ||
attr_accessor :updated_at | ||
|
||
alias :template_id :dns_template_id | ||
alias :template_id= :dns_template_id= | ||
alias :prio :priority | ||
alias :prio= :priority= | ||
alias :record_type :type | ||
alias :record_type= :type= | ||
end | ||
|
||
end |
Oops, something went wrong.