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

Parameters:

  • zone (Zone, #read)

    The zone from which to find the host record.

  • hostname (String, #read)

    The hostname to find.

Returns:

  • Host records, or an empty list if no records found.



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

Returns Host records, or an empty list if no records found.

Parameters:

  • hostname (String, #read)

    The hostname to find.

Returns:

  • Host records, or an empty list if no records found.



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

Returns The record found, or nil.

Returns:

  • (Host)

    The record found, or nil.



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.

Parameters:

  • zone (Zone, #read)

    The zone to which the host belongs

  • hostname (String, #read)

    The hostname

  • type (String, #read)

    The type of record (e.g ‘CNAME’)

  • ttl (Fixnum, #read)

    The TTL of the record, in seconds.

  • data (String, #read)

    The data field of the record.

Returns:

  • (Host)

    The created or updated host.



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