Class: DNSimple::Template
- Inherits:
-
Object
- Object
- DNSimple::Template
- Includes:
- HTTParty
- Defined in:
- lib/dnsimple/template.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
The template description.
-
#id ⇒ Object
The template ID in DNSimple.
-
#name ⇒ Object
The template name.
-
#short_name ⇒ Object
The template short name.
Class Method Summary collapse
- .all(options = {}) ⇒ Object
- .create(name, short_name, description = nil, options = {}) ⇒ Object
- .find(id_or_short_name, options = {}) ⇒ Object
Instance Method Summary collapse
-
#delete(options = {}) ⇒ Object
(also: #destroy)
Delete the template from DNSimple.
-
#initialize(attributes) ⇒ Template
constructor
:nodoc:.
Constructor Details
#initialize(attributes) ⇒ Template
:nodoc:
18 19 20 21 22 23 |
# File 'lib/dnsimple/template.rb', line 18 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
#description ⇒ Object
The template description
15 16 17 |
# File 'lib/dnsimple/template.rb', line 15 def description @description end |
#id ⇒ Object
The template ID in DNSimple
6 7 8 |
# File 'lib/dnsimple/template.rb', line 6 def id @id end |
#name ⇒ Object
The template name
9 10 11 |
# File 'lib/dnsimple/template.rb', line 9 def name @name end |
#short_name ⇒ Object
The template short name
12 13 14 |
# File 'lib/dnsimple/template.rb', line 12 def short_name @short_name end |
Class Method Details
.all(options = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/dnsimple/template.rb', line 75 def self.all(={}) .merge!(DNSimple::Client.) response = self.get("#{Client.base_uri}/templates", ) pp response if Client.debug? case response.code when 200 response.map { |r| Template.new(r["dns_template"]) } when 401 raise RuntimeError, "Authentication failed" else raise RuntimeError, "Error: #{response.code}" end end |
.create(name, short_name, description = nil, options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dnsimple/template.rb', line 33 def self.create(name, short_name, description=nil, ={}) .merge!(DNSimple::Client.) template_hash = { :name => name, :short_name => short_name, :description => description } .merge!(:body => {:dns_template => template_hash}) response = self.post("#{Client.base_uri}/templates", ) pp response if Client.debug? case response.code when 201 return Template.new(response["dns_template"]) when 401 raise RuntimeError, "Authentication failed" else raise DNSimple::Error.new(name, response["errors"]) end end |
.find(id_or_short_name, options = {}) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/dnsimple/template.rb', line 57 def self.find(id_or_short_name, ={}) .merge!(DNSimple::Client.) response = self.get("#{Client.base_uri}/templates/#{id_or_short_name}", ) pp response if Client.debug? case response.code when 200 return Template.new(response["dns_template"]) when 401 raise RuntimeError, "Authentication failed" when 404 raise RuntimeError, "Could not find template #{id_or_short_name}" else raise DNSimple::Error.new(id_or_short_name, response["errors"]) end end |