Class: DNSimple::Domain
Overview
Represents a single domain.
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.
- #remove_service(id, options = {}) ⇒ Object
-
#resolve_template(template) ⇒ Object
:nodoc:.
Methods inherited from Base
Constructor Details
This class inherits a constructor from DNSimple::Base
Instance Attribute Details
#created_at ⇒ Object
When the domain was created in DNSimple
12 13 14 |
# File 'lib/dnsimple/domain.rb', line 12 def created_at @created_at end |
#id ⇒ Object
The domain ID in DNSimple
6 7 8 |
# File 'lib/dnsimple/domain.rb', line 6 def id @id end |
#name ⇒ Object
The domain name
9 10 11 |
# File 'lib/dnsimple/domain.rb', line 9 def name @name end |
#name_server_status ⇒ Object
The current known name server status
18 19 20 |
# File 'lib/dnsimple/domain.rb', line 18 def name_server_status @name_server_status end |
#updated_at ⇒ Object
When the domain was last update in DNSimple
15 16 17 |
# File 'lib/dnsimple/domain.rb', line 15 def updated_at @updated_at end |
Class Method Details
.all(options = {}) ⇒ Object
Get all domains for the account.
161 162 163 164 165 166 167 168 169 170 |
# File 'lib/dnsimple/domain.rb', line 161 def self.all(={}) response = DNSimple::Client.get("domains", ) case response.code when 200 response.map { |r| new(r["domain"]) } else raise RequestError.new("Error listing domains", response) end end |
.check(name, options = {}) ⇒ Object
Check the availability of a name
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/dnsimple/domain.rb', line 92 def self.check(name, ={}) response = DNSimple::Client.get("domains/#{name}/check", ) case response.code when 200 "registered" when 404 "available" else raise RequestError.new("Error checking availability", response) 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.
108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/dnsimple/domain.rb', line 108 def self.create(name, ={}) .merge!({:body => {:domain => {:name => name}}}) response = DNSimple::Client.post("domains", ) case response.code when 201 new(response["domain"]) else raise RequestError.new("Error creating domain", response) 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.
146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/dnsimple/domain.rb', line 146 def self.find(id_or_name, ={}) id = id_or_name response = DNSimple::Client.get("domains/#{id}", ) case response.code when 200 new(response["domain"]) when 404 raise RecordNotFound, "Could not find domain #{id}" else raise RequestError.new("Error finding domain", response) end end |
.register(name, registrant = {}, extended_attributes = {}, options = {}) ⇒ Object
Purchase a domain name.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/dnsimple/domain.rb', line 122 def self.register(name, registrant={}, extended_attributes={}, ={}) body = {:domain => {:name => name}} if registrant if registrant[:id] body[:domain][:registrant_id] = registrant[:id] else body.merge!(:contact => DNSimple::Contact.resolve_attributes(registrant)) end end body.merge!(:extended_attribute => extended_attributes) .merge!({:body => body}) response = DNSimple::Client.post("domain_registrations", ) case response.code when 201 return DNSimple::Domain.new(response["domain"]) else raise RequestError.new("Error registering domain", response) end end |
Instance Method Details
#add_service(id_or_short_name, options = {}) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/dnsimple/domain.rb', line 68 def add_service(id_or_short_name, ={}) .merge!(:body => {:service => {:id => id_or_short_name}}) response = DNSimple::Client.post("domains/#{name}/applied_services", ) case response.code when 200 true else raise RequestError.new("Error adding service", response) end end |
#applied_services(options = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dnsimple/domain.rb', line 46 def applied_services(={}) response = DNSimple::Client.get("domains/#{name}/applied_services", ) case response.code when 200 response.map { |r| DNSimple::Service.new(r["service"]) } else raise RequestError.new("Error listing applied services", response) 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.
29 30 31 32 33 34 |
# File 'lib/dnsimple/domain.rb', line 29 def apply(template, ={}) .merge!(:body => {}) template = resolve_template(template) DNSimple::Client.post("domains/#{name}/templates/#{template.id}/apply", ) end |
#available_services(options = {}) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/dnsimple/domain.rb', line 57 def available_services(={}) response = DNSimple::Client.get("domains/#{name}/available_services", ) case response.code when 200 response.map { |r| DNSimple::Service.new(r["service"]) } else raise RequestError.new("Error listing available services", response) end end |
#delete(options = {}) ⇒ Object Also known as: destroy
Delete the domain from DNSimple. WARNING: this cannot be undone.
22 23 24 |
# File 'lib/dnsimple/domain.rb', line 22 def delete(={}) DNSimple::Client.delete("domains/#{name}", ) end |
#remove_service(id, options = {}) ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/dnsimple/domain.rb', line 80 def remove_service(id, ={}) response = DNSimple::Client.delete("domains/#{name}/applied_services/#{id}", ) case response.code when 200 true else raise RequestError.new("Error removing service", response) end end |