Class: TortoiseLabs::DNS::Zone

Inherits:
Object
  • Object
show all
Defined in:
lib/tortoiselabs/dns.rb

Overview

DNS zone class

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zhash) ⇒ Zone

Returns a new instance of Zone.



10
11
12
13
14
15
16
17
18
19
# File 'lib/tortoiselabs/dns.rb', line 10

def initialize(zhash)
  @id, @name, @user = zhash["id"], zhash["name"], zhash["user"]
  @records = Array.new
  
  zhash["records"].each do |record|
    obj = Record.new(record)
    obj.zoneid = @id
    @records << obj
  end
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/tortoiselabs/dns.rb', line 8

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/tortoiselabs/dns.rb', line 8

def name
  @name
end

#recordsObject (readonly)

Returns the value of attribute records.



8
9
10
# File 'lib/tortoiselabs/dns.rb', line 8

def records
  @records
end

#userObject (readonly)

Returns the value of attribute user.



8
9
10
# File 'lib/tortoiselabs/dns.rb', line 8

def user
  @user
end

Class Method Details

.create(domain) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/tortoiselabs/dns.rb', line 54

def self.create(domain)
  TortoiseLabs::Client.post("/dns/zone/new", {:domain_name => domain})
  list = self.list
  if list.keys.include?(domain)
    return list[domain]
  else
    return false
  end
end

.listObject

Class Methods



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/tortoiselabs/dns.rb', line 41

def self.list
  response = TortoiseLabs::Client.get("/dns/zones").parsed_response
  json = JSON.parse(response)
  zones = Hash.new
  
  json["zones"].each do |zone|
    obj = self.new(zone)
    zones[obj.name] = obj
  end
  
  zones
end

Instance Method Details

#deleteObject

Instance Methods



23
24
25
26
# File 'lib/tortoiselabs/dns.rb', line 23

def delete
  resp = TortoiseLabs::Client.get("/dns/zone/#{@id}/delete")
  Zone.list
end

#new_record(subdomain, type, content, ttl = 3600, prio = 0) ⇒ Object



28
29
30
31
32
33
# File 'lib/tortoiselabs/dns.rb', line 28

def new_record(subdomain, type, content, ttl = 3600, prio = 0)
  resp = TortoiseLabs::Client.post("/dns/zone/#{@id}/record/new", 
     {:subdomain => subdomain, :type => type, :ttl => ttl,
      :prio => prio, :content => content})
  Zone.list[@name]
end

#to_sObject



35
36
37
# File 'lib/tortoiselabs/dns.rb', line 35

def to_s
  @name
end