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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +49 -9
- data/README.md +64 -15
- data/lib/gandi_v5/billing/info/prepaid.rb +1 -0
- data/lib/gandi_v5/data/converter/array_of.rb +3 -2
- data/lib/gandi_v5/data/converter/integer.rb +3 -2
- data/lib/gandi_v5/data/converter/symbol.rb +3 -2
- data/lib/gandi_v5/data/converter/time.rb +3 -2
- data/lib/gandi_v5/data/converter.rb +3 -2
- data/lib/gandi_v5/data.rb +13 -14
- data/lib/gandi_v5/domain/availability/product/period.rb +1 -1
- data/lib/gandi_v5/domain/contact.rb +5 -5
- data/lib/gandi_v5/domain/tld.rb +2 -2
- data/lib/gandi_v5/domain/transfer_in/availability.rb +51 -0
- data/lib/gandi_v5/domain/transfer_in.rb +172 -0
- data/lib/gandi_v5/domain/web_forwarding.rb +182 -0
- data/lib/gandi_v5/domain.rb +52 -13
- data/lib/gandi_v5/email/forward.rb +1 -1
- data/lib/gandi_v5/email/mailbox.rb +6 -6
- data/lib/gandi_v5/email/slot.rb +1 -1
- data/lib/gandi_v5/email.rb +3 -0
- data/lib/gandi_v5/error/gandi_error.rb +1 -0
- data/lib/gandi_v5/live_dns/domain/dnssec_key.rb +16 -11
- data/lib/gandi_v5/live_dns/domain/snapshot.rb +5 -1
- data/lib/gandi_v5/live_dns/domain/tsig_key.rb +8 -5
- data/lib/gandi_v5/live_dns/domain.rb +29 -1
- data/lib/gandi_v5/live_dns.rb +2 -0
- data/lib/gandi_v5/simple_hosting/instance/application.rb +1 -0
- data/lib/gandi_v5/simple_hosting/instance/database.rb +1 -0
- data/lib/gandi_v5/simple_hosting/instance/language.rb +1 -1
- data/lib/gandi_v5/simple_hosting/instance/upgrade.rb +1 -0
- data/lib/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone.rb +2 -1
- data/lib/gandi_v5/simple_hosting/instance/virtual_host.rb +90 -5
- data/lib/gandi_v5/simple_hosting/instance.rb +9 -0
- data/lib/gandi_v5/simple_hosting.rb +1 -0
- data/lib/gandi_v5/template/dispatch.rb +109 -0
- data/lib/gandi_v5/template/payload/dns_record.rb +23 -0
- data/lib/gandi_v5/template/payload/web_forwarding.rb +82 -0
- data/lib/gandi_v5/template/payload.rb +64 -0
- data/lib/gandi_v5/template.rb +271 -0
- data/lib/gandi_v5/version.rb +1 -1
- data/lib/gandi_v5.rb +115 -66
- data/spec/.rubocop.yml +3 -50
- data/spec/features/list_domain_renewals_spec.rb +16 -0
- data/spec/features/list_email_addresses_spec.rb +39 -0
- data/spec/fixtures/bodies/GandiV5_Domain_TransferIn/fetch.yml +21 -0
- data/spec/fixtures/bodies/GandiV5_Domain_TransferIn_Availability/fetch.yml +10 -0
- data/spec/fixtures/bodies/GandiV5_Domain_WebForwarding/fetch.yml +9 -0
- data/spec/fixtures/bodies/GandiV5_Domain_WebForwarding/list.yml +9 -0
- data/spec/fixtures/bodies/GandiV5_Template/fetch.yml +41 -0
- data/spec/fixtures/bodies/GandiV5_Template/list.yml +20 -0
- data/spec/fixtures/bodies/GandiV5_Template_Dispatch/fetch.yml +49 -0
- data/spec/fixtures/vcr/Examples/List_domain_renewals.yml +54 -0
- data/spec/fixtures/vcr/Examples/List_email_addresses.yml +103 -0
- data/spec/spec_helper.rb +8 -7
- data/spec/units/gandi_v5/domain/transfer_in/availability_spec.rb +49 -0
- data/spec/units/gandi_v5/domain/transfer_in_spec.rb +143 -0
- data/spec/units/gandi_v5/domain/web_forwarding_spec.rb +150 -0
- data/spec/units/gandi_v5/domain_spec.rb +50 -0
- data/spec/units/gandi_v5/simple_hosting/instance/virtual_host_spec.rb +125 -0
- data/spec/units/gandi_v5/simple_hosting/instance_spec.rb +8 -0
- data/spec/units/gandi_v5/template/dispatch_spec.rb +70 -0
- data/spec/units/gandi_v5/template/payload/web_forwarding_spec.rb +44 -0
- data/spec/units/gandi_v5/template_spec.rb +341 -0
- data/spec/units/gandi_v5_spec.rb +1 -1
- metadata +191 -57
- data/.gitignore +0 -26
- data/.rspec +0 -3
- data/.rubocop.yml +0 -74
- data/.travis.yml +0 -38
- data/FUNDING.yml +0 -10
- data/Gemfile +0 -6
- data/Guardfile +0 -39
- data/Rakefile +0 -3
- data/bin/console +0 -13
- data/gandi_v5.gemspec +0 -42
- data/spec/units/gandi_v5/billing/info_spec.rb +0 -4
- data/spec/units/gandi_v5/domain/availability/product/period_spec.rb +0 -4
- data/spec/units/gandi_v5/domain/availability/product/price_spec.rb +0 -4
- data/spec/units/gandi_v5/domain/availability/product_spec.rb +0 -4
- data/spec/units/gandi_v5/domain/availability/tax_spec.rb +0 -4
- data/spec/units/gandi_v5/domain/contract_spec.rb +0 -4
- data/spec/units/gandi_v5/domain/dates_spec.rb +0 -4
- data/spec/units/gandi_v5/domain/restore_information_spec.rb +0 -4
- data/spec/units/gandi_v5/error_spec.rb +0 -4
- data/spec/units/gandi_v5/sharing_space_spec.rb +0 -4
- data/spec/units/gandi_v5/simple_hosting/instance/database_spec.rb +0 -4
- data/spec/units/gandi_v5/simple_hosting/instance/language_spec.rb +0 -4
- data/spec/units/gandi_v5/simple_hosting/instance/upgrade_spec.rb +0 -4
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GandiV5
|
4
|
+
class Template
|
5
|
+
# Payload of a configuration template.
|
6
|
+
# @!attribute [r] dns_records
|
7
|
+
# @return [Array<GandiV5::Template::Payload::DNSRecord>, :default, nil]
|
8
|
+
# the DNS records this template will create.
|
9
|
+
# @!attribute [r] mailboxes
|
10
|
+
# @return [Array<String>, nil] the mailbox names (upto 2) which will be created.
|
11
|
+
# @!attribute [r] name_servers
|
12
|
+
# @return [Array<String>, :live_dns, nil] hosts to use as name servers for the domain.
|
13
|
+
# @!attribute [r] web_redirects
|
14
|
+
# @return [Array<GandiV5::Template::Payload::WebRedirect>, nil]
|
15
|
+
# what web redirects will be created.
|
16
|
+
class Payload
|
17
|
+
include GandiV5::Data
|
18
|
+
|
19
|
+
member(
|
20
|
+
:dns_records,
|
21
|
+
gandi_key: 'dns:records',
|
22
|
+
converter: GandiV5::Data::Converter.new(
|
23
|
+
from_gandi: lambda { |hash|
|
24
|
+
if hash['default']
|
25
|
+
:default
|
26
|
+
else
|
27
|
+
hash.fetch('records').map do |item|
|
28
|
+
GandiV5::Template::Payload::DNSRecord.from_gandi item
|
29
|
+
end
|
30
|
+
end
|
31
|
+
}
|
32
|
+
)
|
33
|
+
)
|
34
|
+
|
35
|
+
member(
|
36
|
+
:mailboxes,
|
37
|
+
gandi_key: 'domain:mailboxes',
|
38
|
+
converter: GandiV5::Data::Converter.new(
|
39
|
+
from_gandi: ->(h_a_h) { h_a_h.fetch('values').map { |h| h.fetch('login') } }
|
40
|
+
)
|
41
|
+
)
|
42
|
+
|
43
|
+
member(
|
44
|
+
:name_servers,
|
45
|
+
gandi_key: 'domain:nameservers',
|
46
|
+
converter: GandiV5::Data::Converter.new(
|
47
|
+
from_gandi: ->(h) { h.fetch('service').eql?('livedns') ? :livedns : h.fetch('addresses') }
|
48
|
+
)
|
49
|
+
)
|
50
|
+
|
51
|
+
member(
|
52
|
+
:web_forwardings,
|
53
|
+
gandi_key: 'domain:webredirs',
|
54
|
+
converter: GandiV5::Data::Converter.new(
|
55
|
+
from_gandi: lambda { |hash|
|
56
|
+
hash.fetch('values').map do |item|
|
57
|
+
GandiV5::Template::Payload::WebForwarding.from_gandi item
|
58
|
+
end
|
59
|
+
}
|
60
|
+
)
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,271 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GandiV5
|
4
|
+
# Manage configuration templates.
|
5
|
+
# @!attribute [r] description
|
6
|
+
# @return [String] template purpose's description.
|
7
|
+
# @!attribute [r] editable
|
8
|
+
# @return [Boolean]
|
9
|
+
# @!attribute [r] uuid
|
10
|
+
# @return [String]
|
11
|
+
# @!attribute [r] name
|
12
|
+
# @return [String]
|
13
|
+
# @!attribute [r] orgname
|
14
|
+
# @return [String]
|
15
|
+
# @!attribute [r] sharing_space
|
16
|
+
# @return [GandiV5::SharingSpace]
|
17
|
+
# @!attribute [r] variables
|
18
|
+
# @return [Array<String>, nil]
|
19
|
+
# @!attribute [r] payload
|
20
|
+
# @return [Array<GandiV5::Template::Payload] the settings which will be applied
|
21
|
+
# when this template is used.
|
22
|
+
class Template
|
23
|
+
include GandiV5::Data
|
24
|
+
|
25
|
+
members :name, :description, :editable, :variables
|
26
|
+
member :uuid, gandi_key: 'id'
|
27
|
+
member :organisation_name, gandi_key: 'orgname'
|
28
|
+
member :payload, converter: GandiV5::Template::Payload
|
29
|
+
member(
|
30
|
+
:sharing_space,
|
31
|
+
gandi_key: 'sharing_space',
|
32
|
+
converter: GandiV5::SharingSpace
|
33
|
+
)
|
34
|
+
|
35
|
+
# Requery Gandi for this template's information.
|
36
|
+
# @return [GandiV5::Template]
|
37
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
38
|
+
def refresh
|
39
|
+
_response, data = GandiV5.get url
|
40
|
+
from_gandi data
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
# Delete this template from Gandi.
|
45
|
+
# @see https://api.gandi.net/docs/template/#delete-v5-template-templates-id
|
46
|
+
# @return [nil]
|
47
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
48
|
+
def delete
|
49
|
+
GandiV5.delete url
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
|
53
|
+
# Applies the template to a domain.
|
54
|
+
# @see https://api.gandi.net/v5/template/dispatch/{id}
|
55
|
+
# @return [String] The UUID of the dispatch,
|
56
|
+
# keep hold of this you'll need it if you want to check the progress.
|
57
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
58
|
+
def apply(domain_uuid)
|
59
|
+
body = { 'object_type' => 'domain', 'object_id' => domain_uuid }.to_json
|
60
|
+
_response, data = GandiV5.post url, body
|
61
|
+
data.fetch('dispatch_href').split('/').last
|
62
|
+
end
|
63
|
+
|
64
|
+
# Update the template in Gandi.
|
65
|
+
# @see https://api.gandi.net/docs/template/#patch-v5-template-templates-id
|
66
|
+
# @param name [String, #to_s] the name to give the created template.
|
67
|
+
# @param description [String, #to_s] description of what the template achieves.
|
68
|
+
# @param dns_records [Array<Hash>, :default] The DNS records to create (as Gandi's docs)
|
69
|
+
# @option dns_records [String] :name The name of the DNS record to create.
|
70
|
+
# @option dns_records [String] :type The type of the DNS record to create.
|
71
|
+
# @option dns_records [Array<String>] :values The values for the created DNS record.
|
72
|
+
# @option dns_records [Integer] :ttl The TTL for the created record (300-2592000)
|
73
|
+
# @param mailboxes [Array<String>] The mailboxes to create (as Gandi's docs)
|
74
|
+
# @param name_servers [Array<String>, :livedns] The name servers to create (as Gandi's docs)
|
75
|
+
# @param web_forwardings [Array<Hash>] The web redirects to create (as Gandi's docs)
|
76
|
+
# @option web_forwardings [:cloak, :http301, :http302, :permanent, :temporary, :found] :type
|
77
|
+
# @option web_forwardings [String] :target
|
78
|
+
# @option web_forwardings [String] :source_host (optional)
|
79
|
+
# @option web_forwardings [Boolean] :override (optional, default false)
|
80
|
+
# When you create a redirection on a domain, a DNS record is created if it does not exist.
|
81
|
+
# When the record already exists and this parameter is set to true it will overwrite the
|
82
|
+
# record. Otherwise it will trigger an error.
|
83
|
+
# @option web_forwardings [:http, :https, :https_only] :protocol (optional)
|
84
|
+
# @return [GandiV5::Template]
|
85
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error
|
86
|
+
# rubocop:disable Metrics/AbcSize
|
87
|
+
def update(
|
88
|
+
name: nil,
|
89
|
+
description: nil,
|
90
|
+
dns_records: nil,
|
91
|
+
mailboxes: nil,
|
92
|
+
name_servers: nil,
|
93
|
+
web_forwardings: nil
|
94
|
+
)
|
95
|
+
|
96
|
+
body = Hash.new { |hash, key| hash[key] = {} }
|
97
|
+
body['name'] = name if name
|
98
|
+
body['description'] = description if description
|
99
|
+
body['payload']['dns:records'] = gandify_dns_records(dns_records) if dns_records
|
100
|
+
body['payload']['domain:mailboxes'] = gandify_mailboxes(mailboxes) if mailboxes
|
101
|
+
body['payload']['domain:nameservers'] = gandify_name_servers(name_servers) if name_servers
|
102
|
+
if web_forwardings
|
103
|
+
body['payload']['domain:webredirs'] = gandify_web_forwardings(web_forwardings)
|
104
|
+
end
|
105
|
+
|
106
|
+
GandiV5.patch url, body.to_json
|
107
|
+
refresh
|
108
|
+
end
|
109
|
+
# rubocop:enable Metrics/AbcSize
|
110
|
+
|
111
|
+
# Get information for a template.
|
112
|
+
# @see https://api.gandi.net/docs/template/#get-v5-template-templates-id
|
113
|
+
# @param uuid [String, #to_s] unique identifier of the template.
|
114
|
+
# @return [GandiV5::Template]
|
115
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
116
|
+
def self.fetch(uuid)
|
117
|
+
_response, data = GandiV5.get url(uuid)
|
118
|
+
from_gandi data
|
119
|
+
end
|
120
|
+
|
121
|
+
# List templates.
|
122
|
+
# @see https://api.gandi.net/docs/template/#get-v5-template-templates
|
123
|
+
# @param page [Integer, #each<Integer>] which page(s) of results to get.
|
124
|
+
# If page is not provided keep querying until an empty list is returned.
|
125
|
+
# If page responds to .each then iterate until an empty list is returned.
|
126
|
+
# @param per_page [Integer, #to_s] (optional default 100) how many results ot get per page.
|
127
|
+
# @return [Array<GandiV5::Template>]
|
128
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error.
|
129
|
+
def self.list(page: (1..), per_page: 100)
|
130
|
+
templates = []
|
131
|
+
GandiV5.paginated_get(url, page, per_page) do |data|
|
132
|
+
templates += data.map { |template| from_gandi template }
|
133
|
+
end
|
134
|
+
templates
|
135
|
+
end
|
136
|
+
|
137
|
+
# Create a new template.
|
138
|
+
# @see https://api.gandi.net/docs/template/#post-v5-template-templates
|
139
|
+
# @param name [String, #to_s] the name to give the created template.
|
140
|
+
# @param description [String, #to_s] description of what the template achieves.
|
141
|
+
# @param sharing_id [String] either:
|
142
|
+
# * nil (default) - nothing special happens,
|
143
|
+
# the template belongs to the user making the request.
|
144
|
+
# * an organization ID - the template will belong to the organization.
|
145
|
+
# * a reseller ID - the template will belong to the reseller.
|
146
|
+
# @param payload [Hash, #to_h]
|
147
|
+
# @option payload [Hash] 'dns:records' The DNS records to create (as Gandi's docs)
|
148
|
+
# @option payload [Hash] 'domain:mailboxes' The mailboxes to create (as Gandi's docs)
|
149
|
+
# @option payload [Hash] 'domain:nameservers' The name servers to create (as Gandi's docs)
|
150
|
+
# @option payload [Hash] 'domain:webredirs' The web redirects to create (as Gandi's docs)
|
151
|
+
# @option payload [Array<Hash>, :default] :dns_records
|
152
|
+
# Generate dns:records from the passed list or use Gandi's default records.
|
153
|
+
# @option dns_records [String] :name The name of the DNS record to create.
|
154
|
+
# @option dns_records [String] :type The type of the DNS record to create.
|
155
|
+
# @option dns_records [Array<String>] :values The values for the created DNS record.
|
156
|
+
# @option dns_records [Integer] :ttl The TTL for the created record (300-2592000)
|
157
|
+
# @option payload [Array<String>] :mailboxes
|
158
|
+
# Generate domain:mailboxes from the passed list of mail names.
|
159
|
+
# @option payload [Array<String>, :livedns] :name_servers
|
160
|
+
# Generate domain:nameservers from the passed list of addresses, or set to Gandi's livedns.
|
161
|
+
# @option payload [Array<Hash>] :web_forwardings Generate domain:webredirs from the passed list.
|
162
|
+
# @option web_forwardings [:cloak, :http301, :http302, :permanent, :temporary, :found] :type
|
163
|
+
# @option web_forwardings [String] :target
|
164
|
+
# @option web_forwardings [String] :host (optional)
|
165
|
+
# @option web_forwardings [Boolean] :override (optional, default false)
|
166
|
+
# When you create a redirection on a domain, a DNS record is created if it does not exist.
|
167
|
+
# When the record already exists and this parameter is set to true it will overwrite the
|
168
|
+
# record. Otherwise it will trigger an error.
|
169
|
+
# @option web_forwardings [:http, :https, :https_only] :protocol (optional)
|
170
|
+
# @return [GandiV5::Template] the created template
|
171
|
+
# @raise [GandiV5::Error::GandiError] if Gandi returns an error
|
172
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
173
|
+
def self.create(name:, description:, sharing_id: nil, **payload)
|
174
|
+
if payload.key? :dns_records
|
175
|
+
payload['dns:records'] = gandify_dns_records(payload.delete(:dns_records))
|
176
|
+
end
|
177
|
+
if payload.key? :mailboxes
|
178
|
+
payload['domain:mailboxes'] = gandify_mailboxes(payload.delete(:mailboxes))
|
179
|
+
end
|
180
|
+
if payload.key? :name_servers
|
181
|
+
payload['domain:nameservers'] = gandify_name_servers(payload.delete(:name_servers))
|
182
|
+
end
|
183
|
+
if payload.key? :web_forwardings
|
184
|
+
payload['domain:webredirs'] = gandify_web_forwardings(payload.delete(:web_forwardings))
|
185
|
+
end
|
186
|
+
|
187
|
+
url_ = sharing_id ? "#{url}?sharing_id=#{sharing_id}" : url
|
188
|
+
body = { name: name, description: description, payload: payload }.to_json
|
189
|
+
|
190
|
+
response, _data = GandiV5.post url_, body
|
191
|
+
fetch response.headers[:location].split('/').last
|
192
|
+
end
|
193
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
194
|
+
|
195
|
+
private
|
196
|
+
|
197
|
+
def self.gandify_dns_records(value)
|
198
|
+
if value == :default
|
199
|
+
{ default: true }
|
200
|
+
else
|
201
|
+
{
|
202
|
+
default: false,
|
203
|
+
records: value
|
204
|
+
}
|
205
|
+
end
|
206
|
+
end
|
207
|
+
private_class_method :gandify_dns_records
|
208
|
+
|
209
|
+
def gandify_dns_records(value)
|
210
|
+
self.class.send :gandify_dns_records, value
|
211
|
+
end
|
212
|
+
|
213
|
+
def self.gandify_mailboxes(value)
|
214
|
+
{ values: value.map { |name| { login: name } } }
|
215
|
+
end
|
216
|
+
private_class_method :gandify_mailboxes
|
217
|
+
|
218
|
+
def gandify_mailboxes(value)
|
219
|
+
self.class.send :gandify_mailboxes, value
|
220
|
+
end
|
221
|
+
|
222
|
+
def self.gandify_name_servers(value)
|
223
|
+
if value == :livedns
|
224
|
+
{ service: :livedns }
|
225
|
+
else
|
226
|
+
{
|
227
|
+
service: :custom,
|
228
|
+
addresses: value
|
229
|
+
}
|
230
|
+
end
|
231
|
+
end
|
232
|
+
private_class_method :gandify_name_servers
|
233
|
+
|
234
|
+
def gandify_name_servers(value)
|
235
|
+
self.class.send :gandify_name_servers, value
|
236
|
+
end
|
237
|
+
|
238
|
+
def self.gandify_web_forwardings(value)
|
239
|
+
type_map = {
|
240
|
+
'permanent' => 'http301',
|
241
|
+
'temporary' => 'http302',
|
242
|
+
'found' => 'http302'
|
243
|
+
}
|
244
|
+
|
245
|
+
{
|
246
|
+
values: value.map do |redirect|
|
247
|
+
type = redirect.fetch(:type).to_s
|
248
|
+
new_redirect = { type: type_map.fetch(type, type), url: redirect.fetch(:target) }
|
249
|
+
new_redirect[:host] = redirect[:host] if redirect.key?(:host)
|
250
|
+
new_redirect[:override] = redirect[:override] if redirect.key?(:override)
|
251
|
+
new_redirect[:protocol] = redirect[:protocol].to_s.delete('_') if redirect.key?(:protocol)
|
252
|
+
new_redirect
|
253
|
+
end
|
254
|
+
}
|
255
|
+
end
|
256
|
+
private_class_method :gandify_web_forwardings
|
257
|
+
|
258
|
+
def gandify_web_forwardings(value)
|
259
|
+
self.class.send :gandify_web_forwardings, value
|
260
|
+
end
|
261
|
+
|
262
|
+
def url
|
263
|
+
"#{BASE}template/templates/#{CGI.escape uuid}"
|
264
|
+
end
|
265
|
+
|
266
|
+
def self.url(uuid = nil)
|
267
|
+
"#{BASE}template/templates" + (uuid ? "/#{CGI.escape uuid}" : '')
|
268
|
+
end
|
269
|
+
private_class_method :url
|
270
|
+
end
|
271
|
+
end
|
data/lib/gandi_v5/version.rb
CHANGED
data/lib/gandi_v5.rb
CHANGED
@@ -1,18 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'json'
|
3
4
|
require 'rest_client'
|
4
5
|
require 'securerandom'
|
5
6
|
require 'zeitwerk'
|
6
7
|
|
7
8
|
# Custom inflector for Zeitwerk.
|
9
|
+
# @api private
|
8
10
|
class MyInflector < Zeitwerk::Inflector
|
9
11
|
# Convert file's base name to class name when
|
10
12
|
# Zeitwerk's included inflector gets it wrong.
|
11
13
|
# @param basename [String] the file's base name (no path or extension)
|
12
|
-
# @param
|
14
|
+
# @param _abspath [String] the file's absolute path
|
13
15
|
# @return [String] the class name
|
14
16
|
def camelize(basename, _abspath)
|
15
17
|
case basename
|
18
|
+
when 'dns_record'
|
19
|
+
'DNSRecord'
|
16
20
|
when 'live_dns'
|
17
21
|
'LiveDNS'
|
18
22
|
when 'tld'
|
@@ -31,32 +35,37 @@ loader.setup
|
|
31
35
|
|
32
36
|
# Namespace for classes which access the Gandi V5 API.
|
33
37
|
# Also provides useful methods and constants for them.
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
+
# To get your API key login to Gandi and visit
|
39
|
+
# "User Settings" -> "Change password & configure access restrictions".
|
40
|
+
# Set your API key either in the GANDI_API_KEY environment variable or
|
41
|
+
# by setting the api_key class attribute.
|
38
42
|
# @see https://api.gandi.net/docs/
|
39
43
|
# @see https://doc.livedns.gandi.net/
|
40
44
|
# @!attribute [w] api_key
|
41
45
|
# @return [String]
|
42
46
|
class GandiV5
|
47
|
+
# Base URL for all API requests.
|
43
48
|
BASE = 'https://api.gandi.net/v5/'
|
44
49
|
|
50
|
+
# Get information on a domain.
|
45
51
|
# @see GandiV5::Domain.fetch
|
46
52
|
def self.domain(fqdn)
|
47
53
|
GandiV5::Domain.fetch(fqdn)
|
48
54
|
end
|
49
55
|
|
56
|
+
# Get information on all domains.
|
50
57
|
# @see GandiV5::Domain.list
|
51
58
|
def self.domains(**params)
|
52
59
|
GandiV5::Domain.list(**params)
|
53
60
|
end
|
54
61
|
|
62
|
+
# List mailboxes for a domain.
|
55
63
|
# @see GandiV5::Email::Mailbox.list
|
56
64
|
def self.mailboxes(fqdn, **params)
|
57
65
|
GandiV5::Email::Mailbox.list(fqdn, **params)
|
58
66
|
end
|
59
67
|
|
68
|
+
# List email slots for a domain.
|
60
69
|
# @see GandiV5::Email::Slot.list
|
61
70
|
def self.mailbox_slots(fqdn)
|
62
71
|
GandiV5::Email::Slot.list(fqdn)
|
@@ -65,15 +74,21 @@ class GandiV5
|
|
65
74
|
class << self
|
66
75
|
attr_writer :api_key
|
67
76
|
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
77
|
+
# Make a GET request to a Gandi end point.
|
78
|
+
# @param url [String, #to_s]
|
79
|
+
# the full URL (including GandiV5::BASE) to fetch.
|
80
|
+
# @param headers [Hash{String, Symbol, #to_s => String, Symbol, #to_s}]
|
81
|
+
# the headers to send in the request, the authorisation will be added.
|
82
|
+
# @return [Array<(RestClient::Response, Object)>]
|
83
|
+
# The response from the server and the result of parsing the responce's body.
|
84
|
+
# @raise [RestClient::NotFound]
|
85
|
+
# @raise [RestClient::Unauthorized]
|
86
|
+
# Bad authentication attempt because of a wrong API Key.
|
87
|
+
# @raise [RestClient::Forbidden]
|
88
|
+
# Access to the resource is denied.
|
89
|
+
# Mainly due to a lack of permissions to access it.
|
90
|
+
# @raise [GandiV5::Error]
|
91
|
+
# @raise [JSON::ParserError]
|
77
92
|
def get(url, **headers)
|
78
93
|
prepare_headers headers, url
|
79
94
|
response = RestClient.get url, **headers
|
@@ -82,15 +97,23 @@ class GandiV5
|
|
82
97
|
handle_bad_request(e)
|
83
98
|
end
|
84
99
|
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
100
|
+
# Make a GET request to a paginated end point at Gandi.
|
101
|
+
# @param url [String, #to_s]
|
102
|
+
# the full URL (including GandiV5::BASE) to fetch.
|
103
|
+
# @param page [#each, Integer] the page/pages of results to get.
|
104
|
+
# @param per_page [Integer, #to_s] the number of items to get per page of results.
|
105
|
+
# @param headers [Hash{String, Symbol, #to_s => String, Symbol, #to_s}]
|
106
|
+
# the headers to send in the request, the authorisation will be added.
|
107
|
+
# @return [Array<(RestClient::Response, Object)>]
|
108
|
+
# The response from the server and the result of parsing the responce's body.
|
109
|
+
# @raise [RestClient::NotFound]
|
110
|
+
# @raise [RestClient::Unauthorized]
|
111
|
+
# Bad authentication attempt because of a wrong API Key.
|
112
|
+
# @raise [RestClient::Forbidden]
|
113
|
+
# Access to the resource is denied.
|
114
|
+
# Mainly due to a lack of permissions to access it.
|
115
|
+
# @raise [GandiV5::Error]
|
116
|
+
# @raise [JSON::ParserError]
|
94
117
|
def paginated_get(url, page = (1..), per_page = 100, **headers)
|
95
118
|
unless page.respond_to?(:each)
|
96
119
|
fail ArgumentError, 'page must be positive' unless page.positive?
|
@@ -112,16 +135,21 @@ class GandiV5
|
|
112
135
|
end
|
113
136
|
end
|
114
137
|
|
115
|
-
#
|
116
|
-
#
|
117
|
-
#
|
118
|
-
#
|
119
|
-
#
|
120
|
-
#
|
121
|
-
#
|
122
|
-
#
|
123
|
-
#
|
124
|
-
#
|
138
|
+
# Make a DELETE request to a Gandi end point.
|
139
|
+
# @param url [String, #to_s]
|
140
|
+
# the full URL (including GandiV5::BASE) to fetch.
|
141
|
+
# @param headers [Hash{String, Symbol, #to_s => String, Symbol, #to_s}]
|
142
|
+
# the headers to send in the request, the authorisation will be added.
|
143
|
+
# @return [Array<(RestClient::Response, Object)>]
|
144
|
+
# The response from the server and the result of parsing the responce's body.
|
145
|
+
# @raise [RestClient::NotFound]
|
146
|
+
# @raise [RestClient::Unauthorized]
|
147
|
+
# Bad authentication attempt because of a wrong API Key.
|
148
|
+
# @raise [RestClient::Forbidden]
|
149
|
+
# Access to the resource is denied.
|
150
|
+
# Mainly due to a lack of permissions to access it.
|
151
|
+
# @raise [GandiV5::Error]
|
152
|
+
# @raise [JSON::ParserError]
|
125
153
|
def delete(url, **headers)
|
126
154
|
prepare_headers headers, url
|
127
155
|
response = RestClient.delete url, **headers
|
@@ -133,17 +161,24 @@ class GandiV5
|
|
133
161
|
handle_bad_request(e)
|
134
162
|
end
|
135
163
|
|
136
|
-
#
|
137
|
-
#
|
138
|
-
#
|
139
|
-
#
|
140
|
-
#
|
141
|
-
#
|
142
|
-
#
|
143
|
-
#
|
144
|
-
#
|
145
|
-
#
|
146
|
-
#
|
164
|
+
# Make a PATCH request to a Gandi end point.
|
165
|
+
# @param url [String, #to_s]
|
166
|
+
# the full URL (including GandiV5::BASE) to fetch.
|
167
|
+
# @param payload [String, #to_s] the body for the request.
|
168
|
+
# @param headers [Hash{String, Symbol, #to_s => String, Symbol, #to_s}]
|
169
|
+
# the headers to send in the request, the authorisation will be added.
|
170
|
+
# @return [Array<(RestClient::Response, Object)>]
|
171
|
+
# The response from the server and the result of parsing the responce's body.
|
172
|
+
# @raise [RestClient::NotFound]
|
173
|
+
# @raise [RestClient::Unauthorized]
|
174
|
+
# Bad authentication attempt because of a wrong API Key.
|
175
|
+
# @raise [RestClient::Forbidden]
|
176
|
+
# Access to the resource is denied.
|
177
|
+
# Mainly due to a lack of permissions to access it.
|
178
|
+
# @raise [RestClient::BadRequest]
|
179
|
+
# @raise [RestClient::Conflict]
|
180
|
+
# @raise [GandiV5::Error]
|
181
|
+
# @raise [JSON::ParserError]
|
147
182
|
def patch(url, payload = '', **headers)
|
148
183
|
prepare_headers headers, url
|
149
184
|
headers[:'content-type'] ||= 'application/json'
|
@@ -153,17 +188,24 @@ class GandiV5
|
|
153
188
|
handle_bad_request(e)
|
154
189
|
end
|
155
190
|
|
156
|
-
#
|
157
|
-
#
|
158
|
-
#
|
159
|
-
#
|
160
|
-
#
|
161
|
-
#
|
162
|
-
#
|
163
|
-
#
|
164
|
-
#
|
165
|
-
#
|
166
|
-
#
|
191
|
+
# Make a POST request to a Gandi end point.
|
192
|
+
# @param url [String, #to_s]
|
193
|
+
# the full URL (including GandiV5::BASE) to fetch.
|
194
|
+
# @param payload [String, #to_s] the body for the request.
|
195
|
+
# @param headers [Hash{String, Symbol, #to_s => String, Symbol, #to_s}]
|
196
|
+
# the headers to send in the request, the authorisation will be added.
|
197
|
+
# @return [Array<(RestClient::Response, Object)>]
|
198
|
+
# The response from the server and the result of parsing the responce's body.
|
199
|
+
# @raise [RestClient::NotFound]
|
200
|
+
# @raise [RestClient::Unauthorized]
|
201
|
+
# Bad authentication attempt because of a wrong API Key.
|
202
|
+
# @raise [RestClient::Forbidden]
|
203
|
+
# Access to the resource is denied.
|
204
|
+
# Mainly due to a lack of permissions to access it.
|
205
|
+
# @raise [RestClient::BadRequest]
|
206
|
+
# @raise [RestClient::Conflict]
|
207
|
+
# @raise [GandiV5::Error]
|
208
|
+
# @raise [JSON::ParserError]
|
167
209
|
def post(url, payload = '', **headers)
|
168
210
|
prepare_headers headers, url
|
169
211
|
headers[:'content-type'] ||= 'application/json'
|
@@ -173,17 +215,24 @@ class GandiV5
|
|
173
215
|
handle_bad_request(e)
|
174
216
|
end
|
175
217
|
|
176
|
-
#
|
177
|
-
#
|
178
|
-
#
|
179
|
-
#
|
180
|
-
#
|
181
|
-
#
|
182
|
-
#
|
183
|
-
#
|
184
|
-
#
|
185
|
-
#
|
186
|
-
#
|
218
|
+
# Make a PUT request to a Gandi end point.
|
219
|
+
# @param url [String, #to_s]
|
220
|
+
# the full URL (including GandiV5::BASE) to fetch.
|
221
|
+
# @param payload [String, #to_s] the body for the request.
|
222
|
+
# @param headers [Hash{String, Symbol, #to_s => String, Symbol, #to_s}]
|
223
|
+
# the headers to send in the request, the authorisation will be added
|
224
|
+
# @return [Array<(RestClient::Response, Object)>]
|
225
|
+
# The response from the server and the result of parsing the responce's body.
|
226
|
+
# @raise [RestClient::NotFound]
|
227
|
+
# @raise [RestClient::Unauthorized]
|
228
|
+
# Bad authentication attempt because of a wrong API Key.
|
229
|
+
# @raise [RestClient::Forbidden]
|
230
|
+
# Access to the resource is denied.
|
231
|
+
# Mainly due to a lack of permissions to access it.
|
232
|
+
# @raise [RestClient::BadRequest]
|
233
|
+
# @raise [RestClient::Conflict]
|
234
|
+
# @raise [GandiV5::Error]
|
235
|
+
# @raise [JSON::ParserError]
|
187
236
|
def put(url, payload = '', **headers)
|
188
237
|
prepare_headers headers, url
|
189
238
|
headers[:'content-type'] ||= 'application/json'
|
data/spec/.rubocop.yml
CHANGED
@@ -2,57 +2,10 @@ require:
|
|
2
2
|
- rubocop-performance
|
3
3
|
AllCops:
|
4
4
|
TargetRubyVersion: 2.6.0
|
5
|
-
|
6
|
-
Enabled: true
|
5
|
+
NewCops: enable
|
7
6
|
Layout/LineLength:
|
8
7
|
Max: 125
|
9
|
-
|
10
|
-
Enabled:
|
11
|
-
Lint/DeprecatedOpenSSLConstant:
|
12
|
-
Enabled: true
|
13
|
-
Lint/MixedRegexpCaptureTypes:
|
14
|
-
Enabled: true
|
15
|
-
Lint/RaiseException:
|
16
|
-
Enabled: true
|
17
|
-
Lint/StructNewOverride:
|
18
|
-
Enabled: true
|
8
|
+
Lint/ConstantDefinitionInBlock:
|
9
|
+
Enabled: false
|
19
10
|
Metrics/BlockLength:
|
20
11
|
Max: 750
|
21
|
-
Performance/AncestorsInclude:
|
22
|
-
Enabled: true
|
23
|
-
Performance/BigDecimalWithNumericArgument:
|
24
|
-
Enabled: true
|
25
|
-
Performance/RedundantSortBlock:
|
26
|
-
Enabled: true
|
27
|
-
Performance/RedundantStringChars:
|
28
|
-
Enabled: true
|
29
|
-
Performance/ReverseFirst:
|
30
|
-
Enabled: true
|
31
|
-
Performance/SortReverse:
|
32
|
-
Enabled: true
|
33
|
-
Performance/Squeeze:
|
34
|
-
Enabled: true
|
35
|
-
Performance/StringInclude:
|
36
|
-
Enabled: true
|
37
|
-
Style/AccessorGrouping:
|
38
|
-
Enabled: true
|
39
|
-
Style/BisectedAttrAccessor:
|
40
|
-
Enabled: true
|
41
|
-
Style/ExponentialNotation:
|
42
|
-
Enabled: true
|
43
|
-
Style/HashEachMethods:
|
44
|
-
Enabled: true
|
45
|
-
Style/HashTransformKeys:
|
46
|
-
Enabled: true
|
47
|
-
Style/HashTransformValues:
|
48
|
-
Enabled: true
|
49
|
-
Style/RedundantAssignment:
|
50
|
-
Enabled: true
|
51
|
-
Style/RedundantFetchBlock:
|
52
|
-
Enabled: true
|
53
|
-
Style/RedundantRegexpCharacterClass:
|
54
|
-
Enabled: true
|
55
|
-
Style/RedundantRegexpEscape:
|
56
|
-
Enabled: true
|
57
|
-
Style/SlicingWithRange:
|
58
|
-
Enabled: true
|