gandi_v5 0.8.0 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +49 -9
  3. data/README.md +64 -15
  4. data/lib/gandi_v5/billing/info/prepaid.rb +1 -0
  5. data/lib/gandi_v5/data/converter/array_of.rb +3 -2
  6. data/lib/gandi_v5/data/converter/integer.rb +3 -2
  7. data/lib/gandi_v5/data/converter/symbol.rb +3 -2
  8. data/lib/gandi_v5/data/converter/time.rb +3 -2
  9. data/lib/gandi_v5/data/converter.rb +3 -2
  10. data/lib/gandi_v5/data.rb +13 -14
  11. data/lib/gandi_v5/domain/availability/product/period.rb +1 -1
  12. data/lib/gandi_v5/domain/contact.rb +5 -5
  13. data/lib/gandi_v5/domain/tld.rb +2 -2
  14. data/lib/gandi_v5/domain/transfer_in/availability.rb +51 -0
  15. data/lib/gandi_v5/domain/transfer_in.rb +172 -0
  16. data/lib/gandi_v5/domain/web_forwarding.rb +182 -0
  17. data/lib/gandi_v5/domain.rb +52 -13
  18. data/lib/gandi_v5/email/forward.rb +1 -1
  19. data/lib/gandi_v5/email/mailbox.rb +6 -6
  20. data/lib/gandi_v5/email/slot.rb +1 -1
  21. data/lib/gandi_v5/email.rb +3 -0
  22. data/lib/gandi_v5/error/gandi_error.rb +1 -0
  23. data/lib/gandi_v5/live_dns/domain/dnssec_key.rb +16 -11
  24. data/lib/gandi_v5/live_dns/domain/snapshot.rb +5 -1
  25. data/lib/gandi_v5/live_dns/domain/tsig_key.rb +8 -5
  26. data/lib/gandi_v5/live_dns/domain.rb +29 -1
  27. data/lib/gandi_v5/live_dns.rb +2 -0
  28. data/lib/gandi_v5/simple_hosting/instance/application.rb +1 -0
  29. data/lib/gandi_v5/simple_hosting/instance/database.rb +1 -0
  30. data/lib/gandi_v5/simple_hosting/instance/language.rb +1 -1
  31. data/lib/gandi_v5/simple_hosting/instance/upgrade.rb +1 -0
  32. data/lib/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone.rb +2 -1
  33. data/lib/gandi_v5/simple_hosting/instance/virtual_host.rb +90 -5
  34. data/lib/gandi_v5/simple_hosting/instance.rb +9 -0
  35. data/lib/gandi_v5/simple_hosting.rb +1 -0
  36. data/lib/gandi_v5/template/dispatch.rb +109 -0
  37. data/lib/gandi_v5/template/payload/dns_record.rb +23 -0
  38. data/lib/gandi_v5/template/payload/web_forwarding.rb +82 -0
  39. data/lib/gandi_v5/template/payload.rb +64 -0
  40. data/lib/gandi_v5/template.rb +271 -0
  41. data/lib/gandi_v5/version.rb +1 -1
  42. data/lib/gandi_v5.rb +115 -66
  43. data/spec/.rubocop.yml +3 -50
  44. data/spec/features/list_domain_renewals_spec.rb +16 -0
  45. data/spec/features/list_email_addresses_spec.rb +39 -0
  46. data/spec/fixtures/bodies/GandiV5_Domain_TransferIn/fetch.yml +21 -0
  47. data/spec/fixtures/bodies/GandiV5_Domain_TransferIn_Availability/fetch.yml +10 -0
  48. data/spec/fixtures/bodies/GandiV5_Domain_WebForwarding/fetch.yml +9 -0
  49. data/spec/fixtures/bodies/GandiV5_Domain_WebForwarding/list.yml +9 -0
  50. data/spec/fixtures/bodies/GandiV5_Template/fetch.yml +41 -0
  51. data/spec/fixtures/bodies/GandiV5_Template/list.yml +20 -0
  52. data/spec/fixtures/bodies/GandiV5_Template_Dispatch/fetch.yml +49 -0
  53. data/spec/fixtures/vcr/Examples/List_domain_renewals.yml +54 -0
  54. data/spec/fixtures/vcr/Examples/List_email_addresses.yml +103 -0
  55. data/spec/spec_helper.rb +8 -7
  56. data/spec/units/gandi_v5/domain/transfer_in/availability_spec.rb +49 -0
  57. data/spec/units/gandi_v5/domain/transfer_in_spec.rb +143 -0
  58. data/spec/units/gandi_v5/domain/web_forwarding_spec.rb +150 -0
  59. data/spec/units/gandi_v5/domain_spec.rb +50 -0
  60. data/spec/units/gandi_v5/simple_hosting/instance/virtual_host_spec.rb +125 -0
  61. data/spec/units/gandi_v5/simple_hosting/instance_spec.rb +8 -0
  62. data/spec/units/gandi_v5/template/dispatch_spec.rb +70 -0
  63. data/spec/units/gandi_v5/template/payload/web_forwarding_spec.rb +44 -0
  64. data/spec/units/gandi_v5/template_spec.rb +341 -0
  65. data/spec/units/gandi_v5_spec.rb +1 -1
  66. metadata +191 -57
  67. data/.gitignore +0 -26
  68. data/.rspec +0 -3
  69. data/.rubocop.yml +0 -74
  70. data/.travis.yml +0 -38
  71. data/FUNDING.yml +0 -10
  72. data/Gemfile +0 -6
  73. data/Guardfile +0 -39
  74. data/Rakefile +0 -3
  75. data/bin/console +0 -13
  76. data/gandi_v5.gemspec +0 -42
  77. data/spec/units/gandi_v5/billing/info_spec.rb +0 -4
  78. data/spec/units/gandi_v5/domain/availability/product/period_spec.rb +0 -4
  79. data/spec/units/gandi_v5/domain/availability/product/price_spec.rb +0 -4
  80. data/spec/units/gandi_v5/domain/availability/product_spec.rb +0 -4
  81. data/spec/units/gandi_v5/domain/availability/tax_spec.rb +0 -4
  82. data/spec/units/gandi_v5/domain/contract_spec.rb +0 -4
  83. data/spec/units/gandi_v5/domain/dates_spec.rb +0 -4
  84. data/spec/units/gandi_v5/domain/restore_information_spec.rb +0 -4
  85. data/spec/units/gandi_v5/error_spec.rb +0 -4
  86. data/spec/units/gandi_v5/sharing_space_spec.rb +0 -4
  87. data/spec/units/gandi_v5/simple_hosting/instance/database_spec.rb +0 -4
  88. data/spec/units/gandi_v5/simple_hosting/instance/language_spec.rb +0 -4
  89. data/spec/units/gandi_v5/simple_hosting/instance/upgrade_spec.rb +0 -4
