Class: ZerigoDNS::Host

Inherits:
Client
  • Object
show all
Includes:
Resource
Defined in:
lib/zerigodns/host.rb

Constant Summary

Constants inherited from Client

Client::ACTIONS, Client::ResponseError

Instance Attribute Summary

Attributes inherited from Client

#response

Class Method Summary collapse

Methods included from Resource

included

Methods inherited from Client

connection

Class Method Details

.find_all_by_hostname(zone, hostname) ⇒ Object

Find host record(s) by zone and hostname



29
30
31
32
# File 'lib/zerigodns/host.rb', line 29

def find_all_by_hostname zone, hostname
  fqdn = [hostname, zone.domain].reject(&:nil?).reject(&:empty?).join('.')
  all(fqdn: fqdn, zone_id: zone.id)
end

.find_by_zone_and_hostname(which, zone, hostname) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/zerigodns/host.rb', line 14

def find_by_zone_and_hostname which, zone, hostname
  if which == :all
    find_all_by_hostname(zone, hostname)
  else
    find_all_by_hostname(zone, hostname).send(which)
  end
end

.find_first_by_hostname(zone, hostname) ⇒ Host



35
36
37
# File 'lib/zerigodns/host.rb', line 35

def find_first_by_hostname zone, hostname
  find_all_by_hostname(zone, hostname).first
end

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

Update or Create Host for a zone This method will only update the first record.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/zerigodns/host.rb', line 47

def update_or_create(zone, hostname, type, ttl, data)
  host = find_first_by_hostname(zone, hostname)
  if host
    host.update(ttl: ttl, host_type: type, data: data)
  else
    host = create(
      :zone_id    => zone.id, 
      :hostname   => hostname,
      :host_type  => type,
      :data       => data,
      :ttl        => ttl
    )
  end  
  host
end