Class: GandiV5::LiveDNS::Domain

Inherits:
Object
  • Object
show all
Includes:
Data, HasZoneRecords
Defined in:
lib/gandi_v5/live_dns/domain.rb

Overview

A domain name within the LiveDNS system.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasZoneRecords

#add_record, #delete_records, #fetch_records, #fetch_zone_lines, #replace_records, #replace_records_for

Methods included from Data

#from_gandi, included, #initialize, #to_gandi, #to_h, #values_at

Instance Attribute Details

#fqdnString (readonly)

Returns:

  • (String)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/gandi_v5/live_dns/domain.rb', line 10

class Domain
  include GandiV5::Data
  include GandiV5::LiveDNS::HasZoneRecords

  members :fqdn

  member(
    :zone_uuid,
    gandi_key: 'zone',
    converter: GandiV5::Data::Converter.new(from_gandi: ->(zone) { zone&.split('/')&.last })
  )

  # Refetch the information for this domain from Gandi.
  # @return [GandiV5::LiveDNS::Domain]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def refresh
    _response, data = GandiV5.get url
    from_gandi data
  end

  # Change the zone used by this domain.
  # @param uuid [String, #uuid, #to_s] the UUID of the zone this domain should now use.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def change_zone(uuid)
    uuid = uuid.uuid if uuid.respond_to?(:uuid)
    _response, data = GandiV5.patch url, { zone_uuid: uuid }.to_json
    self.zone_uuid = uuid
    data['message']
  end

  # @see GandiV5::LiveDNS::Zone.fetch
  def fetch_zone
    GandiV5::LiveDNS::Zone.fetch zone_uuid
  end

  # The domain's zone (fetching from Gandi if required).
  # @return [GandiV5::LiveDNS::Zone]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def zone
    @zone ||= fetch_zone
  end

  # List the domains.
  # @return [Array<GandiV5::LiveDNS::Domain>]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.list
    _response, data = GandiV5.get url
    data.map { |item| from_gandi item }
  end

  # Get a domain.
  # @param fqdn [String, #to_s] the fully qualified domain name to fetch.
  # @return [GandiV5::LiveDNS::Domain]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(fqdn)
    _response, data = GandiV5.get url(fqdn)
    from_gandi data
  end

  private

  def url
    "#{BASE}domains/#{CGI.escape(fqdn)}"
  end

  def self.url(fqdn = nil)
    "#{BASE}domains" + (fqdn ? "/#{CGI.escape(fqdn)}" : '')
  end
  private_class_method :url
end

#zone_uuidString (readonly)

Returns:

  • (String)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/gandi_v5/live_dns/domain.rb', line 10

class Domain
  include GandiV5::Data
  include GandiV5::LiveDNS::HasZoneRecords

  members :fqdn

  member(
    :zone_uuid,
    gandi_key: 'zone',
    converter: GandiV5::Data::Converter.new(from_gandi: ->(zone) { zone&.split('/')&.last })
  )

  # Refetch the information for this domain from Gandi.
  # @return [GandiV5::LiveDNS::Domain]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def refresh
    _response, data = GandiV5.get url
    from_gandi data
  end

  # Change the zone used by this domain.
  # @param uuid [String, #uuid, #to_s] the UUID of the zone this domain should now use.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def change_zone(uuid)
    uuid = uuid.uuid if uuid.respond_to?(:uuid)
    _response, data = GandiV5.patch url, { zone_uuid: uuid }.to_json
    self.zone_uuid = uuid
    data['message']
  end

  # @see GandiV5::LiveDNS::Zone.fetch
  def fetch_zone
    GandiV5::LiveDNS::Zone.fetch zone_uuid
  end

  # The domain's zone (fetching from Gandi if required).
  # @return [GandiV5::LiveDNS::Zone]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def zone
    @zone ||= fetch_zone
  end

  # List the domains.
  # @return [Array<GandiV5::LiveDNS::Domain>]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.list
    _response, data = GandiV5.get url
    data.map { |item| from_gandi item }
  end

  # Get a domain.
  # @param fqdn [String, #to_s] the fully qualified domain name to fetch.
  # @return [GandiV5::LiveDNS::Domain]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(fqdn)
    _response, data = GandiV5.get url(fqdn)
    from_gandi data
  end

  private

  def url
    "#{BASE}domains/#{CGI.escape(fqdn)}"
  end

  def self.url(fqdn = nil)
    "#{BASE}domains" + (fqdn ? "/#{CGI.escape(fqdn)}" : '')
  end
  private_class_method :url
end

Class Method Details

.fetch(fqdn) ⇒ GandiV5::LiveDNS::Domain

Get a domain.

Parameters:

  • fqdn (String, #to_s)

    the fully qualified domain name to fetch.

Returns:

Raises:



65
66
67
68
# File 'lib/gandi_v5/live_dns/domain.rb', line 65

def self.fetch(fqdn)
  _response, data = GandiV5.get url(fqdn)
  from_gandi data
end

.listArray<GandiV5::LiveDNS::Domain>

List the domains.

Returns:

Raises:



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

def self.list
  _response, data = GandiV5.get url
  data.map { |item| from_gandi item }
end

Instance Method Details

#change_zone(uuid) ⇒ String

Change the zone used by this domain.

Parameters:

  • uuid (String, #uuid, #to_s)

    the UUID of the zone this domain should now use.

Returns:

  • (String)

    The confirmation message from Gandi.

Raises:



34
35
36
37
38
39
# File 'lib/gandi_v5/live_dns/domain.rb', line 34

def change_zone(uuid)
  uuid = uuid.uuid if uuid.respond_to?(:uuid)
  _response, data = GandiV5.patch url, { zone_uuid: uuid }.to_json
  self.zone_uuid = uuid
  data['message']
end

#fetch_zoneObject

See Also:



42
43
44
# File 'lib/gandi_v5/live_dns/domain.rb', line 42

def fetch_zone
  GandiV5::LiveDNS::Zone.fetch zone_uuid
end

#refreshGandiV5::LiveDNS::Domain

Refetch the information for this domain from Gandi.

Returns:

Raises:



25
26
27
28
# File 'lib/gandi_v5/live_dns/domain.rb', line 25

def refresh
  _response, data = GandiV5.get url
  from_gandi data
end

#zoneGandiV5::LiveDNS::Zone

The domain’s zone (fetching from Gandi if required).

Returns:

Raises:



49
50
51
# File 'lib/gandi_v5/live_dns/domain.rb', line 49

def zone
  @zone ||= fetch_zone
end