Class: GandiV5::LiveDNS::Zone

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

Overview

A zone within the LiveDNS system. Zones can be used by any number of domains.

Defined Under Namespace

Classes: Snapshot

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

#nameString (readonly)



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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gandi_v5/live_dns/zone.rb', line 27

class Zone
  include GandiV5::Data
  include GandiV5::LiveDNS::HasZoneRecords

  members :uuid, :name
  member :sharing_uuid, gandi_key: 'sharing_id'
  member :soa_retry, gandi_key: 'retry'
  member :soa_minimum, gandi_key: 'minimum'
  member :soa_refresh, gandi_key: 'refresh'
  member :soa_expire, gandi_key: 'expire'
  member :soa_serial, gandi_key: 'serial'
  member :soa_email, gandi_key: 'email'
  member :soa_primary_ns, gandi_key: 'primary_ns'

  alias zone_uuid uuid

  # Generate SOA record for the zone
  # @return [String]
  def to_s
    "@\tIN\tSOA\t#{soa_primary_ns} #{soa_email} (\n" \
    "\t#{soa_serial}\t;Serial\n" \
    "\t#{soa_refresh}\t\t;Refresh\n" \
    "\t#{soa_retry}\t\t;Retry\n" \
    "\t#{soa_expire}\t\t;Expire\n" \
    "\t#{soa_minimum}\t\t;Minimum & Negative TTL\n" \
    ')'
  end

  # List the domains that use this zone.
  # @return [Array<String>] The FQDNs.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def list_domains
    _response, data = GandiV5.get "#{url}/domains"
    data.map { |item| item['fqdn'] }
  end

  # Attach domain to this zone.
  # @param fqdn [String, #fqdn, #to_s] the fully qualified domain name
  #   that should start using this zone.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def attach_domain(fqdn)
    fqdn = fqdn.fqdn if fqdn.respond_to?(:fqdn)
    _resp, data = GandiV5.patch "#{BASE}domains/#{CGI.escape fqdn}", { zone_uuid: uuid }.to_json
    data['message']
  end

  # Get snapshot UUIDs for this zone from Gandi.
  # @return [Hash{String => Time}] Mapping snapshot UUID to time made.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def snapshots
    GandiV5::LiveDNS::Zone::Snapshot.list uuid
  end

  # Get snapshot from Gandi.
  # @param uuid [String] the UUID of the snapshot to fetch.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def snapshot(uuid)
    GandiV5::LiveDNS::Zone::Snapshot.fetch self.uuid, uuid
  end

  # Take a snapshot of this zone.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def take_snapshot
    _response, data = GandiV5.post "#{url}/snapshots"
    snapshot data['uuid']
  end

  # Update this zone.
  # @param name [String, #to_s] new name for the zone.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def update(name:)
    _response, data = GandiV5.patch url, { name: name }.to_json
    self.name = name
    data['message']
  end

  # Delete this zone from Gandi.
  # @return [nil]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    GandiV5.delete url
  end

  # Create a new zone.
  # @param name [String] the name for the created zone.
  # @param sharing_id [String] the UUID of the account to ceate the zone under.
  # @return [GandiV5::LiveDNS::Zone] The created zone.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.create(name, sharing_id: nil)
    params = sharing_id ? { sharing_id: sharing_id } : {}

    response, _data = GandiV5.post(
      url,
      { name: name }.to_json,
      params: params
    )

    fetch response.headers[:location].split('/').last
  end

  # List the zones.
  # @return [Array<GandiV5::LiveDNS::Zone>]
  # @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 zone from Gandi.
  # @param uuid [String, #to_s] the UUID of the zone to fetch.
  # @return [GandiV5::LiveDNS::Zone]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(uuid)
    _response, data = GandiV5.get url(uuid)
    from_gandi data
  end

  private

  def url
    "#{BASE}zones/#{CGI.escape uuid}"
  end

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

#sharing_uuidString (readonly)



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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gandi_v5/live_dns/zone.rb', line 27

