gandi_v5 0.9.1 → 0.10.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 (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/README.md +10 -6
  4. data/lib/gandi_v5.rb +2 -0
  5. data/lib/gandi_v5/domain.rb +39 -1
  6. data/lib/gandi_v5/domain/transfer_in.rb +2 -0
  7. data/lib/gandi_v5/domain/web_forwarding.rb +182 -0
  8. data/lib/gandi_v5/email.rb +2 -0
  9. data/lib/gandi_v5/email/forward.rb +1 -1
  10. data/lib/gandi_v5/email/mailbox.rb +1 -1
  11. data/lib/gandi_v5/live_dns/domain/snapshot.rb +1 -1
  12. data/lib/gandi_v5/live_dns/domain/tsig_key.rb +1 -1
  13. data/lib/gandi_v5/simple_hosting/instance.rb +6 -0
  14. data/lib/gandi_v5/simple_hosting/instance/virtual_host.rb +87 -2
  15. data/lib/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone.rb +1 -1
  16. data/lib/gandi_v5/template.rb +271 -0
  17. data/lib/gandi_v5/template/dispatch.rb +109 -0
  18. data/lib/gandi_v5/template/payload.rb +64 -0
  19. data/lib/gandi_v5/template/payload/dns_record.rb +23 -0
  20. data/lib/gandi_v5/template/payload/web_forwarding.rb +82 -0
  21. data/lib/gandi_v5/version.rb +1 -1
  22. data/spec/fixtures/bodies/GandiV5_Domain_WebForwarding/fetch.yml +9 -0
  23. data/spec/fixtures/bodies/GandiV5_Domain_WebForwarding/list.yml +9 -0
  24. data/spec/fixtures/bodies/GandiV5_Template/fetch.yml +41 -0
  25. data/spec/fixtures/bodies/GandiV5_Template/list.yml +20 -0
  26. data/spec/fixtures/bodies/GandiV5_Template_Dispatch/fetch.yml +49 -0
  27. data/spec/spec_helper.rb +8 -7
  28. data/spec/units/gandi_v5/domain/web_forwarding_spec.rb +150 -0
  29. data/spec/units/gandi_v5/domain_spec.rb +50 -0
  30. data/spec/units/gandi_v5/simple_hosting/instance/virtual_host_spec.rb +125 -0
  31. data/spec/units/gandi_v5/simple_hosting/instance_spec.rb +8 -0
  32. data/spec/units/gandi_v5/template/dispatch_spec.rb +70 -0
  33. data/spec/units/gandi_v5/template/payload/web_forwarding_spec.rb +44 -0
  34. data/spec/units/gandi_v5/template_spec.rb +341 -0
  35. data/spec/units/gandi_v5_spec.rb +1 -1
  36. metadata +73 -47
  37. data/spec/units/gandi_v5/billing/info_spec.rb +0 -4
  38. data/spec/units/gandi_v5/domain/availability/product/period_spec.rb +0 -4
  39. data/spec/units/gandi_v5/domain/availability/product/price_spec.rb +0 -4
  40. data/spec/units/gandi_v5/domain/availability/product_spec.rb +0 -4
  41. data/spec/units/gandi_v5/domain/availability/tax_spec.rb +0 -4
  42. data/spec/units/gandi_v5/domain/contract_spec.rb +0 -4
  43. data/spec/units/gandi_v5/domain/dates_spec.rb +0 -4
  44. data/spec/units/gandi_v5/domain/restore_information_spec.rb +0 -4
  45. data/spec/units/gandi_v5/error_spec.rb +0 -4
  46. data/spec/units/gandi_v5/sharing_space_spec.rb +0 -4
  47. data/spec/units/gandi_v5/simple_hosting/instance/database_spec.rb +0 -4
  48. data/spec/units/gandi_v5/simple_hosting/instance/language_spec.rb +0 -4
  49. data/spec/units/gandi_v5/simple_hosting/instance/upgrade_spec.rb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4bfa3d695cec03737e8e5c3639c7744300babd00d59081f4edf14f013d2e9787
4
- data.tar.gz: ce687383ed1d014889d22e9d33a068dad8a8dc8ec2a73a38c9150014195a3f0b
3
+ metadata.gz: cc90c3434cb1207a7eed04d4b2331039f8ac8e32e2861e4d3693b034658eabb1
4
+ data.tar.gz: 51b125b39d4b4fe71a2fc4f55815bf8c4e5c94a5d7e01bfd9e104be1886a91fa
5
5
  SHA512:
6
- metadata.gz: a2752f84704fbd326503b2bada3e3193d2215abc6c19e1b71198b29eabaf4e67f473249d076aa806ca2c937195a35c7d2a8c490e1f586d0c3f121be5900c1ae5
7
- data.tar.gz: 398dc026b251a700432dee898e23c207bee4fa10c5bcc879f706f0e9c0ed0793d3b670861b97221bd4f64bfbfd27c32a589b5b7eeb911662b95623461ec90f59
6
+ metadata.gz: 6478500701daaeec1623ce28db9d0568a9971f6087d7d7064d13cded11afa76e24b987e7804b7a88a2b5f3b4aa0496b860352399be8fcd82cdb88b640ba1c5e8
7
+ data.tar.gz: bd3089b11811fc944acaf7d39798d45a36c5e17a9a5be90d2a90d07270a2ca835e73428f58d641893d79f074b96a7c42671efb1ed2c4c40ca838840a0ee87759
@@ -1,5 +1,23 @@
1
1
  # Gandi V5 API Gem Changelog
2
2
 
3
+ ## Version 0.10.0
4
+
5
+ * GandiV5::Domain
6
+ * Add \#transfer_lock(lock = true) and \#transfer_unlock
7
+ * Add template_id argument to .create
8
+ * Add \#web_forwardings -> GandiV5::Domain::WebForwarding.list
9
+ * Add \#new_web_forwarding -> GandiV5::Domain::WebForwarding.create
10
+ * GandiV5::Domain::TransferIn
11
+ * Add template_id argument to .create
12
+ * GandiV5::Domain::WebForwarding
13
+ * GandiV5::SimpleHosting::Instance::VirtualHost: (I don't use simple hosting myself so it's possible I've misread the docs and a bug is waiting to be found, please add an issue if I have)
14
+ * Add .create (aliased as GandiV5::SimpleHosting::Instance#create_virtual_host)
15
+ * Add \#delete
16
+ * Add \#update
17
+ * GandiV5::Template
18
+ * GandiV5::Template::Dispatch
19
+ * Add testing against truffleruby-20.3.0
20
+
3
21
  ## Version 0.9.1
4
22
 
5
23
  * Add testing against ruby 2.7.2 and 3.0.0
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/gandi_v5.png)](http://badge.fury.io/rb/gandi_v5)
2
- [![Build Status](https://secure.travis-ci.org/robertgauld/gandi_v5.png?branch=main)](http://travis-ci.org/robertgauld/gandi_v5)
2
+ [![Commit Checks](https://github.com/robertgauld/gandi_v5/workflows/Commit%20Checks/badge.svg)](https://github.com/robertgauld/gandi_v5/actions?query=workflow%3A%22Commit+Checks%22)
3
3
  [![Coveralls Status](https://coveralls.io/repos/robertgauld/gandi_v5/badge.png?branch=main)](https://coveralls.io/r/robertgauld/gandi_v5)
4
4
  [![Code Climate](https://codeclimate.com/github/robertgauld/gandi_v5.png?branch=main)](https://codeclimate.com/github/robertgauld/gandi_v5)
5
5
 
@@ -10,9 +10,12 @@ This gem supports the following versions of ruby, it may work on other versions
10
10
  * 2.6.0 - 2.6.6
11
11
  * 2.7.0 - 2.7.2
12
12
  * 3.0.0
13
- * truffleruby 20.1.0 - 20.2.0
14
- * jruby, once it's reached parity with ruby 2.6.x
15
- * rubinius, once it's reached parity with ruby 2.6.x
13
+ * truffleruby 20.1.0 - 20.3.0
14
+
15
+ This gem doesn't yet support the following versions of ruby, although hopefully it soon will.
16
+
17
+ * jruby - not yet at parity with ruby 2.6.x
18
+ * rubinius - not yet at parity with ruby 2.6.x
16
19
 
17
20
 
18
21
  ## Gandi V5
@@ -37,12 +40,12 @@ Details of the gem's API can be found at <https://rubydoc.info/github/robertgaul
37
40
  If you're using bundler then add it to your Gemfile and run the bundle command.
38
41
 
39
42
  ```ruby
40
- gem 'gandi_v5', '~> 0.8'
43
+ gem 'gandi_v5', '~> 0.10'
41
44
  ```
42
45
 
43
46
  If you're not using bundler then install it from the command line.
44
47
  ```bash
45
- gem install gandi_v5 -v '~> 0.8'
48
+ gem install gandi_v5 -v '~> 0.10'
46
49
  ```
47
50
 
48
51
  ## Usage
@@ -121,6 +124,7 @@ We follow the [Semantic Versioning](http://semver.org/) concept.
121
124
 
122
125
  | Gem Version | Gandi API Release Date |
123
126
  | --------------- | ------------------------ |
127
+ | 0.10.0 | 2020-12-10 |
124
128
  | 0.9.0 | 2020-07-29 |
125
129
  | 0.8.0 | 2020-07-10 |
126
130
  | 0.7.0 | 2020-05-07 |
@@ -14,6 +14,8 @@ class MyInflector < Zeitwerk::Inflector
14
14
  # @return [String] the class name
15
15
  def camelize(basename, _abspath)
16
16
  case basename
17
+ when 'dns_record'
18
+ 'DNSRecord'
17
19
  when 'live_dns'
18
20
  'LiveDNS'
19
21
  when 'tld'
@@ -181,7 +181,7 @@ class GandiV5
181
181
  admin: admin.respond_to?(:to_gandi) ? admin.to_gandi : admin,
182
182
  bill: bill.respond_to?(:to_gandi) ? bill.to_gandi : bill,
183
183
  tech: tech.respond_to?(:to_gandi) ? tech.to_gandi : tech
184
- }.reject { |_k, v| v.nil? }.to_json
184
+ }.compact { |_k, v| v.nil? }.to_json
185
185
 
186
186
  GandiV5.patch url('contacts'), body
187
187
  fetch_contacts
@@ -252,6 +252,29 @@ class GandiV5
252
252
  data['message']
253
253
  end
254
254
 
255
+ # Lock this domain - preventing it from being transfered.
256
+ # @see https://api.gandi.net/docs/domains/#patch-v5-domain-domains-domain-status
257
+ # Most extensions have a transfer protection mechanism, that consists of a lock that can be put
258
+ # on the domain. When the transfer lock is enabled, the domain can't be transferred.
259
+ # @params lock [Boolean] whether the domain should be locked (true) or unlocked (false)
260
+ # @return [String] The confirmation message from Gandi.
261
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
262
+ # rubocop:disable Style/OptionalBooleanParameter
263
+ def transfer_lock(lock = true)
264
+ _response, data = GandiV5.patch url('status'), { 'clientTransferProhibited' => lock }.to_json
265
+ @status = lock ? 'clientTransferProhibited' : nil
266
+ data['message']
267
+ end
268
+ # rubocop:enable Style/OptionalBooleanParameter
269
+
270
+ # Unlock this domain - allowing it to be transfered.
271
+ # @see https://api.gandi.net/docs/domains/#patch-v5-domain-domains-domain-status
272
+ # @return [String] The confirmation message from Gandi.
273
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
274
+ def transfer_unlock
275
+ transfer_lock false
276
+ end
277
+
255
278
  # Requery Gandi fo this domain's information.
256
279
  # @return [GandiV5::Domain]
257
280
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
@@ -417,6 +440,19 @@ class GandiV5
417
440
  GandiV5::Email::Forward.list(**params, fqdn: fqdn)
418
441
  end
419
442
 
443
+ # Get web forwardings for the domain.
444
+ # @see GandiV5::Domain::WebRedirection.list
445
+ def web_forwardings(**params)
446
+ GandiV5::Domain::WebForwarding.list(fqdn, **params)
447
+ end
448
+
449
+ # Get a web forwarding.
450
+ # @see GandiV5::Domain::WebRedirection.fetch
451
+ # @param host [String, #to_s] the host the redirection is setup on.
452
+ def web_forwarding(host)
453
+ GandiV5::Domain::WebForwarding.fetch(fqdn, host)
454
+ end
455
+
420
456
  # Create (register) a new domain.
421
457
  # @note This is not a free operation. Please ensure your prepaid account has enough credit.
422
458
  # @see https://api.gandi.net/docs/domains#post-v5-domain-domains
@@ -458,6 +494,8 @@ class GandiV5
458
494
  # List of nameservers. Gandi's LiveDNS nameservers are used if omitted..
459
495
  # @param price [Numeric, #to_gandi, #to_json] (optional) unknown - not documented at Gandi.
460
496
  # @param resellee_id [String, #to_gandi, #to_json] (optional) unknown - not documented at Gandi.
497
+ # @param template_id [String, #to_gandi] (optional)
498
+ # Template to be applied when the domain is created.
461
499
  # @param smd [String, #to_gandi, #to_json] (optional)
462
500
  # Contents of a Signed Mark Data file (used for newgtld sunrises, tld_period must be sunrise).
463
501
  # @param tld_period ["sunrise", "landrush", "eap1", "eap2", "eap3", "eap4", "eap5", "eap6",
@@ -105,6 +105,8 @@ class GandiV5
105
105
  # @param change_owner [Boolean] (optional)
106
106
  # whether the change the domain's owner during the transfer.
107
107
  # @param auth_code [String] (optional) authorization code (if required).
108
+ # @param template_id [String, #to_gandi] (optional)
109
+ # Template to be applied when the transfer is done.
108
110
  # @return [String] the confirmation message from Gandi
109
111
  # @return [Hash] if doing a dry run, you get what Gandi returns
110
112
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error
@@ -0,0 +1,182 @@
1
+ # frozen_string_literal: true
2
+
3
+ class GandiV5
4
+ class Domain
5
+ # Manage web forwarding.
6
+ # @!attribute [r] created_at
7
+ # @return [Time, nil]
8
+ # @!attribute [r] updated_at
9
+ # @return [Time, nil]
10
+ # @!attribute [r] type
11
+ # @return [:cloak, :http301, :http302]
12
+ # @!attribute [r] fqdn
13
+ # @return [String]
14
+ # @!attribute [r] protocol
15
+ # @return [:http, :https, :https_only, nil]
16
+ # @!attribute [r] target
17
+ # @return [String]
18
+ # @!attribute [r] cert_status
19
+ # @return [String, nil]
20
+ # @!attribute [r] cert_uuid
21
+ # @return [String, nil]
22
+ class WebForwarding
23
+ include GandiV5::Data
24
+
25
+ members :cert_uuid, :cert_status
26
+ member :target, gandi_key: 'url'
27
+ member :fqdn, gandi_key: 'host'
28
+ member :type, converter: GandiV5::Data::Converter::Symbol
29
+ member :created_at, converter: GandiV5::Data::Converter::Time
30
+ member :updated_at, converter: GandiV5::Data::Converter::Time
31
+ member(
32
+ :protocol,
33
+ converter: GandiV5::Data::Converter.new(
34
+ from_gandi: lambda { |value|
35
+ {
36
+ 'http' => :http,
37
+ 'https' => :https,
38
+ 'httpsonly' => :https_only
39
+ }.fetch(value)
40
+ }
41
+ )
42
+ )
43
+
44
+ # Update the redirection in Gandi.
45
+ # @see https://api.gandi.net/docs/domains/#patch-v5-domain-domains-domain-webredirs-host
46
+ # @param target [String, #to_s] the url to redirect to (e.g. www.example.com/path).
47
+ # @param protocol [:http, :https, :https_only]
48
+ # @param type [:cloak, :http301, :http302]
49
+ # @param override [Boolean] If true, a DNS record will be created.
50
+ # When the value is false and no matching DNS record exists, it will trigger an error.
51
+ # @return [GandiV5::Domain::WebRedirection]
52
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error
53
+ def update(target: nil, protocol: nil, type: nil, override: nil)
54
+ body = {}
55
+ body['url'] = target.to_s unless target.nil?
56
+ body['protocol'] = protocol.to_s.delete('_') unless protocol.nil?
57
+ body['type'] = type.to_s unless type.nil?
58
+ body['override'] = override unless override.nil?
59
+
60
+ GandiV5.patch url, body.to_json
61
+ refresh
62
+ end
63
+
64
+ # Delete this web redirection from Gandi.
65
+ # @see https://api.gandi.net/docs/domains/#delete-v5-domain-domains-domain-webredirs-host
66
+ # @return [String] The confirmation message from Gandi.
67
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
68
+ def delete
69
+ _response, data = GandiV5.delete url
70
+ data['message']
71
+ end
72
+
73
+ # Check if this is an HTTP 301 (permanent) redirection.
74
+ def http301?
75
+ type == :http301
76
+ end
77
+
78
+ # Check if this is an HTTP 302 (found) redirection.
79
+ def http302?
80
+ type == :http302
81
+ end
82
+
83
+ # Check if this is an HTTP 301 (permanent) redirection.
84
+ def permanent?
85
+ type == :http301
86
+ end
87
+
88
+ # Check if this is an HTTP 302 (found) redirection.
89
+ def found?
90
+ type == :http302
91
+ end
92
+
93
+ # Check if this is a temporary redirection.
94
+ def temporary?
95
+ type == :http302
96
+ end
97
+
98
+ # Check if it's an http end point
99
+ def http?
100
+ protocol == :http || protocol == :https
101
+ end
102
+
103
+ # Check if it's an https end point
104
+ def https?
105
+ protocol == :https || protocol == :https_only
106
+ end
107
+
108
+ # Check if it's an https only
109
+ def https_only?
110
+ protocol == :https_only
111
+ end
112
+
113
+ # Create a new web redirection.
114
+ # @see https://api.gandi.net/docs/domains/#post-v5-domain-domains-domain-webredirs
115
+ # @param domain [String, #to_s] the domain name to create the redirection in.
116
+ # @param host [String, #to_s] the host name to redirect from.
117
+ # @param target [String, #to_s] the url to redirect to (e.g. www.example.com/path).
118
+ # @param protocol [:http, :https, :https_only]
119
+ # @param type [:cloak, :http301, :http302]
120
+ # @param override [Boolean] When you create a redirection on a domain, a DNS record is created
121
+ # if it does not exist. When the record already exists and this parameter is set to true it
122
+ # will overwrite the record. Otherwise it will trigger an error.
123
+ # @return [GandiV5::Domain::WebRedirection] the created redirection
124
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error
125
+ def self.create(domain:, host:, target:, protocol:, type:, override: false)
126
+ body = {
127
+ 'host' => host.to_s,
128
+ 'protocol' => protocol.to_s.delete('_'),
129
+ 'type' => type.to_s,
130
+ 'url' => target.to_s,
131
+ 'override' => override
132
+ }.to_json
133
+
134
+ GandiV5.post url(domain), body
135
+ fetch domain, host
136
+ end
137
+
138
+ # Get web redirect for a host in a domain.
139
+ # @see https://api.gandi.net/docs/domains/#get-v5-domain-domains-domain-webredirs-host
140
+ # @param domain [String, #to_s] the domain to get the web redirection for.
141
+ # @param host [String, #to_s] the host name to get the web redirection for.
142
+ # @return [GandiV5::Domain::WebRedirect]
143
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
144
+ def self.fetch(domain, host)
145
+ _response, data = GandiV5.get url(domain, host)
146
+ redirect = from_gandi data
147
+ redirect.instance_exec { @domain = domain }
148
+ redirect
149
+ end
150
+
151
+ # List web redirects for a domain.
152
+ # @see https://api.gandi.net/docs/domains/#get-v5-domain-domains-domain-webredirs-host
153
+ # @param domain [String, #to_s] the domain to get the web redirections for.
154
+ # @param page [#each<Integer, #to_s>] the page(s) of results to retrieve.
155
+ # If page is not provided keep querying until an empty list is returned.
156
+ # If page responds to .each then iterate until an empty list is returned.
157
+ # @param per_page [Integer, #to_s] (optional default 100) how many results to get per page.
158
+ # @return [Array<GandiV5::Domain::WebRedirect>]
159
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
160
+ def self.list(domain, page: (1..), per_page: 100)
161
+ redirects = []
162
+ GandiV5.paginated_get(url(domain), page, per_page) do |data|
163
+ redirects += data.map { |redirect| from_gandi redirect }
164
+ end
165
+ redirects.each { |redirect| redirect.instance_exec { @domain = domain } }
166
+ redirects
167
+ end
168
+
169
+ private
170
+
171
+ def url
172
+ "#{BASE}domain/domains/#{CGI.escape @domain}/webredirs/#{fqdn}"
173
+ end
174
+
175
+ def self.url(domain, host = nil)
176
+ "#{BASE}domain/domains/#{CGI.escape domain}/webredirs" +
177
+ (host ? "/#{CGI.escape host}.#{CGI.escape domain}" : '')
178
+ end
179
+ private_class_method :url
180
+ end
181
+ end
182
+ end
@@ -3,6 +3,8 @@
3
3
  class GandiV5
4
4
  # Gandi Email Mailbox Management API.
5
5
  # @see https://api.gandi.net/docs/email/
6
+ # rubocop:disable Lint/EmptyClass
6
7
  class Email
7
8
  end
9
+ # rubocop:enable Lint/EmptyClass
8
10
  end
@@ -77,7 +77,7 @@ class GandiV5
77
77
  # @return [Array<GandiV5::Email::Forward>]
78
78
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
79
79
  def self.list(fqdn, page: (1..), per_page: 100, **params)
80
- params.reject! { |_k, v| v.nil? }
80
+ params.compact! { |_k, v| v.nil? }
81
81
 
82
82
  mailboxes = []
83
83
  GandiV5.paginated_get(url(fqdn), page, per_page, params: params) do |data|
@@ -199,7 +199,7 @@ class GandiV5
199
199
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
200
200
  def self.list(fqdn, page: (1..), per_page: 100, **params)
201
201
  params['~login'] = params.delete(:login)
202
- params.reject! { |_k, v| v.nil? }
202
+ params.compact! { |_k, v| v.nil? }
203
203
 
204
204
  mailboxes = []
205
205
  GandiV5.paginated_get(url(fqdn), page, per_page, params: params) do |data|
@@ -60,7 +60,7 @@ class GandiV5
60
60
  # @return [Array<GandiV5::LiveDNS::Domain::Snapshot>]
61
61
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
62
62
  def self.list(fqdn, page: (1..), per_page: 100, **params)
63
- params.reject! { |_k, v| v.nil? }
63
+ params.compact! { |_k, v| v.nil? }
64
64
 
65
65
  snapshots = []
66
66
  GandiV5.paginated_get(url(fqdn), page, per_page, params: params) do |data|
@@ -23,7 +23,7 @@ class GandiV5
23
23
  gandi_key: 'config_samples',
24
24
  converter: GandiV5::Data::Converter.new(
25
25
  from_gandi: ->(value) { value.transform_keys(&:to_sym) },
26
- to_gandi: ->(_value) { nil }
26
+ to_gandi: ->(_value) {}
27
27
  )
28
28
  )
29
29
 
@@ -146,6 +146,12 @@ class GandiV5
146
146
  data
147
147
  end
148
148
 
149
+ # @see GandiV5::SimpleHosting::Instance::VirtualHost.create
150
+ def create_virtual_host(fqdn, **params)
151
+ GandiV5::SimpleHosting::Instance::VirtualHost.create(uuid, fqdn, **params)
152
+ refresh
153
+ end
154
+
149
155
  # Requery Gandi fo this instance's information.
150
156
  # @return [GandiV5::SimpleHosting::Instance]
151
157
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
@@ -57,7 +57,7 @@ class GandiV5
57
57
  converter: GandiV5::SimpleHosting::Instance::VirtualHost::LinkedDnsZone
58
58
  )
59
59
 
60
- # Requery Gandi fo this hosts's information.
60
+ # Requery Gandi fo this virtual hosts's information.
61
61
  # @return [GandiV5::SimpleHosting::Instance::VirtualHost]
62
62
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
63
63
  def refresh
@@ -65,6 +65,59 @@ class GandiV5
65
65
  from_gandi data
66
66
  end
67
67
 
68
+ # Delete the virtual host.
69
+ # @see https://api.gandi.net/docs/simplehosting/#delete-v5-simplehosting-instances-instance_id-vhosts-vhost_fqdn
70
+ # @return [String] The confirmation message from Gandi.
71
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
72
+ def delete
73
+ _response, data = GandiV5.delete url
74
+ data['message']
75
+ end
76
+
77
+ # Update the virtual host.
78
+ # @see https://api.gandi.net/docs/simplehosting/#patch-v5-simplehosting-instances-instance_id-vhosts-vhost_fqdn
79
+ # @param application [GandiV5::SimpleHosting::Instance::Application, Hash]
80
+ # @param https_strategy [:http_only, :allow_http_and_https, :redirect_http_to_https]
81
+ # @param linked_dns_zone_allow_alteration [Boolean]
82
+ # authorize Gandi to modify your DNS zone so that your vhost points to their
83
+ # Simple Hosting public endpoints.
84
+ # @param linked_dns_zone_allow_alteration_override [Boolean]
85
+ # authorize Gandi to override your DNS zone if there already is a record to
86
+ # link your instance to your vhost fqdn.
87
+ # @return [GandiV5::SimpleHosting::Instance::VirtualHost] self.
88
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
89
+ # rubocop:disable Metrics/MethodLength
90
+ def update(
91
+ application: nil,
92
+ https_strategy: nil,
93
+ linked_dns_zone_allow_alteration: nil,
94
+ linked_dns_zone_allow_alteration_override: false
95
+ )
96
+ https_strategy = case https_strategy
97
+ when nil then nil
98
+ when :http_only then 'HTTP_only'
99
+ when :allow_http_and_https then 'allow_HTTP_and_HTTPS'
100
+ when :redirect_http_to_https then 'redirect_HTTP_to_HTTPS'
101
+ else
102
+ fail ArgumentError,
103
+ "https_strategy #{https_strategy.inspect} is invalid"
104
+ end
105
+
106
+ body = {}
107
+ body[:application] = application.to_h.slice(:name, :parameters) if application
108
+ body[:https_strategy] = https_strategy if https_strategy
109
+ unless linked_dns_zone_allow_alteration.nil?
110
+ body[:linked_dns_zone] = {
111
+ allow_alteration: linked_dns_zone_allow_alteration,
112
+ allow_alteration_override: linked_dns_zone_allow_alteration_override
113
+ }
114
+ end
115
+
116
+ _response, data = GandiV5.put url, body.to_json
117
+ from_gandi data
118
+ end
119
+ # rubocop:enable Metrics/MethodLength
120
+
68
121
  # Check if the virtual host is being created
69
122
  # @return [Boolean]
70
123
  def being_created?
@@ -148,7 +201,39 @@ class GandiV5
148
201
  from_gandi data.merge('instance_uuid' => instance_uuid)
149
202
  end
150
203
 
151
- # List instances.
204
+ # Create a new virtual host for an instance
205
+ # @see https://api.gandi.net/docs/simplehosting/#post-v5-simplehosting-instances-instance_id-vhosts
206
+ # @param fqdn [String, #to_s] the fully qualified domain of the virtual host to create.
207
+ # @param application [GandiV5::SimpleHosting::Instance::Application, Hash]
208
+ # @param linked_dns_zone_allow_alteration [Boolean]
209
+ # authorize Gandi to modify your DNS zone so that your vhost points to their
210
+ # Simple Hosting public endpoints.
211
+ # @param linked_dns_zone_allow_alteration_override [Boolean]
212
+ # authorize Gandi to override your DNS zone if there already is a record to
213
+ # link your instance to your vhost fqdn.
214
+ # @return [GandiV5::SimpleHosting::Instance::VirtualHost]
215
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
216
+ def self.create(
217
+ instance_uuid,
218
+ fqdn,
219
+ application: nil,
220
+ linked_dns_zone_allow_alteration: nil,
221
+ linked_dns_zone_allow_alteration_override: false
222
+ )
223
+ body = { fqdn: fqdn }
224
+ body[:application] = application.to_h.slice(:name, :parameters) if application
225
+ unless linked_dns_zone_allow_alteration.nil?
226
+ body[:linked_dns_zone] = {
227
+ allow_alteration: linked_dns_zone_allow_alteration,
228
+ allow_alteration_override: linked_dns_zone_allow_alteration_override
229
+ }
230
+ end
231
+
232
+ _response, _data = GandiV5.post url(instance_uuid), body.to_json
233
+ fetch instance_uuid, fqdn
234
+ end
235
+
236
+ # List virtual hosts for an instance.
152
237
  # @see https://api.gandi.net/docs/simplehosting#get-v5-simplehosting-instances-instance_id-vhosts
153
238
  # @param page [#each<Integer, #to_s>] the page(s) of results to retrieve.
154
239
  # If page is not provided keep querying until an empty list is returned.