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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5bcedab1f98eded02f20893ca2f4b8c5a47abe1d72d3e055ef5688b2969104df
4
- data.tar.gz: 6db74218bd3914c662c2b6cac47c76a4d9497368f80b3ef4f31ad7e6537604a5
3
+ metadata.gz: 1040cd55b98ae6f6d747d769a74e5b2cd92b09b1a8cbe5a4115851d76485f1da
4
+ data.tar.gz: afd99593144ae4650027b3bfa316bf2a49430954a2cfc846e4782a4123853ca1
5
5
  SHA512:
6
- metadata.gz: 29dad44ec126323a917bcc5c4ac8dd200e1acc7ac32cfdf7c4608a919dd872e9f2071031b371d7ad8bae8a2ed09e6bd2bf660d0095b59999859e91d180b53e70
7
- data.tar.gz: 1d2c599205a31b449c003cf4e2628b0326cf90d45ae3c75a68356879e463ee708c6d81f5fb64e1ee75ffe73fbc5402cc3e2fc290fddfe6777c0fb304ccb45a8f
6
+ metadata.gz: 1124d5fc0cc35cb3e9c41629ba9286b40c0b31a7f47f8dc7e76f7135143770c29b8da8acbecb6869ec1a9c93cd30115287f9f42b0a5e1126ee89b6ef4ff08aa2
7
+ data.tar.gz: 800b4b45ea100c39929ba4bae9ab0479b5c9d552e1d10a56029df2ff8b023a90d5794b939fb4de9ba0dc2f1b2abd71fe62f661cb5c85346ee5b53acf02d6b8f3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # Gandi V5 API Gem Changelog
2
2
 
