Class: DNSApp::Domain

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Object

check_required_keys, delete, get, #initialize, #parent_id, #parent_id=, post, put

Constructor Details

This class inherits a constructor from DNSApp::Object

Instance Attribute Details

#auth_idObject

The AUTHID for the domain. Used for transfers.



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

def auth_id
  @auth_id
end

#authoritativeObject

Whether DNSApp.net is authoritative for the domain If false the domain doesn’t point to the DNSApp.net nameservers



19
20
21
# File 'lib/dnsapp/domain.rb', line 19

def authoritative
  @authoritative
end

#created_atObject

When the domain was created



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

def created_at
  @created_at
end

#handleObject

The domain handle



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

def handle
  @handle
end

#idObject

id for the domain



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

def id
  @id
end

#lockedObject

Whether the domain is locked. Must be false if you wish to transfer.



27
28
29
# File 'lib/dnsapp/domain.rb', line 27

def locked
  @locked
end

#nameObject

The domain name



10
11
12
# File 'lib/dnsapp/domain.rb', line 10

def name
  @name
end

#statusObject

The status of the domain



25
26
27
# File 'lib/dnsapp/domain.rb', line 25

def status
  @status
end

#updated_atObject

When the domain was updated



16
17
18
# File 'lib/dnsapp/domain.rb', line 16

def updated_at
  @updated_at
end

#user_idObject

The user_id for the domain



21
22
23
# File 'lib/dnsapp/domain.rb', line 21

def user_id
  @user_id
end

Class Method Details

.allObject

Retrives all domains



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

def all        
  response = get("/domains")["domains"]        
  response.collect { |attributes| Domain.new attributes }
end

.create(name) ⇒ Object

Creates a new domain name must be without www or similar.

Example

DNSApp::Domain.create("example.org")


65
66
67
68
69
70
71
72
73
74
# File 'lib/dnsapp/domain.rb', line 65

def create(name)
  name.is_a? String or raise TypeError, "name must be string"
  r = post("/domains", :query => {"domain[name]" => name})
  r["errors"] and raise StandardError, r["errors"]["error"].to_a.join(", ")
  if r.code == 201
    Domain.new r["domain"]
  else
    raise StandardError, 'Could not create the domain'
  end        
end

.find(id_or_name) ⇒ Object

Find domain by id or name

Example

DNSApp::Domain.find(10)
DNSApp::Domain.find("example.org")


40
41
42
43
44
45
46
# File 'lib/dnsapp/domain.rb', line 40

def find(id_or_name)
  if id_or_name.is_a?(Integer)
    find_by_id(id_or_name)
  else
    find_by_name(id_or_name)
  end
end

.find_by_id(id) ⇒ Object

Find domain by id



49
50
51
52
53
# File 'lib/dnsapp/domain.rb', line 49

def find_by_id(id)
  response = get("/domains/#{id}")["domain"]
  response or return nil
  Domain.new response
end

.find_by_name(name) ⇒ Object

Find domain by name



56
57
58
59
# File 'lib/dnsapp/domain.rb', line 56

def find_by_name(name)
  domain = self.all.select { |d| d.name == name }
  return domain.blank? ? nil : domain.first
end

Instance Method Details

#destroyObject

Deletes the domain. This cannot be undone. Returns the deleted domain object.

Example

DNSApp::Domain.find(10).destroy


82
83
84
85
86
87
88
89
# File 'lib/dnsapp/domain.rb', line 82

def destroy
  r = self.class.delete("/domains/#{self.id}")
  if r.code == 200
    self
  else
    raise StandardError, 'Could not delete the domain'
  end      
end

#recordsObject

Get records on the domain.

Example

DNSApp::Domain.find(10).records.all
DNSApp::Domain.find(10).records.create(:name => '%d', :content => '1.2.3.4', :type => 'A', :ttl => 3600)


95
96
97
98
# File 'lib/dnsapp/domain.rb', line 95

def records
  @@parent_id = self.id
  DNSApp::Record
end