Class: DNSimple::Domain

Inherits:
Base
  • Object
show all
Defined in:
lib/dnsimple/domain.rb

Overview

Represents a single domain.

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

#created_atObject

When the domain was created in DNSimple



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

def created_at
  @created_at
end

#idObject

The domain ID in DNSimple



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

def id
  @id
end

#nameObject

The domain name



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

def name
  @name
end

#name_server_statusObject

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_atObject

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(options={})
  response = DNSimple::Client.get("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



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/dnsimple/domain.rb', line 92

def self.check(name, options={})
  response = DNSimple::Client.get("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.



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

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

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

  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, options={})
  id = id_or_name
  response = DNSimple::Client.get("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.



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={}, 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("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



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, options={})
  options.merge!(:body => {:service => {:id => id_or_short_name}})
  response = DNSimple::Client.post("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



46
47
48
49
50
51
52
53
54
55
# File 'lib/dnsimple/domain.rb', line 46

def applied_services(options={})
  response = DNSimple::Client.get("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.



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

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

  DNSimple::Client.post("domains/#{name}/templates/#{template.id}/apply", options)
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(options={})
  response = DNSimple::Client.get("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.



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

def delete(options={})
  DNSimple::Client.delete("domains/#{name}", options)
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, options={})
  response = DNSimple::Client.delete("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

:nodoc:



37
38
39
40
41
42
43
44
# File 'lib/dnsimple/domain.rb', line 37

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