3
+ ## Version 0.10.1
4
+
5
+ * Fix issue with json not being included
6
+
7
+ ## Version 0.10.0
8
+
9
+ * GandiV5::Domain
10
+ * Add \#transfer_lock(lock = true) and \#transfer_unlock
11
+ * Add template_id argument to .create
12
+ * Add \#web_forwardings -> GandiV5::Domain::WebForwarding.list
13
+ * Add \#new_web_forwarding -> GandiV5::Domain::WebForwarding.create
14
+ * GandiV5::Domain::TransferIn
15
+ * Add template_id argument to .create
16
+ * GandiV5::Domain::WebForwarding
17
+ * 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)
18
+ * Add .create (aliased as GandiV5::SimpleHosting::Instance#create_virtual_host)
19
+ * Add \#delete
20
+ * Add \#update
21
+ * GandiV5::Template
22
+ * GandiV5::Template::Dispatch
23
+ * Add testing against truffleruby-20.3.0
24
+
25
+ ## Version 0.9.1
26
+
27
+ * Add testing against ruby 2.7.2 and 3.0.0
28
+
29
+ ## Version 0.9.0
30
+
31
+ * Add transferring a domain to Gandi (I don't have any domains outside Gandi to test this 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):
32
+ * GandiV5::Domain::TransferIn:
33
+ * .create(fqdn, \*\*options)
34
+ * .fetch(fqdn)
35
+ * .relaunch(fqdn)
36
+ * .resend_foa_emails(fqdn, email_address)
37
+ * \#relaunch
38
+ * \#resend_foa_emails(email_address)
39
+ * GandiV5::Domain::TransferIn::Availabillity:
40
+ * .fetch(fqdn, auth_code = nil)
41
+ * Documentation improvements
42
+
3
43
  ## Version 0.8.0
4
44
 
5
45
  * Domain:
@@ -21,15 +61,15 @@
21
61
  * .list now returns an array of strings
22
62
  * Can no longer change the zone used by a domain
23
63
  * Added automatic_snapshots attribute for whether snapshots are automatically created when a modification is made to this domain's records
24
- * #replace_records and #replace_records_for merged into #replace_records
64
+ * \#replace_records and \#replace_records_for merged into \#replace_records
25
65
  * If replacing with a zone file use the new #replace_zone_lines
26
66
  * Added:
27
67
  * .create
28
68
  * .record_types
29
69
  * .generic_name_servers(fqdn)
30
- * #name_servers and #fetch_name_servers
31
- * #tsig_keys, #fetch_tsig_keys, #add_tsig_key, #remove_tsig_key
32
- * #axfr_clients, #fetch_axfr_clients, #add_axfr_client, #remove_axfr_client
70
+ * \#name_servers and #fetch_name_servers
71
+ * \#tsig_keys, #fetch_tsig_keys, \#add_tsig_key, \#remove_tsig_key
72
+ * \#axfr_clients, #fetch_axfr_clients, #add_axfr_client, \#remove_axfr_client
33
73
  * ::DnssecKeys, #dnssec_keys, #fetch_dnssec_keys
34
74
  * Snapshots:
35
75
  * Moved to live under LiveDNS::Domain not LiveDNS::Zone
@@ -79,11 +119,11 @@
79
119
  ## Version 0.2.0
80
120
 
81
121
  * Enhancements to GandiV5::Domain
82
- * .availability(fqdn, **options) moved to GandiV5::Domain::Availability.fetch(fqdn, **options)
122
+ * .availability(fqdn, \*\*options) moved to GandiV5::Domain::Availability.fetch(fqdn, \*\*options)
83
123
  * .create now returns created domain (except in dry-run mode)
84
124
  * .tlds moved to GandiV5::Domain::TLD.list
85
125
  * .tld(name) moved to GandiV5::Domain::TLD.fetch(name)
86
- * #renewal_price(currency: 'GBP', period: 1) added
126
+ * \#renewal_price(currency: 'GBP', period: 1) added
87
127
  * Enhancements to GandiV5::Email::Mailbox
88
128
  * .create now returns created mailbox
89
129
  * .create now checks for available slots and a valid type has been passed
@@ -92,14 +132,14 @@
92
132
  * Add #disable to disable the auto responder in Gandi
93
133
  * Enhancements to GandiV5::Email::Slot
94
134
  * .create now returns created slot
95
- * #delete now checks for inactiveness and refundableness
135
+ * \#delete now checks for inactiveness and refundableness
96
136
  * Enhancements to GandiV5::LiveDNS::Domain
97
137
  * Add #zone and #fetch_zone
98
- * Remove #replace_*_records_for methods
138
+ * Remove #replace_\*_records_for methods
99
139
  * Changes to #replace_records_for to allow calling with name, type, ttl and values. When calling with name and fecords records MUST be passed as an array.
100
140
  * Enhancements to GandiV5::LiveDNS::Zone
101
141
  * .create now returns created zone
102
- * Remove #replace_*_records_for methods
142
+ * Remove #replace_\*_records_for methods
103
143
  * Changes to #replace_records_for to allow calling with name, type, ttl and values. When calling with name and fecords records MUST be passed as an array.
104
144
  * Enhancements to GandiV5::LiveDNS::Zone::Snapshot
105
145
  * Add .list
data/README.md CHANGED
@@ -1,18 +1,21 @@
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=master)](http://travis-ci.org/robertgauld/gandi_v5)
3
- [![Coveralls Status](https://coveralls.io/repos/robertgauld/gandi_v5/badge.png?branch=master)](https://coveralls.io/r/robertgauld/gandi_v5)
4
- [![Code Climate](https://codeclimate.com/github/robertgauld/gandi_v5.png?branch=master)](https://codeclimate.com/github/robertgauld/gandi_v5)
5
- [![security](https://hakiri.io/github/robertgauld/gandi_v5/master.svg)](https://hakiri.io/github/robertgauld/gandi_v5/master)
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
+ [![Coveralls Status](https://coveralls.io/repos/robertgauld/gandi_v5/badge.png?branch=main)](https://coveralls.io/r/robertgauld/gandi_v5)
4
+ [![Code Climate](https://codeclimate.com/github/robertgauld/gandi_v5.png?branch=main)](https://codeclimate.com/github/robertgauld/gandi_v5)
6
5
 
7
6
  ## Ruby Versions
8
7
  This gem supports the following versions of ruby, it may work on other versions but is not tested against them so don't rely on it.
9
8
 
10
9
  * ruby:
11
- * 2.6.0 - 2.6.6
12
- * 2.7.0 - 2.7.1
13
- * truffleruby 20.1.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
10
+ * 2.6.0 - 2.6.7
11
+ * 2.7.0 - 2.7.3
12
+ * 3.0.0 - 3.0.1
13
+ * truffleruby 20.1.0 - 21.0.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
@@ -25,23 +28,24 @@ Gandi say: **_"Please note that this API is currently in BETA testing, so care s
25
28
 
26
29
  But then you were going to be careful anyway as this gem is currently in the version 0.something range weren't you!
27
30
 
28
- Details of the API can be found at:
31
+ Details of Gandi's API can be found at:
29
32
 
30
33
  * <https://api.gandi.net/docs/>
31
34
  * <https://doc.livedns.gandi.net/>
32
35
 
36
+ Details of the gem's API can be found at <https://rubydoc.info/github/robertgauld/gandi_v5/main>
33
37
 
34
38
  ## Installation
35
39
 
36
40
  If you're using bundler then add it to your Gemfile and run the bundle command.
37
41
 
38
42
  ```ruby
39
- gem 'gandi_v5', '~> 0.7'
43
+ gem 'gandi_v5', '~> 0.10'
40
44
  ```
41
45
 
42
46
  If you're not using bundler then install it from the command line.
43
47
  ```bash
44
- gem install gandi_v5 -v '~> 0.7'
48
+ gem install gandi_v5 -v '~> 0.10'
45
49
  ```
46
50
 
47
51
  ## Usage
@@ -58,6 +62,52 @@ GandiV5.api_key = '…' # Unless you've set it in the environment variable GANDI
58
62
 
59
63
  ### Examples
60
64
 
65
+ #### List renewal dates and costs for all domains
66
+ ```ruby
67
+ # For each domain (sorted by assending renewal date) print <date>\t<cost>\t<fqdn>
68
+ GandiV5::Domain.list.each do |domain|
69
+ puts [
70
+ domain.dates.registry_ends_at.to_date,
71
+ "£#{domain.renewal_price.price_after_taxes}",
72
+ domain.fqdn
73
+ ].join("\t")
74
+ end
75
+ ```
76
+
77
+ #### List email addresses for all domains
78
+
79
+ ```ruby
80
+ # For each domain:
81
+ # 1. Create an empty hash to store address => description
82
+ # 2. Get the mailboxes and add them to the hash
83
+ # 3. Get the forwards and add them to the hash
84
+ # 4. Sort the hash by email address
85
+ # 5. Print the list
86
+ GandiV5::Domain.list.each do |domain|
87
+ emails = {}
88
+
89
+ mailboxes = GandiV5::Email::Mailbox.list(domain.fqdn)
90
+ mailboxes.each do |mailbox|
91
+ mailbox.refresh
92
+ emails["#{mailbox.login}@#{domain.fqdn}"] = "#{mailbox.type} mailbox " \
93
+ "(#{mailbox.quota_usage.to_i}% " \
94
+ "of #{(mailbox.quota / 1024**3).round}GB used)"
95
+ mailbox.aliases.each do |alias_name|
96
+ emails["#{alias_name}@#{domain.fqdn}"] = "alias for #{mailbox.login}@#{domain.fqdn}"
97
+ end
98
+ end
99
+
100
+ forwards = GandiV5::Email::Forward.list(domain.fqdn)
101
+ forwards.each do |forward|
102
+ emails["#{forward.source}@#{domain.fqdn}"] = "forwards to #{forward.destinations.join(', ')}"
103
+ end
104
+
105
+ emails.sort.each do |address, text|
106
+ puts "#{address}\t#{text}"
107
+ end
108
+ end
109
+ ```
110
+
61
111
  #### Domains
62
112
 
63
113
  ```ruby
@@ -68,15 +118,14 @@ domains = GandiV5.domains
68
118
  domains.map!(&:refresh)
69
119
  ```
70
120
 
71
- TODO: More examples!
72
-
73
-
74
121
  ## Versioning
75
122
 
76
123
  We follow the [Semantic Versioning](http://semver.org/) concept.
77
124
 
78
125
  | Gem Version | Gandi API Release Date |
79
126
  | --------------- | ------------------------ |
127
+ | 0.10.0 | 2020-12-10 |
128
+ | 0.9.0 | 2020-07-29 |
80
129
  | 0.8.0 | 2020-07-10 |
81
130
  | 0.7.0 | 2020-05-07 |
82
131
  | 0.6.0 | 2020-05-07 (not LiveDNS) |
@@ -22,6 +22,7 @@ class GandiV5
22
22
  member :updated_at, converter: GandiV5::Data::Converter::Time
23
23
 
24
24
  # Check if current balance is below the warning threshold.
25
+ # @return [Boolean]
25
26
  def warning?
26
27
  return nil if warning_threshold.nil?
27
28
 
@@ -4,6 +4,7 @@ class GandiV5
4
4
  module Data
5
5
  class Converter
6
6
  # Used for applying the same converter to each item in an array.
7
+ # @api private
7
8
  class ArrayOf
8
9
  # @param converter the converter to apply to each item in the array.
9
10
  def initialize(converter)
@@ -18,8 +19,8 @@ class GandiV5
18
19
  value.map { |item| converter.to_gandi(item) }
19
20
  end
20
21
 
21
- # @param [Array<Object>]
22
- # @return value [Array<Object>]
22
+ # @param value [Array<Object>]
23
+ # @return [Array<Object>]
23
24
  def from_gandi(value)
24
25
  return nil if value.nil?
25
26
 
@@ -4,6 +4,7 @@ class GandiV5
4
4
  module Data
5
5
  class Converter
6
6
  # Methods for converting strings to/from integerss.
7
+ # @api private
7
8
  class Integer
8
9
  # @param value [Integer]
9
10
  # @return [String]
@@ -13,8 +14,8 @@ class GandiV5
13
14
  value.to_s
14
15
  end
15
16
 
16
- # @param [String]
17
- # @return value [Integer]
17
+ # @param value [String]
18
+ # @return [Integer]
18
19
  def self.from_gandi(value)
19
20
  return nil if value.nil?
20
21
 
@@ -4,6 +4,7 @@ class GandiV5
4
4
  module Data
5
5
  class Converter
6
6
  # Methods for converting strings to/from symbols.
7
+ # @api private
7
8
  class Symbol
8
9
  # @param value [Symbol]
9
10
  # @return [String]
@@ -13,8 +14,8 @@ class GandiV5
13
14
  value.to_s
14
15
  end
15
16
 
16
- # @param [String]
17
- # @return value [Symbol]
17
+ # @param value [String]
18
+ # @return [Symbol]
18
19
  def self.from_gandi(value)
19
20
  return nil if value.nil?
20
21
 
@@ -4,6 +4,7 @@ class GandiV5
4
4
  module Data
5
5
  class Converter
6
6
  # Methods for converting times to/from Gandi ("2019-02-13T11:04:18Z").
7
+ # @api private
7
8
  class Time
8
9
  # Convert a time to Gandi's prefered string format.
9
10
  # @param value [Time]
@@ -15,8 +16,8 @@ class GandiV5
15
16
  end
16
17
 
17
18
  # Convert a time from Gandi's prefered string format.
18
- # @param [String]
19
- # @return value [Time]
19
+ # @param value [String]
20
+ # @return [Time]
20
21
  def self.from_gandi(value)
21
22
  return nil if value.nil?
22
23
 
@@ -3,6 +3,7 @@
3
3
  class GandiV5
4
4
  module Data
5
5
  # Namespace for converters to/from Gandi's format.
6
+ # @api private
6
7
  class Converter
7
8
  # Initialize a new simple converter.
8
9
  # The passed procs will be run at the appropriate time.
@@ -21,8 +22,8 @@ class GandiV5
21
22
  to_gandi_proc.call value
22
23
  end
23
24
 
24
- # @param [Object]
25
- # @return value [Object]
25
+ # @param value [Object]
26
+ # @return [Object]
26
27
  def from_gandi(value)
27
28
  return value unless from_gandi_proc
28
29
 
data/lib/gandi_v5/data.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  class GandiV5
4
4
  # Addin providing a DSL to manage declaring attributes and how to map
5
5
  # and convert to/from Gandi's fields.
6
+ # @api private
6
7
  module Data
7
8
  # api private
8
9
  # Add contents of ClassMethods to the Class which includes this module.
@@ -21,19 +22,17 @@ class GandiV5
21
22
  # Get a hash representation of the object.
22
23
  # @return [Hash<Symbol => Object>]
23
24
  def to_h
24
- Hash[
25
- data_members.map do |key|
26
- value = send(key)
27
- next [key, value] if value.nil?
28
-
29
- if value.is_a?(Enumerable)
30
- value = to_h_transform_enumerable(value)
31
- elsif value.respond_to?(:to_h)
32
- value = value.to_h
33
- end
34
- [key, value]
25
+ data_members.map do |key|
26
+ value = send(key)
27
+ next [key, value] if value.nil?
28
+
29
+ if value.is_a?(Enumerable)
30
+ value = to_h_transform_enumerable(value)
31
+ elsif value.respond_to?(:to_h)
32
+ value = value.to_h
35
33
  end
36
- ]
34
+ [key, value]
35
+ end.to_h
37
36
  end
38
37
 
39
38
  # Get a hash representation of this object suitable for passing back to Gandi.
@@ -149,8 +148,8 @@ class GandiV5
149
148
  return nil if data.nil?
150
149
 
151
150
  new(
152
- translate_gandi(data).transform_keys(&:to_sym)
153
- .select { |k, _v| data_member?(k) }
151
+ **translate_gandi(data).transform_keys(&:to_sym)
152
+ .select { |k, _v| data_member?(k) }
154
153
  )
155
154
  end
156
155
 
@@ -4,7 +4,7 @@ class GandiV5
4
4
  class Domain
5
5
  class Availability
6
6
  class Product
7
- # Information about an available product.
7
+ # Information about an available product's period.
8
8
  # @!attribute [r] name
9
9
  # @return [String]
10
10
  # @!attribute [r]
@@ -4,15 +4,15 @@ class GandiV5
4
4
  class Domain
5
5
  # Information for a single contact for a domain.
6
6
  # @!attribute [r] country
7
- # @return [String] .
7
+ # @return [String]
8
8
  # @!attribute [r] email
9
- # @return [String] .
9
+ # @return [String]
10
10
  # @!attribute [r] family
11
- # @return [String] .
11
+ # @return [String]
12
12
  # @!attribute [r] given
13
- # @return [String] .
13
+ # @return [String]
14
14
  # @!attribute [r] address
15
- # @return [String] .
15
+ # @return [String]
16
16
  # @!attribute [r] type
17
17
  # @return [:person, :company, :association, :'public body', :reseller]
18
18
  # @!attribute [r] brand_number
@@ -12,7 +12,7 @@ class GandiV5
12
12
  # @!attribute [r] category
13
13
  # @return [String]
14
14
  # @!attribute [r] change_owner
15
- # @return [Boolean] whther changing owner is pemritted.
15
+ # @return [Boolean] whether changing owner is pemritted.
16
16
  # @!attribute [r] corporate
17
17
  # @return [Boolean] whether this is a corporate TLD.
18
18
  # @!attribute [r] ext_trade
@@ -27,7 +27,7 @@ class GandiV5
27
27
 
28
28
  # List of available TLDs.
29
29
  # @see https://api.gandi.net/docs/domains#get-v5-domain-tlds
30
- # @return Array<GandiV5::Domain::TLD>
30
+ # @return [Array<GandiV5::Domain::TLD>]
31
31
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
32
32
  def self.list
33
33
  GandiV5.get(url)
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ class GandiV5
4
+ class Domain
5
+ class TransferIn
6
+ # Information about the availabillity of a domain to be transfered into Gandi.
7
+ # @!attribute [r] fqdn
8
+ # @return [String] the fully qualified domain name.
9
+ # @!attribute [r] fqdn_unicode
10
+ # @return [String] the fully qualified domain name in unicode.
11
+ # @!attribute [r] available
12
+ # @return [Boolean] whether the domain can be transfered.
13
+ # @!attribute [r] corporate
14
+ # @return [Boolean] Optional
15
+ # @!attribute [r] internal
16
+ # @return [Boolean] Optional
17
+ # @!attribute [r] minimum_duration
18
+ # @return [Integer] Optional the minimum duration you can reregister the domain for.
19
+ # @!attribute [r] maximum_duration
20
+ # @return [Integer] Optional the maximum duration you can reregister the domain for.
21
+ # @!attribute [r] durations
22
+ # @return [Array<Integer>] Optional the durations you can reregister the domain for.
23
+ # @!attribute [r] message
24
+ # @return [String, nil] Optional message explaining why the domain can't be transfered.
25
+ class Availability
26
+ include GandiV5::Data
27
+
28
+ members :fqdn, :available, :corporate, :internal,
29
+ :minimum_duration, :maximum_duration
30
+ member :durations, array: true
31
+ member :message, gandi_key: 'msg'
32
+ member :fqdn_unicode, gandi_key: 'fqdn_ulabel'
33
+
34
+ # Find out if a domain can be transfered to Gandi.
35
+ # @see https://api.gandi.net/docs/domains/#post-v5-domain-transferin-domain-available
36
+ # @param fqdn [String, #to_s] the fully qualified domain name to query.
37
+ # @param auth_code [String, #to_s] authorization code (if required).
38
+ # @return [GandiV5::Domain::TransferIn::Availabillity]
39
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
40
+ def self.fetch(fqdn, auth_code = nil)
41
+ url = "#{BASE}domain/transferin/#{fqdn}/available"
42
+ body = {}
43
+ body['authinfo'] = auth_code if auth_code
44
+
45
+ _response, data = GandiV5.post url, body
46
+ from_gandi data
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,172 @@
1
+ # frozen_string_literal: true
2
+
3
+ class GandiV5
4
+ class Domain
5
+ # Manage a domain's transfer to Gandi.
6
+ # @!attribute [r] fqdn
7
+ # @return [String] the fully qualified domain name being transfered
8
+ # @!attribute [r] created_at
9
+ # @return [Time]
10
+ # @!attribute [r] updated_at
11
+ # @return [Time]
12
+ # @!attribute [r] owner_contact
13
+ # @return [String]
14
+ # @!attribute [r] step
15
+ # @return [String]
16
+ # @!attribute [r] step_number
17
+ # @return [Integer]
18
+ # @!attribute [r] errortype
19
+ # @return [String] (optional)
20
+ # @!attribute [r] errortype_label
21
+ # @return [String] (optional)
22
+ # @!attribute [r] duration
23
+ # @return [Integer] (optional)
24
+ # @!attribute [r] reseller_uuid
25
+ # @return [String] (optional)
26
+ # @!attribute [r] version
27
+ # @return [Integer] (optional)
28
+ # @!attribute [r] foa
29
+ # @return [Hash{String=>String}] (optional) email => status
30
+ # @!attribute [r] inner_step
31
+ # @return [String] (optional)
32
+ # @!attribute [r] transfer_procedure
33
+ # @return [String] (optional)
34
+ # @!attribute [r] start_at
35
+ # @return [Time] (optional)
36
+ # @!attribute [r] regac_at
37
+ # @return [Time] (optional)
38
+ class TransferIn
39
+ include GandiV5::Data
40
+
41
+ members :fqdn, :owner_contact, :step, :errortype, :errortype_label, :inner_step,
42
+ :transfer_procedure, :reseller_uuid, :version, :foa_status, :duration
43
+
44
+ member :step_number, gandi_key: 'step_nb'
45
+ member :created_at, converter: GandiV5::Data::Converter::Time
46
+ member :updated_at, converter: GandiV5::Data::Converter::Time
47
+ member :regac_at, converter: GandiV5::Data::Converter::Time
48
+ member :start_at, converter: GandiV5::Data::Converter::Time
49
+
50
+ # Relaunch the transfer process after something went wrong.
51
+ # @see https://api.gandi.net/docs/domains/#put-v5-domain-transferin-domain
52
+ # @return [String] the confirmation message from Gandi
53
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
54
+ def relaunch
55
+ TransferIn.relaunch fqdn
56
+ end
57
+
58
+ # Resend the {https://icannwiki.org/FOA Form Of Authorization} email.
59
+ # @see https://api.gandi.net/docs/domains/#post-v5-domain-transferin-domain-foa
60
+ # @return [String] the confirmation message from Gandi
61
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
62
+ def resend_foa_emails(email_address)
63
+ TransferIn.resend_foa_emails fqdn, email_address
64
+ end
65
+
66
+ # Start the transfer of a domain to Gandi.
67
+ # @note This is not a free operation. Please ensure your prepaid account has enough credit.
68
+ # @see https://api.gandi.net/docs/domains/#post-v5-domain-transferin
69
+ # @param fqdn [String, #to_s] the fully qualified domain name to create.
70
+ # @param dry_run [Boolean]
71
+ # whether the details should be checked instead of actually creating the domain.
72
+ # @param sharing_id [String] either:
73
+ # * nil (default) - nothing special happens
74
+ # * an organization ID - pay using another organization
75
+ # (you need to have billing permissions on the organization
76
+ # and use the same organization name for the domain name's owner).
77
+ # The invoice will be edited using this organization's information.
78
+ # * a reseller ID - buy a domain for a customer using a reseller account
79
+ # (you need to have billing permissions on the reseller organization
80
+ # and have your customer's information for the owner).
81
+ # The invoice will be edited using the reseller organization's information.
82
+ # @param owner [GandiV5::Domain::Contact, #to_gandi, #to_h] (required)
83
+ # the owner of the new domain.
84
+ # @param admin [GandiV5::Domain::Contact, #to_gandi, #to_h] (optional, defaults to owner)
85
+ # the administrative contact for the new domain.
86
+ # @param bill [GandiV5::Domain::Contact, #to_gandi, #to_h] (optional, defaults to owner)
87
+ # the billing contact for the new domain.
88
+ # @param tech [GandiV5::Domain::Contact, #to_gandi, #to_h] (optional, defaults to owner)
89
+ # the technical contact for the new domain.
90
+ # @param currency ["EUR", "USD", "GBP", "TWD", "CNY"] (optional)
91
+ # the currency you wish to be charged in.
92
+ # @param duration [Integer] (optional, default 1, minimum 1 maximum 10)
93
+ # how many years to register for.
94
+ # @param enforce_premium [Boolean] (optional)
95
+ # must be set to true if the domain is a premium domain.
96
+ # @param extra_parameters [Hash, #to_gandi, #to_json] (optional)
97
+ # unknown - not documented at Gandi.
98
+ # @param nameserver_ips [Hash<String => Array<String>>, #to_gandi, #to_json] (optional)
99
+ # For glue records only - dictionnary associating a nameserver to a list of IP addresses.
100
+ # @param nameservers [Array<String>, #to_gandi, #to_json] (optional)
101
+ # List of nameservers. Gandi's LiveDNS nameservers are used if omitted..
102
+ # @param price [Numeric, #to_gandi, #to_json] (optional) unknown - not documented at Gandi.
103
+ # @param resellee_id [String, #to_gandi, #to_json] (optional)
104
+ # unknown - not documented at Gandi.
105
+ # @param change_owner [Boolean] (optional)
106
+ # whether the change the domain's owner during the transfer.
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.
110
+ # @return [String] the confirmation message from Gandi
111
+ # @return [Hash] if doing a dry run, you get what Gandi returns
112
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error
113
+ def self.create(fqdn, dry_run: false, sharing_id: nil, **params)
114
+ fail ArgumentError, 'missing keyword: owner' unless params.key?(:owner)
115
+
116
+ body = params.merge(fqdn: fqdn)
117
+ .transform_values { |val| val.respond_to?(:to_gandi) ? val.to_gandi : val }
118
+ .to_json
119
+ url_ = sharing_id ? "#{url}?sharing_id=#{sharing_id}" : url
120
+
121
+ _response, data = GandiV5.post(url_, body, 'Dry-Run': dry_run ? 1 : 0)
122
+ dry_run ? data : data['message']
123
+ end
124
+
125
+ # Get information on an existing transfer.
126
+ # @see https://api.gandi.net/docs/domains/#get-v5-domain-transferin-domain
127
+ # @param fqdn [String, #to_s] the fully qualified domain name to check.
128
+ # @return [GandiV5::Domain::TransferIn]
129
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
130
+ def self.fetch(fqdn)
131
+ _response, data = GandiV5.get url(fqdn)
132
+ transfer = from_gandi data
133
+ transfer.instance_exec { @fqdn = data.dig('params', 'domain') }
134
+ transfer.instance_exec { @reseller_uuid = data.dig('params', 'reseller') }
135
+ transfer.instance_exec { @version = data.dig('params', 'version') }
136
+ transfer.instance_exec { @duration = data.dig('params', 'duration') }
137
+ if data.key?('foa')
138
+ transfer.instance_exec do
139
+ @foa_status = data['foa'].map { |hash| hash.values_at('email', 'answer') }.to_h
140
+ end
141
+ end
142
+ transfer
143
+ end
144
+
145
+ # Relaunch the transfer process after something went wrong.
146
+ # @see https://api.gandi.net/docs/domains/#put-v5-domain-transferin-domain
147
+ # @return [String] the confirmation message from Gandi
148
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
149
+ def self.relaunch(fqdn)
150
+ _response, data = GandiV5.put url(fqdn)
151
+ data['message']
152
+ end
153
+
154
+ # Resend the {https://icannwiki.org/FOA Form Of Authorization} email.
155
+ # @see https://api.gandi.net/docs/domains/#post-v5-domain-transferin-domain-foa
156
+ # @return [String] the confirmation message from Gandi
157
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
158
+ def self.resend_foa_emails(fqdn, email_address)
159
+ _response, data = GandiV5.post "#{url(fqdn)}/foa", { 'email' => email_address }.to_json
160
+ data['message']
161
+ end
162
+
163
+ private
164
+
165
+ def self.url(fqdn = nil)
166
+ "#{BASE}domain/transferin" +
167
+ (fqdn ? "/#{CGI.escape fqdn}" : '')
168
+ end
169
+ private_class_method :url
170
+ end
171
+ end
172
+ end