Class: DNSimple::Domain

Inherits:
Base
  • Object
show all
Defined in:
lib/dnsimple/domain.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

#auto_renewObject

Is the domain set to autorenew



35
36
37
# File 'lib/dnsimple/domain.rb', line 35

def auto_renew
  @auto_renew
end

#created_atObject

When the domain was created in DNSimple



11
12
13
# File 'lib/dnsimple/domain.rb', line 11

def created_at
  @created_at
end

#expires_onObject

When the domain is due to expire



20
21
22
# File 'lib/dnsimple/domain.rb', line 20

def expires_on
  @expires_on
end

#idObject

The domain ID in DNSimple



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

def id
  @id
end

#lockableObject

Is the domain lockable



32
33
34
# File 'lib/dnsimple/domain.rb', line 32

def lockable
  @lockable
end

#nameObject

The domain name



8
9
10
# File 'lib/dnsimple/domain.rb', line 8

def name
  @name
end

#name_server_statusObject

The current known name server status



17
18
19
# File 'lib/dnsimple/domain.rb', line 17

def name_server_status
  @name_server_status
end

#registrant_idObject

ID of the registrant in DNSimple



26
27
28
# File 'lib/dnsimple/domain.rb', line 26

def registrant_id
  @registrant_id
end

#stateObject

The state of the domain in DNSimple



23
24
25
# File 'lib/dnsimple/domain.rb', line 23

def state
  @state
end

#updated_atObject

When the domain was last update in DNSimple



14
15
16
# File 'lib/dnsimple/domain.rb', line 14

def updated_at
  @updated_at
end

#user_idObject

User ID in DNSimple



29
30
31
# File 'lib/dnsimple/domain.rb', line 29

def user_id
  @user_id
end

#whois_protectedObject

Is the whois information protected



38
39
40
# File 'lib/dnsimple/domain.rb', line 38

def whois_protected
  @whois_protected
end

Class Method Details

.all(options = {}) ⇒ Object

Get all domains for the account.



110
111
112
113
114
115
116
117
118
119
# File 'lib/dnsimple/domain.rb', line 110

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

  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



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

def self.check(name, options={})
  response = DNSimple::Client.get("/v1/domains/#{name}/check", options)

  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.



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/dnsimple/domain.rb', line 58

def self.create(name, options={})
  options.merge!({:body => {:domain => {:name => name}}})

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

  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.



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/dnsimple/domain.rb', line 96

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

  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.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/dnsimple/domain.rb', line 72

def self.register(name, registrant={}, extended_attributes={}, options={})
  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)
  options.merge!({:body => body})

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

  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



180
181
182
183
184
185
186
187
188
189
190
# File 'lib/dnsimple/domain.rb', line 180

def add_service(id_or_short_name, options={})
  options.merge!(:body => {:service => {:id => id_or_short_name}})
  response = DNSimple::Client.post("/v1/domains/#{name}/applied_services", options)

  case response.code
  when 200
    true
  else
    raise RequestError.new("Error adding service", response)
  end
end

#applied_services(options = {}) ⇒ Object



158
159
160
161
162
163
164
165
166
167
# File 'lib/dnsimple/domain.rb', line 158

def applied_services(options={})
  response = DNSimple::Client.get("/v1/domains/#{name}/applied_services", options)

  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.



142
143
144
145
146
147
# File 'lib/dnsimple/domain.rb', line 142

def apply(template, options={})
  options.merge!(:body => {})
  template = resolve_template(template)

  DNSimple::Client.post("/v1/domains/#{name}/templates/#{template.id}/apply", options)
end

#available_services(options = {}) ⇒ Object



169
170
171
172
173
174
175
176
177
178
# File 'lib/dnsimple/domain.rb', line 169

def available_services(options={})
  response = DNSimple::Client.get("/v1/domains/#{name}/available_services", options)

  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.



135
136
137
# File 'lib/dnsimple/domain.rb', line 135

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

#disable_auto_renewObject

Disable auto_renew on the domain



128
129
130
131
# File 'lib/dnsimple/domain.rb', line 128

def disable_auto_renew
  return unless auto_renew
  auto_renew!(:delete)
end

#enable_auto_renewObject

Enable auto_renew on the domain



122
123
124
125
# File 'lib/dnsimple/domain.rb', line 122

def enable_auto_renew
  return if auto_renew
  auto_renew!(:post)
end

#remove_service(id, options = {}) ⇒ Object



192
193
194
195
196
197
198
199
200
201
# File 'lib/dnsimple/domain.rb', line 192

def remove_service(id, options={})
  response = DNSimple::Client.delete("/v1/domains/#{name}/applied_services/#{id}", options)

  case response.code
  when 200
    true
  else
    raise RequestError.new("Error removing service", response)
  end
end

#resolve_template(template) ⇒ Object



149
150
151
152
153
154
155
156
# File 'lib/dnsimple/domain.rb', line 149

def resolve_template(template)
  case template
  when DNSimple::Template
    template
  else
    DNSimple::Template.find(template)
  end
end