Class: DNSimple::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, 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
11 12 13 |
# File 'lib/dnsimple/domain.rb', line 11 def created_at @created_at end |
#id ⇒ Object
The domain ID in DNSimple
5 6 7 |
# File 'lib/dnsimple/domain.rb', line 5 def id @id end |
#name ⇒ Object
The domain name
8 9 10 |
# File 'lib/dnsimple/domain.rb', line 8 def name @name end |
#name_server_status ⇒ Object
The current known name server status
17 18 19 |
# File 'lib/dnsimple/domain.rb', line 17 def name_server_status @name_server_status end |
#updated_at ⇒ Object
When the domain was last update in DNSimple
14 15 16 |
# File 'lib/dnsimple/domain.rb', line 14 def updated_at @updated_at end |
Class Method Details
.all(options = {}) ⇒ Object
Get all domains for the account.
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/dnsimple/domain.rb', line 89 def self.all(={}) response = DNSimple::Client.get("/v1/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
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/dnsimple/domain.rb', line 21 def self.check(name, ={}) response = DNSimple::Client.get("/v1/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.
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dnsimple/domain.rb', line 37 def self.create(name, ={}) .merge!({:body => {:domain => {:name => name}}}) response = DNSimple::Client.post("/v1/domains", ) case response.code when 201 new(response["domain"]) else raise RequestError.new("Error creating domain", response) end end |
.find(id, options = {}) ⇒ Object
Find a specific domain in the account either by the numeric ID or by the fully-qualified domain name.
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/dnsimple/domain.rb', line 75 def self.find(id, ={}) response = DNSimple::Client.get("/v1/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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/dnsimple/domain.rb', line 51 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("/v1/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
149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/dnsimple/domain.rb', line 149 def add_service(id_or_short_name, ={}) .merge!(:body => {:service => {:id => id_or_short_name}}) response = DNSimple::Client.post("/v1/domains/#{name}/applied_services", ) case response.code when 200 true else raise RequestError.new("Error adding service", response) end end |
#applied_services(options = {}) ⇒ Object
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/dnsimple/domain.rb', line 127 def applied_services(={}) response = DNSimple::Client.get("/v1/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.
110 111 112 113 114 115 |
# File 'lib/dnsimple/domain.rb', line 110 def apply(template, ={}) .merge!(:body => {}) template = resolve_template(template) DNSimple::Client.post("/v1/domains/#{name}/templates/#{template.id}/apply", ) end |
#available_services(options = {}) ⇒ Object
138 139 140 141 142 143 144 145 146 147 |
# File 'lib/dnsimple/domain.rb', line 138 def available_services(={}) response = DNSimple::Client.get("/v1/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.
103 104 105 |
# File 'lib/dnsimple/domain.rb', line 103 def delete(={}) DNSimple::Client.delete("/v1/domains/#{name}", ) end |
#remove_service(id, options = {}) ⇒ Object
161 162 163 164 165 166 167 168 169 170 |
# File 'lib/dnsimple/domain.rb', line 161 def remove_service(id, ={}) response = DNSimple::Client.delete("/v1/domains/#{name}/applied_services/#{id}", ) case response.code when 200 true else raise RequestError.new("Error removing service", response) end end |