@@ -0,0 +1,341 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::Template do
4
+ subject do
5
+ described_class.new uuid: 'template-uuid'
6
+ end
7
+
8
+ describe '#refresh' do
9
+ before :each do
10
+ body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Template', 'fetch.yml'))
11
+ expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/template/templates/template-uuid')
12
+ .and_return([nil, YAML.load_file(body_fixture)])
13
+ subject.refresh
14
+ end
15
+
16
+ its('description') { should eq 'description of template' }
17
+ its('editable') { should be true }
18
+ its('uuid') { should eq 'template-uuid' }
19
+ its('name') { should eq 'template name' }
20
+ its('organisation_name') { should eq 'org-name' }
21
+ its('sharing_space.uuid') { should eq 'sharing-space-uuid' }
22
+ its('sharing_space.name') { should eq 'sharing-space-name' }
23
+ its('sharing_space.reseller') { should be true }
24
+ its('sharing_space.type') { should eq 'user' }
25
+ its('sharing_space.reseller_details.uuid') { should eq 'reseller-uuid' }
26
+ its('sharing_space.reseller_details.name') { should eq 'reseller-name' }
27
+ its('variables') { should eq [] }
28
+
29
+ its('payload.dns_records.count') { should eq 1 }
30
+ its('payload.dns_records.first.name') { should eq 'record-name' }
31
+ its('payload.dns_records.first.type') { should eq 'TXT' }
32
+ its('payload.dns_records.first.values') { should eq ['record-value'] }
33
+ its('payload.dns_records.first.ttl') { should eq 600 }
34
+
35
+ its('payload.mailboxes') { should eq ['user-name'] }
36
+
37
+ its('payload.name_servers') { should eq ['1.1.1.1'] }
38
+
39
+ its('payload.web_forwardings.count') { should eq 1 }
40
+ its('payload.web_forwardings.first.type') { should eq :http301 }
41
+ its('payload.web_forwardings.first.target') { should eq 'https://example.com/here' }
42
+ its('payload.web_forwardings.first.fqdn') { should eq 'here.example.com' }
43
+ its('payload.web_forwardings.first.override') { should be true }
44
+ its('payload.web_forwardings.first.protocol') { should eq :https }
45
+ end
46
+
47
+ describe '#update' do
48
+ let(:url) { 'https://api.gandi.net/v5/template/templates/template-uuid' }
49
+ let(:updated_template) { double GandiV5::Template }
50
+
51
+ before :each do
52
+ expect(subject).to receive(:refresh).and_return(updated_template)
53
+ end
54
+
55
+ it 'nothing' do
56
+ expect(GandiV5).to receive(:patch).with(url, '{}')
57
+ expect(subject.update).to be updated_template
58
+ end
59
+
60
+ it 'name' do
61
+ expect(GandiV5).to receive(:patch).with(url, '{"name":"new"}')
62
+ expect(subject.update(name: 'new')).to be updated_template
63
+ end
64
+
65
+ it 'description' do
66
+ expect(GandiV5).to receive(:patch).with(url, '{"description":"new"}')
67
+ expect(subject.update(description: 'new')).to be updated_template
68
+ end
69
+
70
+ it 'dns_records' do
71
+ expect(GandiV5).to receive(:patch).with(url, '{"payload":{"dns:records":{"default":true}}}')
72
+ expect(subject.update(dns_records: :default)).to be updated_template
73
+ end
74
+
75
+ it 'mailboxes' do
76
+ expect(GandiV5).to receive(:patch).with(url, '{"payload":{"domain:mailboxes":{"values":[{"login":"user"}]}}}')
77
+ expect(subject.update(mailboxes: ['user'])).to be updated_template
78
+ end
79
+
80
+ it 'name servers' do
81
+ expect(GandiV5).to receive(:patch).with(url, '{"payload":{"domain:nameservers":{"service":"livedns"}}}')
82
+ expect(subject.update(name_servers: :livedns)).to be updated_template
83
+ end
84
+
85
+ it 'web forwardings' do
86
+ expect(GandiV5).to receive(:patch).with(url, '{"payload":{"domain:webredirs":{"values":[]}}}')
87
+ expect(subject.update(web_forwardings: [])).to be updated_template
88
+ end
89
+ end
90
+
91
+ it '#delete' do
92
+ url = 'https://api.gandi.net/v5/template/templates/template-uuid'
93
+ expect(GandiV5).to receive(:delete).with(url)
94
+ .and_return([nil, { 'message' => 'Confirmation message.' }])
95
+ expect(subject.delete).to be nil
96
+ end
97
+
98
+ it '#apply' do
99
+ url = 'https://api.gandi.net/v5/template/templates/template-uuid'
100
+ body = { 'dispatch_href' => 'https://api.gandi.net/v5/template/dispatch/dispatch-uuid' }
101
+ expect(GandiV5).to receive(:post).with(url, '{"object_type":"domain","object_id":"domain-uuid"}')
102
+ .and_return([nil, body])
103
+ expect(subject.apply('domain-uuid')).to eq 'dispatch-uuid'
104
+ end
105
+
106
+ describe '.list' do
107
+ subject { described_class.list }
108
+
109
+ before :each do
110
+ expect(GandiV5).to receive(:paginated_get).with(url, (1..), 100)
111
+ .and_yield(YAML.load_file(body_fixture))
112
+ end
113
+
114
+ let(:body_fixture) { File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Template', 'list.yml')) }
115
+ let(:url) { 'https://api.gandi.net/v5/template/templates' }
116
+
117
+ its('count') { should eq 1 }
118
+
119
+ its('first.description') { should eq 'description of template' }
120
+ its('first.editable') { should be true }
121
+ its('first.uuid') { should eq 'template-uuid' }
122
+ its('first.name') { should eq 'template name' }
123
+ its('first.organisation_name') { should eq 'org-name' }
124
+ its('first.sharing_space.uuid') { should eq 'sharing-space-uuid' }
125
+ its('first.sharing_space.name') { should eq 'sharing-space-name' }
126
+ its('first.sharing_space.reseller') { should be true }
127
+ its('first.sharing_space.type') { should eq 'user' }
128
+ its('first.sharing_space.reseller_details.uuid') { should eq 'reseller-uuid' }
129
+ its('first.sharing_space.reseller_details.name') { should eq 'reseller-name' }
130
+ end
131
+
132
+ describe '.fetch' do
133
+ subject { described_class.fetch 'template-uuid' }
134
+
135
+ before :each do
136
+ body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Template', 'fetch.yml'))
137
+ expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/template/templates/template-uuid')
138
+ .and_return([nil, YAML.load_file(body_fixture)])
139
+ end
140
+
141
+ its('description') { should eq 'description of template' }
142
+ its('editable') { should be true }
143
+ its('uuid') { should eq 'template-uuid' }
144
+ its('name') { should eq 'template name' }
145
+ its('organisation_name') { should eq 'org-name' }
146
+ its('sharing_space.uuid') { should eq 'sharing-space-uuid' }
147
+ its('sharing_space.name') { should eq 'sharing-space-name' }
148
+ its('sharing_space.reseller') { should be true }
149
+ its('sharing_space.type') { should eq 'user' }
150
+ its('sharing_space.reseller_details.uuid') { should eq 'reseller-uuid' }
151
+ its('sharing_space.reseller_details.name') { should eq 'reseller-name' }
152
+ its('variables') { should eq [] }
153
+
154
+ its('payload.dns_records.count') { should eq 1 }
155
+ its('payload.dns_records.first.name') { should eq 'record-name' }
156
+ its('payload.dns_records.first.type') { should eq 'TXT' }
157
+ its('payload.dns_records.first.values') { should eq ['record-value'] }
158
+ its('payload.dns_records.first.ttl') { should eq 600 }
159
+
160
+ its('payload.mailboxes') { should eq ['user-name'] }
161
+
162
+ its('payload.name_servers') { should eq ['1.1.1.1'] }
163
+
164
+ its('payload.web_forwardings.count') { should eq 1 }
165
+ its('payload.web_forwardings.first.type') { should eq :http301 }
166
+ its('payload.web_forwardings.first.target') { should eq 'https://example.com/here' }
167
+ its('payload.web_forwardings.first.fqdn') { should eq 'here.example.com' }
168
+ its('payload.web_forwardings.first.override') { should be true }
169
+ its('payload.web_forwardings.first.protocol') { should eq :https }
170
+ end
171
+
172
+ describe '.fetch' do
173
+ it 'With default dns records' do
174
+ body = { 'payload' => { 'dns:records' => { 'default' => true, 'records' => [] } } }
175
+ expect(GandiV5).to receive(:get).and_return([nil, body])
176
+ expect(described_class.fetch('template-uuid').payload.dns_records).to be :default
177
+ end
178
+
179
+ it 'With livedns name servers' do
180
+ body = { 'payload' => { 'domain:nameservers' => { 'service' => 'livedns', 'addresses' => [] } } }
181
+ expect(GandiV5).to receive(:get).and_return([nil, body])
182
+ expect(described_class.fetch('template-uuid').payload.name_servers).to be :livedns
183
+ end
184
+ end
185
+
186
+ describe '.create' do
187
+ let(:url) { 'https://api.gandi.net/v5/template/templates' }
188
+
189
+ it 'Without sharing_id' do
190
+ body = {
191
+ 'name' => 'template name',
192
+ 'description' => 'description of template',
193
+ 'payload' => {
194
+ 'dns:records' => {
195
+ 'default' => false,
196
+ 'records' => [{ 'name' => 'host', 'ttl' => 600, 'type' => 'TXT', 'values' => ['value'] }]
197
+ },
198
+ 'domain:mailboxes' => { 'values' => [{ 'login' => 'user1' }, { 'login' => 'user2' }] },
199
+ 'domain:nameservers' => {
200
+ 'service' => 'custom',
201
+ 'addresses' => ['1.1.1.1', '2.2.2.2']
202
+ },
203
+ 'domain:webredirs' => {
204
+ 'values' => [
205
+ {
206
+ 'type' => 'http302',
207
+ 'url' => 'example.com',
208
+ 'host' => 'here',
209
+ 'override' => true,
210
+ 'protocol' => 'httpsonly'
211
+ }
212
+ ]
213
+ }
214
+ }
215
+ }.to_json
216
+ response = double(
217
+ RestClient::Response,
218
+ headers: { location: 'https://api.gandi.net/v5/template/templates/template-uuid' }
219
+ )
220
+ created_template = double GandiV5::Template
221
+ expect(GandiV5).to receive(:post).with(url, body).and_return([response, 'Confirmation message'])
222
+ expect(described_class).to receive(:fetch).with('template-uuid').and_return(created_template)
223
+
224
+ create = {
225
+ name: 'template name',
226
+ description: 'description of template',
227
+ dns_records: [{ name: 'host', ttl: 600, type: 'TXT', values: ['value'] }],
228
+ mailboxes: %w[user1 user2],
229
+ name_servers: ['1.1.1.1', '2.2.2.2'],
230
+ web_forwardings: [
231
+ { type: :http302, target: 'example.com', host: 'here', override: true, protocol: :https_only }
232
+ ]
233
+ }
234
+ expect(described_class.create(**create)).to be created_template
235
+ end
236
+
237
+ it 'With a :permanent web forwarding' do
238
+ url = 'https://api.gandi.net/v5/template/templates'
239
+ body = '{"name":"n","description":"d","payload":{"domain:webredirs":{"values":[{"type":"http301","url":""}]}}}'
240
+ response = double(
241
+ RestClient::Response,
242
+ headers: { location: 'https://api.gandi.net/v5/template/templates/template-uuid' }
243
+ )
244
+ expect(GandiV5).to receive(:post).with(url, body).and_return([response, 'Confirmation message'])
245
+ expect(described_class).to receive(:fetch).with('template-uuid').and_return(double(GandiV5::Template))
246
+
247
+ described_class.create(
248
+ name: 'n',
249
+ description: 'd',
250
+ web_forwardings: [{ type: :permanent, target: '' }]
251
+ )
252
+ end
253
+
254
+ it 'With a :temporary web forwarding' do
255
+ url = 'https://api.gandi.net/v5/template/templates'
256
+ body = '{"name":"n","description":"d","payload":{"domain:webredirs":{"values":[{"type":"http302","url":""}]}}}'
257
+ response = double(
258
+ RestClient::Response,
259
+ headers: { location: 'https://api.gandi.net/v5/template/templates/template-uuid' }
260
+ )
261
+ expect(GandiV5).to receive(:post).with(url, body).and_return([response, 'Confirmation message'])
262
+ expect(described_class).to receive(:fetch).with('template-uuid').and_return(double(GandiV5::Template))
263
+
264
+ described_class.create(
265
+ name: 'n',
266
+ description: 'd',
267
+ web_forwardings: [{ type: :temporary, target: '' }]
268
+ )
269
+ end
270
+
271
+ it 'With a :found web forwarding' do
272
+ url = 'https://api.gandi.net/v5/template/templates'
273
+ body = '{"name":"n","description":"d","payload":{"domain:webredirs":{"values":[{"type":"http302","url":""}]}}}'
274
+ response = double(
275
+ RestClient::Response,
276
+ headers: { location: 'https://api.gandi.net/v5/template/templates/template-uuid' }
277
+ )
278
+ expect(GandiV5).to receive(:post).with(url, body).and_return([response, 'Confirmation message'])
279
+ expect(described_class).to receive(:fetch).with('template-uuid').and_return(double(GandiV5::Template))
280
+
281
+ described_class.create(
282
+ name: 'n',
283
+ description: 'd',
284
+ web_forwardings: [{ type: :found, target: '' }]
285
+ )
286
+ end
287
+
288
+ it 'With sharing_id' do
289
+ url = 'https://api.gandi.net/v5/template/templates?sharing_id=sharing-uuid'
290
+ body = '{"name":"n","description":"d","payload":{}}'
291
+ response = double(
292
+ RestClient::Response,
293
+ headers: { location: 'https://api.gandi.net/v5/template/templates/template-uuid' }
294
+ )
295
+ expect(GandiV5).to receive(:post).with(url, body).and_return([response, 'Confirmation message'])
296
+ expect(described_class).to receive(:fetch).with('template-uuid').and_return(double(GandiV5::Template))
297
+
298
+ described_class.create name: 'n', description: 'd', sharing_id: 'sharing-uuid'
299
+ end
300
+
301
+ it 'Use livedns name servers' do
302
+ body = '{"name":"n","description":"d","payload":{"domain:nameservers":{"service":"livedns"}}}'
303
+ response = double(
304
+ RestClient::Response,
305
+ headers: { location: 'https://api.gandi.net/v5/template/templates/template-uuid' }
306
+ )
307
+ expect(GandiV5).to receive(:post).with(url, body).and_return([response, 'Confirmation message'])
308
+ expect(described_class).to receive(:fetch).with('template-uuid').and_return(double(GandiV5::Template))
309
+
310
+ described_class.create name: 'n', description: 'd', name_servers: :livedns
311
+ end
312
+
313
+ it 'Use default DNS records' do
314
+ body = '{"name":"n","description":"d","payload":{"dns:records":{"default":true}}}'
315
+ response = double(
316
+ RestClient::Response,
317
+ headers: { location: 'https://api.gandi.net/v5/template/templates/template-uuid' }
318
+ )
319
+ expect(GandiV5).to receive(:post).with(url, body).and_return([response, 'Confirmation message'])
320
+ expect(described_class).to receive(:fetch).with('template-uuid').and_return(double(GandiV5::Template))
321
+
322
+ described_class.create name: 'n', description: 'd', dns_records: :default
323
+ end
324
+
325
+ it 'With empty payload' do
326
+ body = {
327
+ 'name' => 'n',
328
+ 'description' => 'd',
329
+ 'payload' => {}
330
+ }.to_json
331
+ response = double(
332
+ RestClient::Response,
333
+ headers: { location: 'https://api.gandi.net/v5/template/templates/template-uuid' }
334
+ )
335
+ expect(GandiV5).to receive(:post).with(url, body).and_return([response, 'Confirmation message'])
336
+ expect(described_class).to receive(:fetch).with('template-uuid').and_return(double(GandiV5::Template))
337
+
338
+ described_class.create name: 'n', description: 'd'
339
+ end
340
+ end
341
+ end
@@ -246,7 +246,7 @@ describe GandiV5 do
246
246
 
247
247
  describe '.paginated_get' do
248
248
  let(:url) { "#{GandiV5::BASE}test/url" }
249
- let(:do_nothing) { ->(_this_data) { nil } }
249
+ let(:do_nothing) { ->(_this_data) {} }
250
250
 
251
251
  it 'Keeps fetching until getting a partial list' do
252
252
  headers1 = { params: { 'page' => 1, 'per_page' => 2 } }