Class: Zerigo::DNS::Host

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

Class Method Summary collapse

Methods inherited from Base

api_key=, #load

Class Method Details

.find_by_hostname(zone, hostname) ⇒ Object

Find by host name



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/zerigo_dns.rb', line 86

def self.find_by_hostname(zone, hostname)
  hosts = find(:all, :params=> { :zone_id => zone }) 
  host = nil
  hosts.each do |h|
    if h.hostname == hostname
      host = h
      break;
    end
  end      
  host
end

.update_or_create(zone, hostname, type, ttl, data) ⇒ Object

Update or Create Host for a zone



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/zerigo_dns.rb', line 99

def self.update_or_create(zone, hostname, type, ttl, data)
  host = find_by_hostname(zone, hostname)
  if host
    # update
    host.host_type  = type
    host.data       = data
    host.ttl        = ttl
    host.save
  else
    # create
    host = create(
      :zone_id    => zone, 
      :hostname   => hostname,
      :host_type  => type,
      :data       => data,
      :ttl        => ttl
    )
  end  
  host
end