gandi_v5 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +27 -0
  3. data/README.md +3 -2
  4. data/lib/gandi_v5.rb +34 -13
  5. data/lib/gandi_v5/domain.rb +2 -8
  6. data/lib/gandi_v5/email/forward.rb +2 -8
  7. data/lib/gandi_v5/email/mailbox.rb +2 -8
  8. data/lib/gandi_v5/live_dns.rb +0 -12
  9. data/lib/gandi_v5/live_dns/domain.rb +313 -29
  10. data/lib/gandi_v5/live_dns/domain/dnssec_key.rb +115 -0
  11. data/lib/gandi_v5/live_dns/domain/record.rb +81 -0
  12. data/lib/gandi_v5/live_dns/domain/snapshot.rb +107 -0
  13. data/lib/gandi_v5/live_dns/domain/tsig_key.rb +71 -0
  14. data/lib/gandi_v5/version.rb +1 -1
  15. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/fetch.yml +1 -2
  16. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/list_tsig.yml +3 -0
  17. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/nameservers.yml +3 -0
  18. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/fetch.yml +12 -0
  19. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/list.yml +9 -0
  20. data/spec/fixtures/bodies/{GandiV5_LiveDNS_Zone_Snapshot → GandiV5_LiveDNS_Domain_Snapshot}/fetch.yml +4 -3
  21. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_Snapshot/list.yml +5 -0
  22. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/fetch.yml +9 -0
  23. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/list.yml +4 -0
  24. data/spec/units/gandi_v5/domain_spec.rb +6 -37
  25. data/spec/units/gandi_v5/email/forward_spec.rb +5 -34
  26. data/spec/units/gandi_v5/email/mailbox_spec.rb +4 -34
  27. data/spec/units/gandi_v5/live_dns/domain/dnssec_key_spec.rb +128 -0
  28. data/spec/units/gandi_v5/live_dns/{record_set_spec.rb → domain/record_spec.rb} +1 -1
  29. data/spec/units/gandi_v5/live_dns/domain/snapshot_spec.rb +101 -0
  30. data/spec/units/gandi_v5/live_dns/domain/tsig_key_spec.rb +78 -0
  31. data/spec/units/gandi_v5/live_dns/domain_spec.rb +297 -118
  32. data/spec/units/gandi_v5/live_dns_spec.rb +0 -12
  33. data/spec/units/gandi_v5_spec.rb +111 -14
  34. metadata +18 -24
  35. data/lib/gandi_v5/live_dns/has_zone_records.rb +0 -153
  36. data/lib/gandi_v5/live_dns/record_set.rb +0 -79
  37. data/lib/gandi_v5/live_dns/zone.rb +0 -160
  38. data/lib/gandi_v5/live_dns/zone/snapshot.rb +0 -81
  39. data/spec/features/domain_spec.rb +0 -45
  40. data/spec/features/livedns_domain_spec.rb +0 -8
  41. data/spec/features/livedns_zone_spec.rb +0 -44
  42. data/spec/features/mailbox_spec.rb +0 -18
  43. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/fetch.yml +0 -11
  44. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/list.yml +0 -11
  45. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone_Snapshot/list.yml +0 -3
  46. data/spec/fixtures/vcr/Domain_features/List_domains.yml +0 -55
  47. data/spec/fixtures/vcr/Domain_features/Renew_domain.yml +0 -133
  48. data/spec/fixtures/vcr/LiveDNS_Domain_features/List_domains.yml +0 -32
  49. data/spec/fixtures/vcr/LiveDNS_Zone_features/List_zones.yml +0 -42
  50. data/spec/fixtures/vcr/LiveDNS_Zone_features/Make_and_save_snapshot.yml +0 -72
  51. data/spec/fixtures/vcr/LiveDNS_Zone_features/Save_zone_to_file.yml +0 -28
  52. data/spec/fixtures/vcr/Mailbox_features/List_mailboxes.yml +0 -39
  53. data/spec/units/gandi_v5/live_dns/zone/snapshot_spec.rb +0 -66
  54. data/spec/units/gandi_v5/live_dns/zone_spec.rb +0 -347