class Zone
  include GandiV5::Data
  include GandiV5::LiveDNS::HasZoneRecords

  members :uuid, :name
  member :sharing_uuid, gandi_key: 'sharing_id'
  member :soa_retry, gandi_key: 'retry'
  member :soa_minimum, gandi_key: 'minimum'
  member :soa_refresh, gandi_key: 'refresh'
  member :soa_expire, gandi_key: 'expire'
  member :soa_serial, gandi_key: 'serial'
  member :soa_email, gandi_key: 'email'
  member :soa_primary_ns, gandi_key: 'primary_ns'

  alias zone_uuid uuid

  # Generate SOA record for the zone
  # @return [String]
  def to_s
    "@\tIN\tSOA\t#{soa_primary_ns} #{soa_email} (\n" \
    "\t#{soa_serial}\t;Serial\n" \
    "\t#{soa_refresh}\t\t;Refresh\n" \
    "\t#{soa_retry}\t\t;Retry\n" \
    "\t#{soa_expire}\t\t;Expire\n" \
    "\t#{soa_minimum}\t\t;Minimum & Negative TTL\n" \
    ')'
  end

  # List the domains that use this zone.
  # @return [Array<String>] The FQDNs.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def list_domains
    _response, data = GandiV5.get "#{url}/domains"
    data.map { |item| item['fqdn'] }
  end

  # Attach domain to this zone.
  # @param fqdn [String, #fqdn, #to_s] the fully qualified domain name
  #   that should start using this zone.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def attach_domain(fqdn)
    fqdn = fqdn.fqdn if fqdn.respond_to?(:fqdn)
    _resp, data = GandiV5.patch "#{BASE}domains/#{CGI.escape fqdn}", { zone_uuid: uuid }.to_json
    data['message']
  end

  # Get snapshot UUIDs for this zone from Gandi.
  # @return [Hash{String => Time}] Mapping snapshot UUID to time made.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def snapshots
    GandiV5::LiveDNS::Zone::Snapshot.list uuid
  end

  # Get snapshot from Gandi.
  # @param uuid [String] the UUID of the snapshot to fetch.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def snapshot(uuid)
    GandiV5::LiveDNS::Zone::Snapshot.fetch self.uuid, uuid
  end

  # Take a snapshot of this zone.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def take_snapshot
    _response, data = GandiV5.post "#{url}/snapshots"
    snapshot data['uuid']
  end

  # Update this zone.
  # @param name [String, #to_s] new name for the zone.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def update(name:)
    _response, data = GandiV5.patch url, { name: name }.to_json
    self.name = name
    data['message']
  end

  # Delete this zone from Gandi.
  # @return [nil]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    GandiV5.delete url
  end

  # Create a new zone.
  # @param name [String] the name for the created zone.
  # @param sharing_id [String] the UUID of the account to ceate the zone under.
  # @return [GandiV5::LiveDNS::Zone] The created zone.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.create(name, sharing_id: nil)
    params = sharing_id ? { sharing_id: sharing_id } : {}

    response, _data = GandiV5.post(
      url,
      { name: name }.to_json,
      params: params
    )

    fetch response.headers[:location].split('/').last
  end

  # List the zones.
  # @return [Array<GandiV5::LiveDNS::Zone>]
  # @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 zone from Gandi.
  # @param uuid [String, #to_s] the UUID of the zone to fetch.
  # @return [GandiV5::LiveDNS::Zone]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(uuid)
    _response, data = GandiV5.get url(uuid)
    from_gandi data
  end

  private

  def url
    "#{BASE}zones/#{CGI.escape uuid}"
  end

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

#soa_emailString (readonly)



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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gandi_v5/live_dns/zone.rb', line 27

class Zone
  include GandiV5::Data
  include GandiV5::LiveDNS::HasZoneRecords

  members :uuid, :name
  member :sharing_uuid, gandi_key: 'sharing_id'
  member :soa_retry, gandi_key: 'retry'
  member :soa_minimum, gandi_key: 'minimum'
  member :soa_refresh, gandi_key: 'refresh'
  member :soa_expire, gandi_key: 'expire'
  member :soa_serial, gandi_key: 'serial'
  member :soa_email, gandi_key: 'email'
  member :soa_primary_ns, gandi_key: 'primary_ns'

  alias zone_uuid uuid

  # Generate SOA record for the zone
  # @return [String]
  def to_s
    "@\tIN\tSOA\t#{soa_primary_ns} #{soa_email} (\n" \
    "\t#{soa_serial}\t;Serial\n" \
    "\t#{soa_refresh}\t\t;Refresh\n" \
    "\t#{soa_retry}\t\t;Retry\n" \
    "\t#{soa_expire}\t\t;Expire\n" \
    "\t#{soa_minimum}\t\t;Minimum & Negative TTL\n" \
    ')'
  end

  # List the domains that use this zone.
  # @return [Array<String>] The FQDNs.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def list_domains
    _response, data = GandiV5.get "#{url}/domains"
    data.map { |item| item['fqdn'] }
  end

  # Attach domain to this zone.
  # @param fqdn [String, #fqdn, #to_s] the fully qualified domain name
  #   that should start using this zone.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def attach_domain(fqdn)
    fqdn = fqdn.fqdn if fqdn.respond_to?(:fqdn)
    _resp, data = GandiV5.patch "#{BASE}domains/#{CGI.escape fqdn}", { zone_uuid: uuid }.to_json
    data['message']
  end

  # Get snapshot UUIDs for this zone from Gandi.
  # @return [Hash{String => Time}] Mapping snapshot UUID to time made.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def snapshots
    GandiV5::LiveDNS::Zone::Snapshot.list uuid
  end

  # Get snapshot from Gandi.
  # @param uuid [String] the UUID of the snapshot to fetch.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def snapshot(uuid)
    GandiV5::LiveDNS::Zone::Snapshot.fetch self.uuid, uuid
  end

  # Take a snapshot of this zone.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def take_snapshot
    _response, data = GandiV5.post "#{url}/snapshots"
    snapshot data['uuid']
  end

  # Update this zone.
  # @param name [String, #to_s] new name for the zone.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def update(name:)
    _response, data = GandiV5.patch url, { name: name }.to_json
    self.name = name
    data['message']
  end

  # Delete this zone from Gandi.
  # @return [nil]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    GandiV5.delete url
  end

  # Create a new zone.
  # @param name [String] the name for the created zone.
  # @param sharing_id [String] the UUID of the account to ceate the zone under.
  # @return [GandiV5::LiveDNS::Zone] The created zone.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.create(name, sharing_id: nil)
    params = sharing_id ? { sharing_id: sharing_id } : {}

    response, _data = GandiV5.post(
      url,
      { name: name }.to_json,
      params: params
    )

    fetch response.headers[:location].split('/').last
  end

  # List the zones.
  # @return [Array<GandiV5::LiveDNS::Zone>]
  # @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 zone from Gandi.
  # @param uuid [String, #to_s] the UUID of the zone to fetch.
  # @return [GandiV5::LiveDNS::Zone]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(uuid)
    _response, data = GandiV5.get url(uuid)
    from_gandi data
  end

  private

  def url
    "#{BASE}zones/#{CGI.escape uuid}"
  end

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

