Class: DNSimple::TemplateRecord

Inherits:
Base
  • Object
show all
Defined in:
lib/dnsimple/template_record.rb

Overview

A single record in a template.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from DNSimple::Base

Instance Attribute Details

#contentObject

The content for the record.



16
17
18
# File 'lib/dnsimple/template_record.rb', line 16

def content
  @content
end

#idObject

The id of the template record



7
8
9
# File 'lib/dnsimple/template_record.rb', line 7

def id
  @id
end

#nameObject

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

#prioObject

The priority (only for MX records)



25
26
27
# File 'lib/dnsimple/template_record.rb', line 25

def prio
  @prio
end

#record_typeObject

The record type



19
20
21
# File 'lib/dnsimple/template_record.rb', line 19

def record_type
  @record_type
end

#templateObject

The template the record belongs to



10
11
12
# File 'lib/dnsimple/template_record.rb', line 10

def template
  @template
end

#ttlObject

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, options={})
  template = DNSimple::Template.find(short_name)
  response = DNSimple::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

.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, options={})
  template = DNSimple::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 = DNSimple::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

.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, options={})
  template = DNSimple::Template.find(short_name)
  response = DNSimple::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

Instance Method Details

#delete(options = {}) ⇒ Object Also known as: destroy



27
28
29
# File 'lib/dnsimple/template_record.rb', line 27

def delete(options={})
  DNSimple::Client.delete("/v1/templates/#{template.id}/template_records/#{id}", options)
end