@@ -13,18 +13,6 @@ describe GandiV5::LiveDNS do
13
13
  expect(described_class.domains).to be returns
14
14
  end
15
15
 
16
- it '.zone' do
17
- returns = double GandiV5::LiveDNS::Zone
18
- expect(GandiV5::LiveDNS::Zone).to receive(:fetch).with('zone-uuid').and_return(returns)
19
- expect(described_class.zone('zone-uuid')).to be returns
20
- end
21
-
22
- it '.zones' do
23
- returns = double Array
24
- expect(GandiV5::LiveDNS::Zone).to receive(:list).and_return(returns)
25
- expect(described_class.zones).to be returns
26
- end
27
-
28
16
  describe '.require_valid_record_type' do
29
17
  it 'Does nothing for valid type' do
30
18
  expect { described_class.require_valid_record_type 'A' }.to_not raise_error
@@ -57,8 +57,10 @@ describe GandiV5 do
57
57
  response_data = { 'hello' => 'world' }
58
58
  response = double RestClient::Response, body: response_data.to_json, headers: { content_type: 'application/json' }
59
59
  expect(described_class).to receive(:prepare_headers)
60
- expect(RestClient).to receive(method).with('url', hash_including(accept: 'application/json')).and_return(response)
61
- expect(described_class.send(method, 'url', accept: 'application/json')).to match_array [response, response_data]
60
+ expect(RestClient).to receive(method).with('url', hash_including(accept: 'application/json'))
61
+ .and_return(response)
62
+ expect(described_class.send(method, 'url', accept: 'application/json'))
63
+ .to match_array [response, response_data]
62
64
  end
63
65
 
64
66
  it 'As text' do
@@ -75,7 +77,7 @@ describe GandiV5 do
75
77
  end
76
78
 
77
79
  it 'Adds authentication header' do
78
- expect(RestClient).to receive(method).with(anything, hash_including(Authorization: 'Apikey abdce12345'))
80
+ expect(RestClient).to receive(method).with(anything, hash_including(authorization: 'Apikey abdce12345'))
79
81
  .and_return(response)
80
82
  expect(described_class).to receive(:parse_response)
81
83
  expect(described_class.send(method, 'https://api.gandi.net/v5/')).to match_array [response, nil]
@@ -146,7 +148,7 @@ describe GandiV5 do
146
148
  end
147
149
 
148
150
  it 'Adds authentication header' do
149
- expect(RestClient).to receive(method).with(any_args, hash_including(Authorization: 'Apikey abdce12345'))
151
+ expect(RestClient).to receive(method).with(any_args, hash_including(authorization: 'Apikey abdce12345'))
150
152
  .and_return(response)
151
153
  expect(described_class).to receive(:parse_response)
152
154
  expect(described_class.send(method, 'https://api.gandi.net/v5/', payload)).to match_array [response, nil]
@@ -168,20 +170,23 @@ describe GandiV5 do
168
170
  end
169
171
  end
170
172
 
171
- describe 'Generates correct authorisation header' do
172
- it 'When requesting from main V5 API' do
173
- expect(described_class.send(:authorisation_header, 'https://api.gandi.net/v5/example'))
174
- .to eq(Authorization: "Apikey #{api_key}")
173
+ describe 'Prepares headers' do
174
+ it 'Sets accept it not present' do
175
+ headers = {}
176
+ described_class.send(:prepare_headers, headers, GandiV5::BASE)
177
+ expect(headers[:accept]).to eq 'application/json'
175
178
  end
176
179
 