#soa_expireInteger (readonly)



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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gandi_v5/live_dns/zone.rb', line 27

class Zone
  include GandiV5::Data
  include GandiV5::LiveDNS::HasZoneRecords

  members :uuid, :name
  member :sharing_uuid, gandi_key: 'sharing_id'
  member :soa_retry, gandi_key: 'retry'
  member :soa_minimum, gandi_key: 'minimum'
  member :soa_refresh, gandi_key: 'refresh'
  member :soa_expire, gandi_key: 'expire'
  member :soa_serial, gandi_key: 'serial'
  member :soa_email, gandi_key: 'email'
  member :soa_primary_ns, gandi_key: 'primary_ns'

  alias zone_uuid uuid

  # Generate SOA record for the zone
  # @return [String]
  def to_s
    "@\tIN\tSOA\t#{soa_primary_ns} #{soa_email} (\n" \
    "\t#{soa_serial}\t;Serial\n" \
    "\t#{soa_refresh}\t\t;Refresh\n" \
    "\t#{soa_retry}\t\t;Retry\n" \
    "\t#{soa_expire}\t\t;Expire\n" \
    "\t#{soa_minimum}\t\t;Minimum & Negative TTL\n" \
    ')'
  end

  # List the domains that use this zone.
  # @return [Array<String>] The FQDNs.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def list_domains
    _response, data = GandiV5.get "#{url}/domains"
    data.map { |item| item['fqdn'] }
  end

  # Attach domain to this zone.
  # @param fqdn [String, #fqdn, #to_s] the fully qualified domain name
  #   that should start using this zone.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def attach_domain(fqdn)
    fqdn = fqdn.fqdn if fqdn.respond_to?(:fqdn)
    _resp, data = GandiV5.patch "#{BASE}domains/#{CGI.escape fqdn}", { zone_uuid: uuid }.to_json
    data['message']
  end

  # Get snapshot UUIDs for this zone from Gandi.
  # @return [Hash{String => Time}] Mapping snapshot UUID to time made.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def snapshots
    GandiV5::LiveDNS::Zone::Snapshot.list uuid
  end

  # Get snapshot from Gandi.
  # @param uuid [String] the UUID of the snapshot to fetch.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def snapshot(uuid)
    GandiV5::LiveDNS::Zone::Snapshot.fetch self.uuid, uuid
  end

  # Take a snapshot of this zone.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def take_snapshot
    _response, data = GandiV5.post "#{url}/snapshots"
    snapshot data['uuid']
  end

  # Update this zone.
  # @param name [String, #to_s] new name for the zone.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def update(name:)
    _response, data = GandiV5.patch url, { name: name }.to_json
    self.name = name
    data['message']
  end

  # Delete this zone from Gandi.
  # @return [nil]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    GandiV5.delete url
  end

  # Create a new zone.
  # @param name [String] the name for the created zone.
  # @param sharing_id [String] the UUID of the account to ceate the zone under.
  # @return [GandiV5::LiveDNS::Zone] The created zone.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.create(name, sharing_id: nil)
    params = sharing_id ? { sharing_id: sharing_id } : {}

    response, _data = GandiV5.post(
      url,
      { name: name }.to_json,
      params: params
    )

    fetch response.headers[:location].split('/').last
  end

  # List the zones.
  # @return [Array<GandiV5::LiveDNS::Zone>]
  # @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 zone from Gandi.
  # @param uuid [String, #to_s] the UUID of the zone to fetch.
  # @return [GandiV5::LiveDNS::Zone]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(uuid)
    _response, data = GandiV5.get url(uuid)
    from_gandi data
  end

  private

  def url
    "#{BASE}zones/#{CGI.escape uuid}"
  end

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

#soa_minimumInteger (readonly)



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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gandi_v5/live_dns/zone.rb', line 27

