Class: DNSimple::Template

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

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

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/dnsimple/template.rb', line 4

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/dnsimple/template.rb', line 5

def name
  @name
end

#short_nameObject

Returns the value of attribute short_name.



6
7
8
# File 'lib/dnsimple/template.rb', line 6

def short_name
  @short_name
end

Class Method Details

.all(options = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/dnsimple/template.rb', line 43

def self.all(options={})
  response = DNSimple::Client.get("/v1/templates", options)

  case response.code
  when 200
    response.map { |r| new(r["dns_template"]) }
  else
    raise RequestError.new("Error listing templates", response)
  end
end

.create(name, short_name, description = nil, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dnsimple/template.rb', line 10

def self.create(name, short_name, description=nil, options={})
  template_hash = {
    :name        => name,
    :short_name  => short_name,
    :description => description
  }

  options.merge!(:body => {:dns_template => template_hash})

  response = DNSimple::Client.post("/v1/templates", options)

  case response.code
  when 201
    new(response["dns_template"])
  else
    raise RequestError.new("Error creating template", response)
  end
end

.find(id_or_short_name, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dnsimple/template.rb', line 29

def self.find(id_or_short_name, options={})
  id = id_or_short_name
  response = DNSimple::Client.get("/v1/templates/#{id}", options)

  case response.code
  when 200
    new(response["dns_template"])
  when 404
    raise RecordNotFound, "Could not find template #{id}"
  else
    raise RequestError.new("Error finding template", response)
  end
end

Instance Method Details

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

Delete the template from DNSimple. WARNING: this cannot be undone.



57
58
59
# File 'lib/dnsimple/template.rb', line 57

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