177
- it 'When requesting from main LiveDNS V5 API' do
178
- expect(described_class.send(:authorisation_header, 'https://dns.api.gandi.net/api/v5/example'))
179
- .to eq('X-Api-Key': api_key)
180
+ it 'Leaves accept alone if present' do
181
+ headers = { accept: 'leave/alone' }
182
+ described_class.send(:prepare_headers, headers, GandiV5::BASE)
183
+ expect(headers[:accept]).to eq 'leave/alone'
180
184
  end
181
185
 
182
- it 'Raises ArgumentError when requesting an unknown url' do
183
- expect { described_class.send(:authorisation_header, 'https://unknown.example.com') }
184
- .to raise_error ArgumentError, 'Don\'t know how to authorise for url: https://unknown.example.com'
186
+ it 'Sets authorization' do
187
+ headers = {}
188
+ described_class.send(:prepare_headers, headers, GandiV5::BASE)
189
+ expect(headers[:authorization]).to eq "Apikey #{api_key}"
185
190
  end
186
191
  end
187
192
 
@@ -238,4 +243,96 @@ describe GandiV5 do
238
243
  .to raise_error GandiV5::Error::GandiError, 'field: message'
239
244
  end
240
245
  end
246
+
247
+ describe '.paginated_get' do
248
+ let(:url) { "#{GandiV5::BASE}test/url" }
249
+ let(:do_nothing) { ->(_this_data) { nil } }
250
+
251
+ it 'Keeps fetching until getting a partial list' do
252
+ headers1 = { params: { 'page' => 1, 'per_page' => 2 } }
253
+ headers2 = { params: { 'page' => 2, 'per_page' => 2 } }
254
+ expect(GandiV5).to receive(:get).with(url, headers1)
255
+ .ordered
256
+ .and_return([nil, %i[a b]])
257
+ expect(GandiV5).to receive(:get).with(url, headers2)
258
+ .ordered
259
+ .and_return([nil, %i[c]])
260
+
261
+ described_class.paginated_get(url, (1..2), 2, &do_nothing)
262
+ end
263
+
264
+ it 'Keeps fetching until getting an empty list' do
265
+ headers1 = { params: { 'page' => 1, 'per_page' => 2 } }
266
+ headers2 = { params: { 'page' => 2, 'per_page' => 2 } }
267
+ expect(GandiV5).to receive(:get).with(url, headers1)
268
+ .ordered
269
+ .and_return([nil, %i[a b]])
270
+ expect(GandiV5).to receive(:get).with(url, headers2)
271
+ .ordered
272
+ .and_return([nil, []])
273
+
274
+ described_class.paginated_get(url, (1..2), 2, &do_nothing)
275
+ end
276
+
277
+ it 'Passes per_page option' do
278
+ headers = { params: { 'page' => 1, 'per_page' => 100 } }
279
+ expect(GandiV5).to receive(:get).with(url, headers)
280
+ .and_return([nil, []])
281
+ described_class.paginated_get(url, 1, 100, &do_nothing)
282
+ end
283
+
284
+ it 'Passes on other params' do
285
+ headers = { params: { 'page' => 1, 'per_page' => 100, 'custom' => 'value' } }
286
+ expect(GandiV5).to receive(:get).with(url, headers)
287
+ .and_return([nil, []])
288
+ described_class.paginated_get(url, 1, 100, params: { custom: 'value' }, &do_nothing)
289
+ end
290
+
291
+ it 'Passes on other headers' do
292
+ headers = { params: { 'page' => 1, 'per_page' => 100 }, custom: :value }
293
+ expect(GandiV5).to receive(:get).with(url, headers)
294
+ .and_return([nil, []])
295
+ described_class.paginated_get(url, 1, 100, custom: :value, &do_nothing)
296
+ end
297
+
298
+ describe 'Honors passed pages' do
299
+ it 'Has an each method' do
300
+ headers1 = { params: { 'page' => 1, 'per_page' => 2 } }
301
+ headers2 = { params: { 'page' => 2, 'per_page' => 2 } }
302
+ expect(GandiV5).to receive(:get).with(url, headers1)
303
+ .ordered
304
+ .and_return([nil, %i[a b]])
305
+ expect(GandiV5).to receive(:get).with(url, headers2)
306
+ .ordered
307
+ .and_return([nil, %i[c d]])
308
+
309
+ described_class.paginated_get(url, (1..2), 2, &do_nothing)
310
+ end
311
+
312
+ it 'Positive integer' do
313
+ headers = { params: { 'page' => 3, 'per_page' => 2 } }
314
+ expect(GandiV5).to receive(:get).with(url, headers)
315
+ .ordered
316
+ .and_return([nil, %i[a b c]])
317
+ described_class.paginated_get(url, 3, 2, &do_nothing)
318
+ end
319
+
320
+ it 'Nonpositive integer' do
321
+ expect { described_class.paginated_get(url, -3, 2, &do_nothing) }.to \
322
+ raise_error ArgumentError, 'page must be positive'
323
+ end
324
+ end
325
+
326
+ it 'Relies on caller to build their list' do
327
+ this_data = [:a]
328
+ expect(GandiV5).to receive(:get).and_return([nil, this_data])
329
+ expect { |b| described_class.paginated_get(url, 1, 100, &b) }.to yield_with_args(this_data)
330
+ end
331
+
332
+ it 'Requires a block' do
333
+ allow(GandiV5).to receive(:get).and_return([nil, [:a]])
334
+
335
+ expect { described_class.paginated_get(url) }.to raise_error LocalJumpError
336
+ end
337
+ end
241
338
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gandi_v5
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Gauld
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-25 00:00:00.000000000 Z
11
+ date: 2020-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -336,18 +336,14 @@ files:
336
336
  - lib/gandi_v5/error/gandi_error.rb