class Zone
  include GandiV5::Data
  include GandiV5::LiveDNS::HasZoneRecords

  members :uuid, :name
  member :sharing_uuid, gandi_key: 'sharing_id'
  member :soa_retry, gandi_key: 'retry'
  member :soa_minimum, gandi_key: 'minimum'
  member :soa_refresh, gandi_key: 'refresh'
  member :soa_expire, gandi_key: 'expire'
  member :soa_serial, gandi_key: 'serial'
  member :soa_email, gandi_key: 'email'
  member :soa_primary_ns, gandi_key: 'primary_ns'

  alias zone_uuid uuid

  # Generate SOA record for the zone
  # @return [String]
  def to_s
    "@\tIN\tSOA\t#{soa_primary_ns} #{soa_email} (\n" \
    "\t#{soa_serial}\t;Serial\n" \
    "\t#{soa_refresh}\t\t;Refresh\n" \
    "\t#{soa_retry}\t\t;Retry\n" \
    "\t#{soa_expire}\t\t;Expire\n" \
    "\t#{soa_minimum}\t\t;Minimum & Negative TTL\n" \
    ')'
  end

  # List the domains that use this zone.
  # @return [Array<String>] The FQDNs.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def list_domains
    _response, data = GandiV5.get "#{url}/domains"
    data.map { |item| item['fqdn'] }
  end

  # Attach domain to this zone.
  # @param fqdn [String, #fqdn, #to_s] the fully qualified domain name
  #   that should start using this zone.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def attach_domain(fqdn)
    fqdn = fqdn.fqdn if fqdn.respond_to?(:fqdn)
    _resp, data = GandiV5.patch "#{BASE}domains/#{CGI.escape fqdn}", { zone_uuid: uuid }.to_json
    data['message']
  end

  # Get snapshot UUIDs for this zone from Gandi.
  # @return [Hash{String => Time}] Mapping snapshot UUID to time made.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def snapshots
    GandiV5::LiveDNS::Zone::Snapshot.list uuid
  end

  # Get snapshot from Gandi.
  # @param uuid [String] the UUID of the snapshot to fetch.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def snapshot(uuid)
    GandiV5::LiveDNS::Zone::Snapshot.fetch self.uuid, uuid
  end

  # Take a snapshot of this zone.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def take_snapshot
    _response, data = GandiV5.post "#{url}/snapshots"
    snapshot data['uuid']
  end

  # Update this zone.
  # @param name [String, #to_s] new name for the zone.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def update(name:)
    _response, data = GandiV5.patch url, { name: name }.to_json
    self.name = name
    data['message']
  end

  # Delete this zone from Gandi.
  # @return [nil]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    GandiV5.delete url
  end

  # Create a new zone.
  # @param name [String] the name for the created zone.
  # @param sharing_id [String] the UUID of the account to ceate the zone under.
  # @return [GandiV5::LiveDNS::Zone] The created zone.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.create(name, sharing_id: nil)
    params = sharing_id ? { sharing_id: sharing_id } : {}

    response, _data = GandiV5.post(
      url,
      { name: name }.to_json,
      params: params
    )

    fetch response.headers[:location].split('/').last
  end

  # List the zones.
  # @return [Array<GandiV5::LiveDNS::Zone>]
  # @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 zone from Gandi.
  # @param uuid [String, #to_s] the UUID of the zone to fetch.
  # @return [GandiV5::LiveDNS::Zone]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(uuid)
    _response, data = GandiV5.get url(uuid)
    from_gandi data
  end

  private

  def url
    "#{BASE}zones/#{CGI.escape uuid}"
  end

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

#soa_primary_nsString (readonly)



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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gandi_v5/live_dns/zone.rb', line 27

