Class: DNSimple::Domain
- Inherits:
-
Object
- Object
- DNSimple::Domain
- Includes:
- HTTParty
- Defined in:
- lib/dnsimple/domain.rb
Overview
Class representing a single domain in DNSimple.
Instance Attribute Summary collapse
-
#created_at ⇒ Object
When the domain was created in DNSimple.
-
#id ⇒ Object
The domain ID in DNSimple.
-
#name ⇒ Object
The domain name.
-
#name_server_status ⇒ Object
The current known name server status.
-
#updated_at ⇒ Object
When the domain was last update in DNSimple.
Class Method Summary collapse
-
.all(options = {}) ⇒ Object
Get all domains for the account.
-
.check(name, options = {}) ⇒ Object
Check the availability of a name.
-
.create(name, options = {}) ⇒ Object
Create the domain with the given name in DNSimple.
-
.find(id_or_name, options = {}) ⇒ Object
Find a specific domain in the account either by the numeric ID or by the fully-qualified domain name.
-
.register(name, registrant = {}, extended_attributes = {}, options = {}) ⇒ Object
Purchase a domain name.
Instance Method Summary collapse
- #add_service(id_or_short_name, options = {}) ⇒ Object
- #applied_services(options = {}) ⇒ Object
-
#apply(template, options = {}) ⇒ Object
Apply the given named template to the domain.
- #available_services(options = {}) ⇒ Object
-
#delete(options = {}) ⇒ Object
(also: #destroy)
Delete the domain from DNSimple.
-
#initialize(attributes) ⇒ Domain
constructor
:nodoc:.
- #remove_service(id, options = {}) ⇒ Object
-
#resolve_template(template) ⇒ Object
:nodoc:.
Constructor Details
#initialize(attributes) ⇒ Domain
:nodoc:
22 23 24 25 26 27 |
# File 'lib/dnsimple/domain.rb', line 22 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
#created_at ⇒ Object
When the domain was created in DNSimple
13 14 15 |
# File 'lib/dnsimple/domain.rb', line 13 def created_at @created_at end |
#id ⇒ Object
The domain ID in DNSimple
7 8 9 |
# File 'lib/dnsimple/domain.rb', line 7 def id @id end |
#name ⇒ Object
The domain name
10 11 12 |
# File 'lib/dnsimple/domain.rb', line 10 def name @name end |
#name_server_status ⇒ Object
The current known name server status
19 20 21 |
# File 'lib/dnsimple/domain.rb', line 19 def name_server_status @name_server_status end |
#updated_at ⇒ Object
When the domain was last update in DNSimple
16 17 18 |
# File 'lib/dnsimple/domain.rb', line 16 def updated_at @updated_at end |
Class Method Details
.all(options = {}) ⇒ Object
Get all domains for the account.
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/dnsimple/domain.rb', line 203 def self.all(={}) .merge!(DNSimple::Client.) response = self.get("#{DNSimple::Client.base_uri}/domains", ) pp response if DNSimple::Client.debug? case response.code when 200 response.map { |r| DNSimple::Domain.new(r["domain"]) } when 401 raise RuntimeError, "Authentication failed" else raise RuntimeError, "Error: #{response.code}" end end |
.check(name, options = {}) ⇒ Object
Check the availability of a name
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/dnsimple/domain.rb', line 114 def self.check(name, ={}) .merge!(DNSimple::Client.) response = self.get("#{DNSimple::Client.base_uri}/domains/#{name}/check", ) pp response if DNSimple::Client.debug? case response.code when 200 "registered" when 401 raise RuntimeError, "Authentication failed" when 404 "available" else raise "Error: #{response.code}" end end |
.create(name, options = {}) ⇒ Object
Create the domain with the given name in DNSimple. This method returns a Domain instance if the name is created and raises an error otherwise.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/dnsimple/domain.rb', line 133 def self.create(name, ={}) .merge!(DNSimple::Client.) domain_hash = {:name => name} .merge!({:body => {:domain => domain_hash}}) response = self.post("#{DNSimple::Client.base_uri}/domains", ) pp response if DNSimple::Client.debug? case response.code when 201 return DNSimple::Domain.new(response["domain"]) when 401 raise RuntimeError, "Authentication failed" else raise DNSimple::Error.new(name, response["errors"]) end end |
.find(id_or_name, options = {}) ⇒ Object
Find a specific domain in the account either by the numeric ID or by the fully-qualified domain name.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/dnsimple/domain.rb', line 184 def self.find(id_or_name, ={}) .merge!(DNSimple::Client.) response = self.get("#{DNSimple::Client.base_uri}/domains/#{id_or_name}", ) pp response if DNSimple::Client.debug? case response.code when 200 return DNSimple::Domain.new(response["domain"]) when 401 raise RuntimeError, "Authentication failed" when 404 raise RuntimeError, "Could not find domain #{id_or_name}" else raise DNSimple::Error.new(id_or_name, response["errors"]) end end |
.register(name, registrant = {}, extended_attributes = {}, options = {}) ⇒ Object
Purchase a domain name.
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/dnsimple/domain.rb', line 154 def self.register(name, registrant={}, extended_attributes={}, ={}) .merge!(DNSimple::Client.) body = {:domain => {:name => name}} if registrant if registrant[:id] body[:domain][:registrant_id] = registrant[:id] else body.merge!(:contact => Contact.resolve_attributes(registrant)) end end body.merge!(:extended_attribute => extended_attributes) .merge!({:body => body}) response = self.post("#{DNSimple::Client.base_uri}/domain_registrations", ) pp response if DNSimple::Client.debug? case response.code when 201 return DNSimple::Domain.new(response["domain"]) when 401 raise RuntimeError, "Authentication failed" else raise DNSimple::Error.new(name, response["errors"]) end end |
Instance Method Details
#add_service(id_or_short_name, options = {}) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/dnsimple/domain.rb', line 84 def add_service(id_or_short_name, ={}) .merge!(DNSimple::Client.) .merge!(:body => {:service => {:id => id_or_short_name}}) response = self.class.post("#{DNSimple::Client.base_uri}/domains/#{name}/applied_services", ) pp response if DNSimple::Client.debug? case response.code when 200 true when 401 raise RuntimeError, "Authentication failed" else raise "Error: #{response.code}" end end |
#applied_services(options = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/dnsimple/domain.rb', line 56 def applied_services(={}) .merge!(DNSimple::Client.) response = self.class.get("#{Client.base_uri}/domains/#{name}/applied_services", ) pp response if DNSimple::Client.debug? case response.code when 200 response.map { |r| DNSimple::Service.new(r["service"]) } when 401 raise RuntimeError, "Authentication failed" else raise RuntimeError, "Error: #{response.code}" end end |
#apply(template, options = {}) ⇒ Object
Apply the given named template to the domain. This will add all of the records in the template to the domain.
39 40 41 42 43 44 |
# File 'lib/dnsimple/domain.rb', line 39 def apply(template, ={}) .merge!(DNSimple::Client.) .merge!(:body => {}) template = resolve_template(template) self.class.post("#{DNSimple::Client.base_uri}/domains/#{name}/templates/#{template.id}/apply", ) end |
#available_services(options = {}) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/dnsimple/domain.rb', line 70 def available_services(={}) .merge!(DNSimple::Client.) response = self.class.get("#{DNSimple::Client.base_uri}/domains/#{name}/available_services", ) pp response if DNSimple::Client.debug? case response.code when 200 response.map { |r| DNSimple::Service.new(r["service"]) } when 401 raise RuntimeError, "Authentication failed" else raise RuntimeError, "Error: #{response.code}" end end |
#delete(options = {}) ⇒ Object Also known as: destroy
Delete the domain from DNSimple. WARNING: this cannot be undone.
31 32 33 34 |
# File 'lib/dnsimple/domain.rb', line 31 def delete(={}) .merge!(DNSimple::Client.) self.class.delete("#{DNSimple::Client.base_uri}/domains/#{name}", ) end |
#remove_service(id, options = {}) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/dnsimple/domain.rb', line 99 def remove_service(id, ={}) .merge!(DNSimple::Client.) response = self.class.delete("#{DNSimple::Client.base_uri}/domains/#{name}/applied_services/#{id}", ) pp response if DNSimple::Client.debug? case response.code when 200 true when 401 raise RuntimeError, "Authentication failed" else raise "Error: #{response.code}" end end |