337
337
  - lib/gandi_v5/live_dns.rb
338
338
  - lib/gandi_v5/live_dns/domain.rb
339
- - lib/gandi_v5/live_dns/has_zone_records.rb
340
- - lib/gandi_v5/live_dns/record_set.rb
341
- - lib/gandi_v5/live_dns/zone.rb
342
- - lib/gandi_v5/live_dns/zone/snapshot.rb
339
+ - lib/gandi_v5/live_dns/domain/dnssec_key.rb
340
+ - lib/gandi_v5/live_dns/domain/record.rb
341
+ - lib/gandi_v5/live_dns/domain/snapshot.rb
342
+ - lib/gandi_v5/live_dns/domain/tsig_key.rb
343
343
  - lib/gandi_v5/organization.rb
344
344
  - lib/gandi_v5/organization/customer.rb
345
345
  - lib/gandi_v5/version.rb
346
346
  - spec/.rubocop.yml
347
- - spec/features/domain_spec.rb
348
- - spec/features/livedns_domain_spec.rb
349
- - spec/features/livedns_zone_spec.rb
350
- - spec/features/mailbox_spec.rb
351
347
  - spec/fixtures/bodies/GandiV5_Billing/info.yml
352
348
  - spec/fixtures/bodies/GandiV5_Domain/fetch.yml
353
349
  - spec/fixtures/bodies/GandiV5_Domain/fetch_contacts.yml
@@ -367,20 +363,17 @@ files:
367
363
  - spec/fixtures/bodies/GandiV5_Email_Slot/list.yml
368
364
  - spec/fixtures/bodies/GandiV5_LiveDNS_Domain/fetch.yml
369
365
  - spec/fixtures/bodies/GandiV5_LiveDNS_Domain/list.yml