class Zone
  include GandiV5::Data
  include GandiV5::LiveDNS::HasZoneRecords

  members :uuid, :name
  member :sharing_uuid, gandi_key: 'sharing_id'
  member :soa_retry, gandi_key: 'retry'
  member :soa_minimum, gandi_key: 'minimum'
  member :soa_refresh, gandi_key: 'refresh'
  member :soa_expire, gandi_key: 'expire'
  member :soa_serial, gandi_key: 'serial'
  member :soa_email, gandi_key: 'email'
  member :soa_primary_ns, gandi_key: 'primary_ns'

  alias zone_uuid uuid

  # Generate SOA record for the zone
  # @return [String]
  def to_s
    "@\tIN\tSOA\t#{soa_primary_ns} #{soa_email} (\n" \
    "\t#{soa_serial}\t;Serial\n" \
    "\t#{soa_refresh}\t\t;Refresh\n" \
    "\t#{soa_retry}\t\t;Retry\n" \
    "\t#{soa_expire}\t\t;Expire\n" \
    "\t#{soa_minimum}\t\t;Minimum & Negative TTL\n" \
    ')'
  end

  # List the domains that use this zone.
  # @return [Array<String>] The FQDNs.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def list_domains
    _response, data = GandiV5.get "#{url}/domains"
    data.map { |item| item['fqdn'] }
  end

  # Attach domain to this zone.
  # @param fqdn [String, #fqdn, #to_s] the fully qualified domain name
  #   that should start using this zone.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def attach_domain(fqdn)
    fqdn = fqdn.fqdn if fqdn.respond_to?(:fqdn)
    _resp, data = GandiV5.patch "#{BASE}domains/#{CGI.escape fqdn}", { zone_uuid: uuid }.to_json
    data['message']
  end

  # Get snapshot UUIDs for this zone from Gandi.
  # @return [Hash{String => Time}] Mapping snapshot UUID to time made.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def snapshots
    GandiV5::LiveDNS::Zone::Snapshot.list uuid
  end

  # Get snapshot from Gandi.
  # @param uuid [String] the UUID of the snapshot to fetch.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def snapshot(uuid)
    GandiV5::LiveDNS::Zone::Snapshot.fetch self.uuid, uuid
  end

  # Take a snapshot of this zone.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def take_snapshot
    _response, data = GandiV5.post "#{url}/snapshots"
    snapshot data['uuid']
  end

  # Update this zone.
  # @param name [String, #to_s] new name for the zone.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def update(name:)
    _response, data = GandiV5.patch url, { name: name }.to_json
    self.name = name
    data['message']
  end

  # Delete this zone from Gandi.
  # @return [nil]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    GandiV5.delete url
  end

  # Create a new zone.
  # @param name [String] the name for the created zone.
  # @param sharing_id [String] the UUID of the account to ceate the zone under.
  # @return [GandiV5::LiveDNS::Zone] The created zone.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.create(name, sharing_id: nil)
    params = sharing_id ? { sharing_id: sharing_id } : {}

    response, _data = GandiV5.post(
      url,
      { name: name }.to_json,
      params: params
    )

    fetch response.headers[:location].split('/').last
  end

  # List the zones.
  # @return [Array<GandiV5::LiveDNS::Zone>]
  # @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 zone from Gandi.
  # @param uuid [String, #to_s] the UUID of the zone to fetch.
  # @return [GandiV5::LiveDNS::Zone]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(uuid)
    _response, data = GandiV5.get url(uuid)
    from_gandi data
  end

  private

  def url
    "#{BASE}zones/#{CGI.escape uuid}"
  end

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

#soa_refreshInteger (readonly)



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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gandi_v5/live_dns/zone.rb', line 27

class Zone
  include GandiV5::Data
  include GandiV5::LiveDNS::HasZoneRecords

  members :uuid, :name
  member :sharing_uuid, gandi_key: 'sharing_id'
  member :soa_retry, gandi_key: 'retry'
  member :soa_minimum, gandi_key: 'minimum'
  member :soa_refresh, gandi_key: 'refresh'
  member :soa_expire, gandi_key: 'expire'
  member :soa_serial, gandi_key: 'serial'
  member :soa_email, gandi_key: 'email'
  member :soa_primary_ns, gandi_key: 'primary_ns'

  alias zone_uuid uuid

  # Generate SOA record for the zone
  # @return [String]
  def to_s
    "@\tIN\tSOA\t#{soa_primary_ns} #{soa_email} (\n" \
    "\t#{soa_serial}\t;Serial\n" \
    "\t#{soa_refresh}\t\t;Refresh\n" \
    "\t#{soa_retry}\t\t;Retry\n" \
    "\t#{soa_expire}\t\t;Expire\n" \
    "\t#{soa_minimum}\t\t;Minimum & Negative TTL\n" \
    ')'
  end

  # List the domains that use this zone.
  # @return [Array<String>] The FQDNs.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def list_domains
    _response, data = GandiV5.get "#{url}/domains"
    data.map { |item| item['fqdn'] }
  end

  # Attach domain to this zone.
  # @param fqdn [String, #fqdn, #to_s] the fully qualified domain name
  #   that should start using this zone.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def attach_domain(fqdn)
    fqdn = fqdn.fqdn if fqdn.respond_to?(:fqdn)
    _resp, data = GandiV5.patch "#{BASE}domains/#{CGI.escape fqdn}", { zone_uuid: uuid }.to_json
    data['message']
  end

  # Get snapshot UUIDs for this zone from Gandi.
  # @return [Hash{String => Time}] Mapping snapshot UUID to time made.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def snapshots
    GandiV5::LiveDNS::Zone::Snapshot.list uuid
  end

  # Get snapshot from Gandi.
  # @param uuid [String] the UUID of the snapshot to fetch.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def snapshot(uuid)
    GandiV5::LiveDNS::Zone::Snapshot.fetch self.uuid, uuid
  end

  # Take a snapshot of this zone.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def take_snapshot
    _response, data = GandiV5.post "#{url}/snapshots"
    snapshot data['uuid']
  end

  # Update this zone.
  # @param name [String, #to_s] new name for the zone.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def update(name:)
    _response, data = GandiV5.patch url, { name: name }.to_json
    self.name = name
    data['message']
  end

  # Delete this zone from Gandi.
  # @return [nil]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    GandiV5.delete url
  end

  # Create a new zone.
  # @param name [String] the name for the created zone.
  # @param sharing_id [String] the UUID of the account to ceate the zone under.
  # @return [GandiV5::LiveDNS::Zone] The created zone.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.create(name, sharing_id: nil)
    params = sharing_id ? { sharing_id: sharing_id } : {}

    response, _data = GandiV5.post(
      url,
      { name: name }.to_json,
      params: params
    )

    fetch response.headers[:location].split('/').last
  end

  # List the zones.
  # @return [Array<GandiV5::LiveDNS::Zone>]
  # @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 zone from Gandi.
  # @param uuid [String, #to_s] the UUID of the zone to fetch.
  # @return [GandiV5::LiveDNS::Zone]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(uuid)
    _response, data = GandiV5.get url(uuid)
    from_gandi data
  end

  private

  def url
    "#{BASE}zones/#{CGI.escape uuid}"
  end

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

#soa_retryInteger (readonly)



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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gandi_v5/live_dns/zone.rb', line 27

class Zone
  include GandiV5::Data
  include GandiV5::LiveDNS::HasZoneRecords

  members :uuid, :name
  member :sharing_uuid, gandi_key: 'sharing_id'
  member :soa_retry, gandi_key: 'retry'
  member :soa_minimum, gandi_key: 'minimum'
  member :soa_refresh, gandi_key: 'refresh'
  member :soa_expire, gandi_key: 'expire'
  member :soa_serial, gandi_key: 'serial'
  member :soa_email, gandi_key: 'email'
  member :soa_primary_ns, gandi_key: 'primary_ns'

  alias zone_uuid uuid

  # Generate SOA record for the zone
  # @return [String]
  def to_s
    "@\tIN\tSOA\t#{soa_primary_ns} #{soa_email} (\n" \
    "\t#{soa_serial}\t;Serial\n" \
    "\t#{soa_refresh}\t\t;Refresh\n" \
    "\t#{soa_retry}\t\t;Retry\n" \
    "\t#{soa_expire}\t\t;Expire\n" \
    "\t#{soa_minimum}\t\t;Minimum & Negative TTL\n" \
    ')'
  end

  # List the domains that use this zone.
  # @return [Array<String>] The FQDNs.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def list_domains
    _response, data = GandiV5.get "#{url}/domains"
    data.map { |item| item['fqdn'] }
  end

  # Attach domain to this zone.
  # @param fqdn [String, #fqdn, #to_s] the fully qualified domain name
  #   that should start using this zone.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def attach_domain(fqdn)
    fqdn = fqdn.fqdn if fqdn.respond_to?(:fqdn)
    _resp, data = GandiV5.patch "#{BASE}domains/#{CGI.escape fqdn}", { zone_uuid: uuid }.to_json
    data['message']
  end

  # Get snapshot UUIDs for this zone from Gandi.
  # @return [Hash{String => Time}] Mapping snapshot UUID to time made.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def snapshots
    GandiV5::LiveDNS::Zone::Snapshot.list uuid
  end

  # Get snapshot from Gandi.
  # @param uuid [String] the UUID of the snapshot to fetch.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def snapshot(uuid)
    GandiV5::LiveDNS::Zone::Snapshot.fetch self.uuid, uuid
  end

  # Take a snapshot of this zone.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def take_snapshot
    _response, data = GandiV5.post "#{url}/snapshots"
    snapshot data['uuid']
  end

  # Update this zone.
  # @param name [String, #to_s] new name for the zone.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def update(name:)
    _response, data = GandiV5.patch url, { name: name }.to_json
    self.name = name
    data['message']
  end

  # Delete this zone from Gandi.
  # @return [nil]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    GandiV5.delete url
  end

  # Create a new zone.
  # @param name [String] the name for the created zone.
  # @param sharing_id [String] the UUID of the account to ceate the zone under.
  # @return [GandiV5::LiveDNS::Zone] The created zone.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.create(name, sharing_id: nil)
    params = sharing_id ? { sharing_id: sharing_id } : {}

    response, _data = GandiV5.post(
      url,
      { name: name }.to_json,
      params: params
    )

    fetch response.headers[:location].split('/').last
  end

  # List the zones.
  # @return [Array<GandiV5::LiveDNS::Zone>]
  # @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 zone from Gandi.
  # @param uuid [String, #to_s] the UUID of the zone to fetch.
  # @return [GandiV5::LiveDNS::Zone]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(uuid)
    _response, data = GandiV5.get url(uuid)
    from_gandi data
  end

  private

  def url
    "#{BASE}zones/#{CGI.escape uuid}"
  end

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

#soa_serialInteger (readonly)



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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gandi_v5/live_dns/zone.rb', line 27