370
- - spec/fixtures/bodies/GandiV5_LiveDNS_Zone/fetch.yml
371
- - spec/fixtures/bodies/GandiV5_LiveDNS_Zone/list.yml
372
- - spec/fixtures/bodies/GandiV5_LiveDNS_Zone_Snapshot/fetch.yml
373
- - spec/fixtures/bodies/GandiV5_LiveDNS_Zone_Snapshot/list.yml
366
+ - spec/fixtures/bodies/GandiV5_LiveDNS_Domain/list_tsig.yml
367
+ - spec/fixtures/bodies/GandiV5_LiveDNS_Domain/nameservers.yml
368
+ - spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/fetch.yml
369
+ - spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/list.yml
370
+ - spec/fixtures/bodies/GandiV5_LiveDNS_Domain_Snapshot/fetch.yml
371
+ - spec/fixtures/bodies/GandiV5_LiveDNS_Domain_Snapshot/list.yml
372
+ - spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/fetch.yml
373
+ - spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/list.yml
374
374
  - spec/fixtures/bodies/GandiV5_Organization/fetch.yml
375
375
  - spec/fixtures/bodies/GandiV5_Organization/list.yml
376
376
  - spec/fixtures/bodies/GandiV5_Organization_Customer/list.yml
377
- - spec/fixtures/vcr/Domain_features/List_domains.yml
378
- - spec/fixtures/vcr/Domain_features/Renew_domain.yml
379
- - spec/fixtures/vcr/LiveDNS_Domain_features/List_domains.yml
380
- - spec/fixtures/vcr/LiveDNS_Zone_features/List_zones.yml
381
- - spec/fixtures/vcr/LiveDNS_Zone_features/Make_and_save_snapshot.yml
382
- - spec/fixtures/vcr/LiveDNS_Zone_features/Save_zone_to_file.yml
383
- - spec/fixtures/vcr/Mailbox_features/List_mailboxes.yml
384
377
  - spec/spec_helper.rb
385
378
  - spec/test.env
386
379
  - spec/units/gandi_v5/billing/info/prepaid_spec.rb
@@ -414,10 +407,11 @@ files:
414
407
  - spec/units/gandi_v5/email/slot_spec.rb
415
408
  - spec/units/gandi_v5/error/gandi_error_spec.rb
416
409
  - spec/units/gandi_v5/error_spec.rb
410
+ - spec/units/gandi_v5/live_dns/domain/dnssec_key_spec.rb
411
+ - spec/units/gandi_v5/live_dns/domain/record_spec.rb
412
+ - spec/units/gandi_v5/live_dns/domain/snapshot_spec.rb
413
+ - spec/units/gandi_v5/live_dns/domain/tsig_key_spec.rb
417
414
  - spec/units/gandi_v5/live_dns/domain_spec.rb
418
- - spec/units/gandi_v5/live_dns/record_set_spec.rb
419
- - spec/units/gandi_v5/live_dns/zone/snapshot_spec.rb
420
- - spec/units/gandi_v5/live_dns/zone_spec.rb
421
415
  - spec/units/gandi_v5/live_dns_spec.rb
422
416
  - spec/units/gandi_v5/organization/customer_spec.rb
423
417
  - spec/units/gandi_v5/organization_spec.rb