class Zone
  include GandiV5::Data
  include GandiV5::LiveDNS::HasZoneRecords

  members :uuid, :name
  member :sharing_uuid, gandi_key: 'sharing_id'
  member :soa_retry, gandi_key: 'retry'
  member :soa_minimum, gandi_key: 'minimum'
  member :soa_refresh, gandi_key: 'refresh'
  member :soa_expire, gandi_key: 'expire'
  member :soa_serial, gandi_key: 'serial'
  member :soa_email, gandi_key: 'email'
  member :soa_primary_ns, gandi_key: 'primary_ns'

  alias zone_uuid uuid

  # Generate SOA record for the zone
  # @return [String]
  def to_s
    "@\tIN\tSOA\t#{soa_primary_ns} #{soa_email} (\n" \
    "\t#{soa_serial}\t;Serial\n" \
    "\t#{soa_refresh}\t\t;Refresh\n" \
    "\t#{soa_retry}\t\t;Retry\n" \
    "\t#{soa_expire}\t\t;Expire\n" \
    "\t#{soa_minimum}\t\t;Minimum & Negative TTL\n" \
    ')'
  end

  # List the domains that use this zone.
  # @return [Array<String>] The FQDNs.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def list_domains
    _response, data = GandiV5.get "#{url}/domains"
    data.map { |item| item['fqdn'] }
  end

  # Attach domain to this zone.
  # @param fqdn [String, #fqdn, #to_s] the fully qualified domain name
  #   that should start using this zone.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def attach_domain(fqdn)
    fqdn = fqdn.fqdn if fqdn.respond_to?(:fqdn)
    _resp, data = GandiV5.patch "#{BASE}domains/#{CGI.escape fqdn}", { zone_uuid: uuid }.to_json
    data['message']
  end

  # Get snapshot UUIDs for this zone from Gandi.
  # @return [Hash{String => Time}] Mapping snapshot UUID to time made.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def snapshots
    GandiV5::LiveDNS::Zone::Snapshot.list uuid
  end

  # Get snapshot from Gandi.
  # @param uuid [String] the UUID of the snapshot to fetch.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def snapshot(uuid)
    GandiV5::LiveDNS::Zone::Snapshot.fetch self.uuid, uuid
  end

  # Take a snapshot of this zone.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def take_snapshot
    _response, data = GandiV5.post "#{url}/snapshots"
    snapshot data['uuid']
  end

  # Update this zone.
  # @param name [String, #to_s] new name for the zone.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def update(name:)
    _response, data = GandiV5.patch url, { name: name }.to_json
    self.name = name
    data['message']
  end

  # Delete this zone from Gandi.
  # @return [nil]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    GandiV5.delete url
  end

  # Create a new zone.
  # @param name [String] the name for the created zone.
  # @param sharing_id [String] the UUID of the account to ceate the zone under.
  # @return [GandiV5::LiveDNS::Zone] The created zone.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.create(name, sharing_id: nil)
    params = sharing_id ? { sharing_id: sharing_id } : {}

    response, _data = GandiV5.post(
      url,
      { name: name }.to_json,
      params: params
    )

    fetch response.headers[:location].split('/').last
  end

  # List the zones.
  # @return [Array<GandiV5::LiveDNS::Zone>]
  # @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 zone from Gandi.
  # @param uuid [String, #to_s] the UUID of the zone to fetch.
  # @return [GandiV5::LiveDNS::Zone]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(uuid)
    _response, data = GandiV5.get url(uuid)
    from_gandi data
  end

  private

  def url
    "#{BASE}zones/#{CGI.escape uuid}"
  end

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

#uuidString (readonly) Also known as: zone_uuid



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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gandi_v5/live_dns/zone.rb', line 27

class Zone
  include GandiV5::Data
  include GandiV5::LiveDNS::HasZoneRecords

  members :uuid, :name
  member :sharing_uuid, gandi_key: 'sharing_id'
  member :soa_retry, gandi_key: 'retry'
  member :soa_minimum, gandi_key: 'minimum'
  member :soa_refresh, gandi_key: 'refresh'
  member :soa_expire, gandi_key: 'expire'
  member :soa_serial, gandi_key: 'serial'
  member :soa_email, gandi_key: 'email'
  member :soa_primary_ns, gandi_key: 'primary_ns'

  alias zone_uuid uuid

  # Generate SOA record for the zone
  # @return [String]
  def to_s
    "@\tIN\tSOA\t#{soa_primary_ns} #{soa_email} (\n" \
    "\t#{soa_serial}\t;Serial\n" \
    "\t#{soa_refresh}\t\t;Refresh\n" \
    "\t#{soa_retry}\t\t;Retry\n" \
    "\t#{soa_expire}\t\t;Expire\n" \
    "\t#{soa_minimum}\t\t;Minimum & Negative TTL\n" \
    ')'
  end

  # List the domains that use this zone.
  # @return [Array<String>] The FQDNs.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def list_domains
    _response, data = GandiV5.get "#{url}/domains"
    data.map { |item| item['fqdn'] }
  end

  # Attach domain to this zone.
  # @param fqdn [String, #fqdn, #to_s] the fully qualified domain name
  #   that should start using this zone.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def attach_domain(fqdn)
    fqdn = fqdn.fqdn if fqdn.respond_to?(:fqdn)
    _resp, data = GandiV5.patch "#{BASE}domains/#{CGI.escape fqdn}", { zone_uuid: uuid }.to_json
    data['message']
  end

  # Get snapshot UUIDs for this zone from Gandi.
  # @return [Hash{String => Time}] Mapping snapshot UUID to time made.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def snapshots
    GandiV5::LiveDNS::Zone::Snapshot.list uuid
  end

  # Get snapshot from Gandi.
  # @param uuid [String] the UUID of the snapshot to fetch.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def snapshot(uuid)
    GandiV5::LiveDNS::Zone::Snapshot.fetch self.uuid, uuid
  end

  # Take a snapshot of this zone.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def take_snapshot
    _response, data = GandiV5.post "#{url}/snapshots"
    snapshot data['uuid']
  end

  # Update this zone.
  # @param name [String, #to_s] new name for the zone.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def update(name:)
    _response, data = GandiV5.patch url, { name: name }.to_json
    self.name = name
    data['message']
  end

  # Delete this zone from Gandi.
  # @return [nil]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    GandiV5.delete url
  end

  # Create a new zone.
  # @param name [String] the name for the created zone.
  # @param sharing_id [String] the UUID of the account to ceate the zone under.
  # @return [GandiV5::LiveDNS::Zone] The created zone.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.create(name, sharing_id: nil)
    params = sharing_id ? { sharing_id: sharing_id } : {}

    response, _data = GandiV5.post(
      url,
      { name: name }.to_json,
      params: params
    )

    fetch response.headers[:location].split('/').last
  end

  # List the zones.
  # @return [Array<GandiV5::LiveDNS::Zone>]
  # @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 zone from Gandi.
  # @param uuid [String, #to_s] the UUID of the zone to fetch.
  # @return [GandiV5::LiveDNS::Zone]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(uuid)
    _response, data = GandiV5.get url(uuid)
    from_gandi data
  end

  private

  def url
    "#{BASE}zones/#{CGI.escape uuid}"
  end

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