@@ -1,153 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class GandiV5
4
- class LiveDNS
5
- # Methods for handling record related requests in both
6
- # GandiV5::LiveDNS::Domain and GandiV5::LiveDNS::Zone.
7
- module HasZoneRecords
8
- # @overload fetch_records()
9
- # Fetch all records for this domain.
10
- # @overload fetch_records(name)
11
- # Fetch records for a name.
12
- # @param name [String] the name to fetch records for.
13
- # @overload fetch_records(name, type)
14
- # Fetch records of a type for a name.
15
- # @param name [String] the name to fetch records for.
16
- # @param type [String] the record type to fetch.
17
- # @return [Array<GandiV5::LiveDNS::RecordSet>]
18
- # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
19
- def fetch_records(name = nil, type = nil)
20
- GandiV5::LiveDNS.require_valid_record_type type if type
21
-
22
- url_ = "#{url}/records"
23
- url_ += "/#{CGI.escape name}" if name
24
- url_ += "/#{CGI.escape type}" if type
25
-
26
- _response, data = GandiV5.get url_
27
- data = [data] unless data.is_a?(Array)
28
- data.map { |item| GandiV5::LiveDNS::RecordSet.from_gandi item }
29
- end
30
-
31
- # @overload fetch_zone_lines()
32
- # Fetch all records for this domain.
33
- # @overload fetch_zone_lines(name)
34
- # Fetch records for a name.
35
- # @param name [String] the name to fetch records for.
36
- # @overload fetch_zone_lines(name, type)
37
- # Fetch records of a type for a name.
38
- # @param name [String] the name to fetch records for.
39
- # @param type [String] the record type to fetch.
40
- # @return [String]
41
- # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
42
- def fetch_zone_lines(name = nil, type = nil)
43
- GandiV5::LiveDNS.require_valid_record_type type if type
44
-
45
- url_ = "#{url}/records"
46
- url_ += "/#{CGI.escape name}" if name
47
- url_ += "/#{CGI.escape type}" if type
48
-
49
- GandiV5.get(url_, accept: 'text/plain').last
50
- end
51
-
52
- # Add record to this domain.
53
- # @param name [String]
54
- # @param type [String]
55
- # @param ttl [Integer]
56
- # @param values [Array<String>]
57
- # @return [String] The confirmation message from Gandi.
58
- # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
59
- def add_record(name, type, ttl, *values)
60
- GandiV5::LiveDNS.require_valid_record_type type
61
- fail ArgumentError, 'ttl must be positive and non-zero' unless ttl.positive?
62
- fail ArgumentError, 'there must be at least one value' if values.none?
63
-
64
- body = {
65
- rrset_name: name,
66
- rrset_type: type,
67
- rrset_ttl: ttl,
68
- rrset_values: values
69
- }.to_json
70
- _response, data = GandiV5.post "#{url}/records", body
71
- data['message']
72
- end
73
-
74
- # @overload delete_records()
75
- # Delete all records for this domain.
76
- # @overload delete_records(name)
77
- # Delete records for a name.
78
- # @param name [String] the name to delete records for.
79
- # @overload delete_records(name, type)
80
- # Delete records of a type for a name.
81
- # @param name [String] the name to delete records for.
82
- # @param type [String] the record type to delete.
83
- # @return [nil]
84
- # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
85
- def delete_records(name = nil, type = nil)
86
- GandiV5::LiveDNS.require_valid_record_type(type) if type
87
-
88
- url_ = "#{url}/records"
89
- url_ += "/#{CGI.escape name}" if name
90
- url_ += "/#{CGI.escape type}" if type
91
- GandiV5.delete(url_).last
92
- end
93
-
94
- # Replace all records for this domain.
95
- # @param records
96
- # [Array<Hash<:name, :type => String, :ttl => Integer, :values => Array<String>>>]
97
- # the records to add.
98
- # @param text [String] zone file lines to replace the records with.
99
- # @return [String] The confirmation message from Gandi.
100
- # @raise [ArgumentError] if neither/both of records & test are passed.
101
- # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
102
- def replace_records(records: nil, text: nil)
103
- unless [records, text].count(&:nil?).eql?(1)
104
- fail ArgumentError, 'you must pass ONE of records: or text:'
105
- end
106
-
107
- if records
108
- body = {
109
- items: records.map { |r| r.transform_keys { |k| "rrset_#{k}" } }
110
- }.to_json
111
- _response, data = GandiV5.put "#{url}/records", body
112
- elsif text
113
- _response, data = GandiV5.put "#{url}/records", text, 'content-type': 'text/plain'
114
- end
115
- data['message']
116
- end
117
-
118
- # @override replace_records_for(name, records)
119
- # Replace records for a name in this domain.
120
- # @param name [String]
121
- # @param records
122
- # [Array<Hash<type: String, ttl: Integer, values: Array<String>>>]
123
- # the records to add.
124
- # @override replace_records_for(name, values, type: nil, ttl: nil)
125
- # Replace records for a name in this domain.
126
- # @param name [String]
127
- # @param type [String] the record type.
128
- # @param ttl [Integer] the TTL to set for the record.
129
- # @param values [Array<String>] the values to set for the record.
130
- # @raise [ArgumentError] if ttl is present and type is absent.
131
- # @return [String] The confirmation message from Gandi.
132
- # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
133
- def replace_records_for(name, records, type: nil, ttl: nil)
134
- fail ArgumentError, 'missing keyword: type' if ttl && type.nil?
135
-
136
- if type
137
- GandiV5::LiveDNS.require_valid_record_type type
138
- body = { rrset_values: records, rrset_ttl: ttl }
139
- # body[:rrset_ttl] = ttl if ttl
140
- _response, data = GandiV5.put "#{url}/records/#{name}/#{type}", body.to_json
141
-
142
- else
143
- body = {
144
- items: records.map { |r| r.transform_keys { |k| "rrset_#{k}" } }
145
- }
146
- _response, data = GandiV5.put "#{url}/records/#{name}", body.to_json
147
- end
148
-
149
- data['message']
150
- end
151
- end
152
- end
153
- end
@@ -1,79 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class GandiV5
4
- class LiveDNS
5
- # A record set which comes from either a domain or zone.
6
- # @!attribute [r] type
7
- # @return [String]
8
- # @!attribute [r] ttl
9
- # @return [Integer]
10
- # @!attribute [r] name
11
- # @return [String]
12
- # @!attribute [r] values
13
- # @return [Array<String>]
14
- class RecordSet
15
- include GandiV5::Data
16
-
17
- member :type, gandi_key: 'rrset_type'
18
- member :ttl, gandi_key: 'rrset_ttl', converter: GandiV5::Data::Converter::Integer
19
- member :name, gandi_key: 'rrset_name'
20
- member :values, gandi_key: 'rrset_values'
21
-
22
- # Generate zone file lines for the record.
23
- # @return [String]
24
- def to_s
25
- values.map do |value|
26
- "#{name}\t#{ttl}\tIN\t#{type}\t#{value}"
27
- end.join("\n")
28
- end
29
-
30
- GandiV5::LiveDNS::RECORD_TYPES.each do |t|
31
- # Check the record type.
32
- # @return [Boolean]
33
- define_method "#{t.downcase}?" do
34
- type.eql?(t)
35
- end
36
- end
37
-
38
- # Check the TTL's value in seconds.
39
- # @param number [Integer] the number of second(s) to check against.
40
- # @return [Boolean]
41
- def second?(number = 1)
42
- ttl == number
43
- end
44
- alias seconds? second?
45
-
46
- # Check the TTL's value in minutes.
47
- # @param number [Integer] the number of minute(s) to check against.
48
- # @return [Boolean]
49
- def minute?(number = 1)
50
- ttl == number * 60
51
- end
52
- alias minutes? minute?
53
-
54
- # Check the TTL's value in hours.
55
- # @param number [Integer] the number of hour(s) to check against.
56
- # @return [Boolean]
57
- def hour?(number = 1)
58
- ttl == number * 3_600
59
- end
60
- alias hours? hour?
61
-
62
- # Check the TTL's value in days.
63
- # @param number [Integer] the number of day(s) to check against.
64
- # @return [Boolean]
65
- def day?(number = 1)
66
- ttl == number * 86_400
67
- end
68
- alias days? day?
69
-
70
- # Check the TTL's value in weeks.
71
- # @param number [Integer] the number of week(s) to check against.
72
- # @return [Boolean]
73
- def week?(number = 1)
74
- ttl == number * 604_800
75
- end
76
- alias weeks? day?
77
- end
78
- end
79
- end