Class Method Details

.create(name, sharing_id: nil) ⇒ GandiV5::LiveDNS::Zone

Create a new zone.

Raises:



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/gandi_v5/live_dns/zone.rb', line 119

def self.create(name, sharing_id: nil)
  params = sharing_id ? { sharing_id: sharing_id } : {}

  response, _data = GandiV5.post(
    url,
    { name: name }.to_json,
    params: params
  )

  fetch response.headers[:location].split('/').last
end

.fetch(uuid) ⇒ GandiV5::LiveDNS::Zone

Get a zone from Gandi.

Raises:



143
144
145
146
# File 'lib/gandi_v5/live_dns/zone.rb', line 143

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

.listArray<GandiV5::LiveDNS::Zone>

List the zones.

Raises:



134
135
136
137
# File 'lib/gandi_v5/live_dns/zone.rb', line 134

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

Instance Method Details

#attach_domain(fqdn) ⇒ String

Attach domain to this zone.

Raises:



68
69
70
71
72
# File 'lib/gandi_v5/live_dns/zone.rb', line 68

def attach_domain(fqdn)
  fqdn = fqdn.fqdn if fqdn.respond_to?(:fqdn)
  _resp, data = GandiV5.patch "#{BASE}domains/#{CGI.escape fqdn}", { zone_uuid: uuid }.to_json
  data['message']
end

#deletenil

Delete this zone from Gandi.

Raises:



110
111
112
# File 'lib/gandi_v5/live_dns/zone.rb', line 110

def delete
  GandiV5.delete url
end

#list_domainsArray<String>

List the domains that use this zone.

Raises:



58
59
60
61
# File 'lib/gandi_v5/live_dns/zone.rb', line 58

def list_domains
  _response, data = GandiV5.get "#{url}/domains"
  data.map { |item| item['fqdn'] }
end

#snapshot(uuid) ⇒ GandiV5::LiveDNS::Zone::Snapshot

Get snapshot from Gandi.

Raises:



85
86
87
# File 'lib/gandi_v5/live_dns/zone.rb', line 85

def snapshot(uuid)
  GandiV5::LiveDNS::Zone::Snapshot.fetch self.uuid, uuid
end

#snapshotsHash{String => Time}

Get snapshot UUIDs for this zone from Gandi.

Raises:



77
78
79
# File 'lib/gandi_v5/live_dns/zone.rb', line 77

def snapshots
  GandiV5::LiveDNS::Zone::Snapshot.list uuid
end

#take_snapshotGandiV5::LiveDNS::Zone::Snapshot

Take a snapshot of this zone.

Raises:



92
93
94
95
# File 'lib/gandi_v5/live_dns/zone.rb', line 92

def take_snapshot
  _response, data = GandiV5.post "#{url}/snapshots"
  snapshot data['uuid']
end

#to_sString

Generate SOA record for the zone



45
46
47
48
49
50
51
52
53
# File 'lib/gandi_v5/live_dns/zone.rb', line 45

def to_s
  "@\tIN\tSOA\t#{soa_primary_ns} #{soa_email} (\n" \
  "\t#{soa_serial}\t;Serial\n" \
  "\t#{soa_refresh}\t\t;Refresh\n" \
  "\t#{soa_retry}\t\t;Retry\n" \
  "\t#{soa_expire}\t\t;Expire\n" \
  "\t#{soa_minimum}\t\t;Minimum & Negative TTL\n" \
  ')'
end

#update(name:) ⇒ String

Update this zone.

Raises:



101
102
103
104
105
# File 'lib/gandi_v5/live_dns/zone.rb', line 101

def update(name:)
  _response, data = GandiV5.patch url, { name: name }.to_json
  self.name = name
  data['message']
end