gandi_v5 0.6.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +81 -5
  3. data/README.md +65 -14
  4. data/lib/gandi_v5.rb +139 -70
  5. data/lib/gandi_v5/billing/info/prepaid.rb +1 -0
  6. data/lib/gandi_v5/data.rb +3 -2
  7. data/lib/gandi_v5/data/converter.rb +3 -2
  8. data/lib/gandi_v5/data/converter/array_of.rb +3 -2
  9. data/lib/gandi_v5/data/converter/integer.rb +3 -2
  10. data/lib/gandi_v5/data/converter/symbol.rb +3 -2
  11. data/lib/gandi_v5/data/converter/time.rb +3 -2
  12. data/lib/gandi_v5/domain.rb +55 -18
  13. data/lib/gandi_v5/domain/availability/product/period.rb +1 -1
  14. data/lib/gandi_v5/domain/contact.rb +5 -5
  15. data/lib/gandi_v5/domain/tld.rb +2 -2
  16. data/lib/gandi_v5/domain/transfer_in.rb +172 -0
  17. data/lib/gandi_v5/domain/transfer_in/availability.rb +51 -0
  18. data/lib/gandi_v5/domain/web_forwarding.rb +182 -0
  19. data/lib/gandi_v5/email.rb +3 -0
  20. data/lib/gandi_v5/email/forward.rb +3 -9
  21. data/lib/gandi_v5/email/mailbox.rb +5 -11
  22. data/lib/gandi_v5/error/gandi_error.rb +1 -0
  23. data/lib/gandi_v5/live_dns.rb +2 -12
  24. data/lib/gandi_v5/live_dns/domain.rb +340 -29
  25. data/lib/gandi_v5/live_dns/domain/dnssec_key.rb +120 -0
  26. data/lib/gandi_v5/live_dns/domain/record.rb +81 -0
  27. data/lib/gandi_v5/live_dns/domain/snapshot.rb +111 -0
  28. data/lib/gandi_v5/live_dns/domain/tsig_key.rb +74 -0
  29. data/lib/gandi_v5/sharing_space.rb +27 -0
  30. data/lib/gandi_v5/simple_hosting.rb +13 -0
  31. data/lib/gandi_v5/simple_hosting/instance.rb +251 -0
  32. data/lib/gandi_v5/simple_hosting/instance/application.rb +45 -0
  33. data/lib/gandi_v5/simple_hosting/instance/database.rb +20 -0
  34. data/lib/gandi_v5/simple_hosting/instance/language.rb +22 -0
  35. data/lib/gandi_v5/simple_hosting/instance/upgrade.rb +22 -0
  36. data/lib/gandi_v5/simple_hosting/instance/virtual_host.rb +272 -0
  37. data/lib/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone.rb +75 -0
  38. data/lib/gandi_v5/template.rb +271 -0
  39. data/lib/gandi_v5/template/dispatch.rb +109 -0
  40. data/lib/gandi_v5/template/payload.rb +64 -0
  41. data/lib/gandi_v5/template/payload/dns_record.rb +23 -0
  42. data/lib/gandi_v5/template/payload/web_forwarding.rb +82 -0
  43. data/lib/gandi_v5/version.rb +1 -1
  44. data/spec/.rubocop.yml +9 -9
  45. data/spec/features/list_domain_renewals_spec.rb +16 -0
  46. data/spec/features/list_email_addresses_spec.rb +39 -0
  47. data/spec/fixtures/bodies/GandiV5_Domain_TransferIn/fetch.yml +21 -0
  48. data/spec/fixtures/bodies/GandiV5_Domain_TransferIn_Availability/fetch.yml +10 -0
  49. data/spec/fixtures/bodies/GandiV5_Domain_WebForwarding/fetch.yml +9 -0
  50. data/spec/fixtures/bodies/GandiV5_Domain_WebForwarding/list.yml +9 -0
  51. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/fetch.yml +1 -2
  52. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/list_tsig.yml +3 -0
  53. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/nameservers.yml +3 -0
  54. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/fetch.yml +12 -0
  55. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/list.yml +9 -0
  56. data/spec/fixtures/bodies/{GandiV5_LiveDNS_Zone_Snapshot → GandiV5_LiveDNS_Domain_Snapshot}/fetch.yml +4 -3
  57. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_Snapshot/list.yml +5 -0
  58. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/fetch.yml +9 -0
  59. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/list.yml +4 -0
  60. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/fetch.yml +80 -0
  61. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/list.yml +38 -0
  62. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/fetch.yml +26 -0
  63. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/list.yml +18 -0
  64. data/spec/fixtures/bodies/GandiV5_Template/fetch.yml +41 -0
  65. data/spec/fixtures/bodies/GandiV5_Template/list.yml +20 -0
  66. data/spec/fixtures/bodies/GandiV5_Template_Dispatch/fetch.yml +49 -0
  67. data/spec/fixtures/vcr/Examples/List_domain_renewals.yml +54 -0
  68. data/spec/fixtures/vcr/Examples/List_email_addresses.yml +103 -0
  69. data/spec/spec_helper.rb +8 -7
  70. data/spec/units/gandi_v5/domain/transfer_in/availability_spec.rb +49 -0
  71. data/spec/units/gandi_v5/domain/transfer_in_spec.rb +143 -0
  72. data/spec/units/gandi_v5/domain/web_forwarding_spec.rb +150 -0
  73. data/spec/units/gandi_v5/domain_spec.rb +56 -37
  74. data/spec/units/gandi_v5/email/forward_spec.rb +5 -34
  75. data/spec/units/gandi_v5/email/mailbox_spec.rb +4 -34
  76. data/spec/units/gandi_v5/live_dns/domain/dnssec_key_spec.rb +128 -0
  77. data/spec/units/gandi_v5/live_dns/{record_set_spec.rb → domain/record_spec.rb} +1 -1
  78. data/spec/units/gandi_v5/live_dns/domain/snapshot_spec.rb +101 -0
  79. data/spec/units/gandi_v5/live_dns/domain/tsig_key_spec.rb +78 -0
  80. data/spec/units/gandi_v5/live_dns/domain_spec.rb +297 -118
  81. data/spec/units/gandi_v5/live_dns_spec.rb +0 -12
  82. data/spec/units/gandi_v5/simple_hosting/instance/application_spec.rb +37 -0
  83. data/spec/units/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone_spec.rb +50 -0
  84. data/spec/units/gandi_v5/simple_hosting/instance/virtual_host_spec.rb +324 -0
  85. data/spec/units/gandi_v5/simple_hosting/instance_spec.rb +190 -0
  86. data/spec/units/gandi_v5/simple_hosting_spec.rb +9 -0
  87. data/spec/units/gandi_v5/template/dispatch_spec.rb +70 -0
  88. data/spec/units/gandi_v5/template/payload/web_forwarding_spec.rb +44 -0
  89. data/spec/units/gandi_v5/template_spec.rb +341 -0
  90. data/spec/units/gandi_v5_spec.rb +111 -14
  91. metadata +226 -79
  92. data/.gitignore +0 -26
  93. data/.rspec +0 -3
  94. data/.rubocop.yml +0 -30
  95. data/.travis.yml +0 -38
  96. data/FUNDING.yml +0 -10
  97. data/Gemfile +0 -6
  98. data/Guardfile +0 -39
  99. data/Rakefile +0 -3
  100. data/bin/console +0 -13
  101. data/gandi_v5.gemspec +0 -42
  102. data/lib/gandi_v5/domain/sharing_space.rb +0 -29
  103. data/lib/gandi_v5/live_dns/has_zone_records.rb +0 -153
  104. data/lib/gandi_v5/live_dns/record_set.rb +0 -79
  105. data/lib/gandi_v5/live_dns/zone.rb +0 -160
  106. data/lib/gandi_v5/live_dns/zone/snapshot.rb +0 -81
  107. data/spec/features/domain_spec.rb +0 -45
  108. data/spec/features/livedns_domain_spec.rb +0 -8
  109. data/spec/features/livedns_zone_spec.rb +0 -44
  110. data/spec/features/mailbox_spec.rb +0 -18
  111. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/fetch.yml +0 -11
  112. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/list.yml +0 -11
  113. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone_Snapshot/list.yml +0 -3
  114. data/spec/fixtures/vcr/Domain_features/List_domains.yml +0 -55
  115. data/spec/fixtures/vcr/Domain_features/Renew_domain.yml +0 -133
  116. data/spec/fixtures/vcr/LiveDNS_Domain_features/List_domains.yml +0 -32
  117. data/spec/fixtures/vcr/LiveDNS_Zone_features/List_zones.yml +0 -42
  118. data/spec/fixtures/vcr/LiveDNS_Zone_features/Make_and_save_snapshot.yml +0 -72
  119. data/spec/fixtures/vcr/LiveDNS_Zone_features/Save_zone_to_file.yml +0 -28
  120. data/spec/fixtures/vcr/Mailbox_features/List_mailboxes.yml +0 -39
  121. data/spec/units/gandi_v5/billing/info_spec.rb +0 -4
  122. data/spec/units/gandi_v5/domain/availability/product/period_spec.rb +0 -4
  123. data/spec/units/gandi_v5/domain/availability/product/price_spec.rb +0 -4
  124. data/spec/units/gandi_v5/domain/availability/product_spec.rb +0 -4
  125. data/spec/units/gandi_v5/domain/availability/tax_spec.rb +0 -4
  126. data/spec/units/gandi_v5/domain/contract_spec.rb +0 -4
  127. data/spec/units/gandi_v5/domain/dates_spec.rb +0 -4
  128. data/spec/units/gandi_v5/domain/restore_information_spec.rb +0 -4
  129. data/spec/units/gandi_v5/domain/sharing_space_spec.rb +0 -4
  130. data/spec/units/gandi_v5/error_spec.rb +0 -4
  131. data/spec/units/gandi_v5/live_dns/zone/snapshot_spec.rb +0 -66
  132. data/spec/units/gandi_v5/live_dns/zone_spec.rb +0 -347
data/.gitignore DELETED
@@ -1,26 +0,0 @@
1
- # Because this is a gem, ignore Gemfile.lock:
2
-
3
- Gemfile.lock
4
-
5
- # And because this is Ruby, ignore the following
6
- # (source: https://github.com/github/gitignore/blob/master/Ruby.gitignore):
7
-
8
- .ruby-version
9
- notes.txt
10
- todo.txt
11
- *.gem
12
- *.rbc
13
- .bundle
14
- .config
15
- coverage
16
- InstalledFiles
17
- lib/bundler/man
18
- pkg
19
- rdoc
20
- doc
21
- spec/reports
22
- test/tmp
23
- test/version_tmp
24
- tmp
25
- gemfiles/*.lock
26
- .yardoc
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --color
2
- --format documentation
3
- --require spec_helper
@@ -1,30 +0,0 @@
1
- require:
2
- - rubocop-performance
3
- AllCops:
4
- TargetRubyVersion: 2.6.0
5
- Gemspec/RequiredRubyVersion:
6
- Enabled: false
7
- Metrics/AbcSize:
8
- Max: 20
9
- Metrics/ClassLength:
10
- Max: 250
11
- Metrics/CyclomaticComplexity:
12
- Max: 8
13
- Metrics/MethodLength:
14
- Max: 15
15
- Metrics/ModuleLength:
16
- Max: 200
17
- Metrics/ParameterLists:
18
- Max: 6
19
- Style/DocumentationMethod:
20
- Enabled: true
21
- Style/HashEachMethods:
22
- Enabled: true
23
- Style/HashTransformKeys:
24
- Enabled: true
25
- Style/HashTransformValues:
26
- Enabled: true
27
- Style/SignalException:
28
- Enabled: false
29
- Layout/LineLength:
30
- Max: 100
@@ -1,38 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.6.0
4
- - 2.6.1
5
- - 2.6.2
6
- - 2.6.3
7
- - 2.6.4
8
- - 2.6.5
9
- - 2.6.6
10
- - 2.7.0
11
- - 2.7.1
12
- - truffleruby-20.1.0
13
- gemfile:
14
- - Gemfile
15
- branches:
16
- only:
17
- - master
18
- - staging
19
- - /gh(?:\d)+(?:-.+)?/
20
- - /dev_ver_\d+\.\d+/
21
- env:
22
- global:
23
- # CC_TEST_REPORTER_ID for reporting test coverage to code climate
24
- - secure: "C3AcK+/2A4h2+ZayJXc89EQp76o8/2RL03PdtVjWPI6cfBSwN174ImWSdIcs6+Bjv8GH+bADsM4epkTjI7H24wh80If/4jAZJMB6LsAxVC3rZVx2UfDghp1Lwcy6BkNx4VVXMQJUR4rA8fXNd1l6n2a72RbPhTaGYxggw+yiKYNjj5m/u3HWPzTQ9wIx/rLzb2shQU1P9tDX4eRqJixYsd8LvStvXewUKlTQSaxNczzfcSOmeJrrytJGuPQxgBx67hlN40cs84oEbhndjlekZRwYepsRcan9umJEDHnE+k0wLlz/vb2cshYp5tdcfkqspaEhUSV7Vr7ZQNIppI3XyY1hs/pTYc2Vytp3OiY0EXBjKRmiHcnmA8EIkrV9i4OSt6Af3EQJaYU56a0BCaEqzRoQJWOZDS8bVowuO4rY8/xINQBwTojIYAplI/vqX/7xvlRbzIgeWdpvQipPC01d2JtmI/5D1FdGWtzYcDCTRTbHyWmjhr7Jt8qEDMFkbpkcAQiS61baEQ0p4CxaLYm/lpPco1U3e/gMOb/EXDhOrF1I8lSBmVJE/Uz2/3kfOa1DQSxDSRmV1nU3pSd7PUi25Pdx0rezJjRl1UC2gnsNZrCLbplk+VkImXTt3iirV/RuHDo+YVT0efaws7TVH7Uf87jqWf4VZEw/KI3tzfF43CE="
25
- before_install: gem update bundler
26
- before_script:
27
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter && chmod +x ./cc-test-reporter && ./cc-test-reporter before-build
28
- script:
29
- - if [[ $(echo $TRAVIS_JOB_NUMBER | awk -F . '{ print $2 }') == '1' ]]; then bundle exec rubocop; fi
30
- - bundle exec rspec
31
- after_script:
32
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
33
- notifications:
34
- slack:
35
- on_success: always
36
- on_failure: always
37
- rooms:
38
- - secure: Nx1TmVs32ILAvH3Cv+jX6rZh1hgx3YaY9azC3PIaJba/bF9xXY1l8L4wF0dJGupQlFP3lWN3Y/aPIJo3SNbH+qll9o317105FfTecPWloyiDgWvz5qPz+oh5MImBUs220jW2XsaACfZkGTUsQt8OUCfhtUeUiW+YqqfAZEwnl+0TyTSFBSLKSNdMcT0sKYPb0IuX5WrOspokSoE9+QL5k0cNN8d78MvtUIC6Em5/ffKVbk4TulQhbzyUhIlPDoxVELq16dQ7njyWJb58khOCaJGV7a2NdFvFCJqImFVQPRT5Ad6EJMQ461cdPY5+ZwxDGlIkA5Srt1L+CyV2wJtMarCIPoGQaxuOTVjNiedEmzblg3K9VXkI7Q5LupJ+vOBhtUS54ODYVBnQgoNVPuRe6T81VZ7NCejeest9bqga8QAVVNhKvMvb6l+YXabnPo7okDZM4+4AlaG/pBKWKjxDJ5QXlbRUZqnJt36sA7y3wvIxnYMX45oaqLD9OS8DQ7Va9+9bsPGZnI0oQrkoPGazGnCryvNtEdl+Qy2KSFaocJL7XLavmAYCmqnNGIaO0eiI+VoX9rvOadDNaPJoa6G4YpO+yTBlx1mxLjneY3FfCHZ1lma7UxzV0t0AVYZtnYBalXbw3mvIWEg6PPRI2uXGCvwUBrNCQqonULsRTFSseMw=
@@ -1,10 +0,0 @@
1
- github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
2
- patreon: robertgauld
3
- open_collective: # Replace with a single Open Collective username
4
- ko_fi: # Replace with a single Ko-fi username
5
- tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
6
- community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
7
- liberapay: # Replace with a single Liberapay username
8
- issuehunt: # Replace with a single IssueHunt username
9
- otechie: # Replace with a single Otechie username
10
- custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- # Specify your gem's dependencies in gandi_v5.gemspec
6
- gemspec
data/Guardfile DELETED
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- guard :bundler do
4
- watch(/^Gemfile(?:\.lock)$/)
5
- watch(/^.+\.gemspec$/)
6
- end
7
-
8
- # rubocop:disable Metrics/BlockLength
9
- group :red_green_refactor, halt_on_fail: true do
10
- group :rspec do
11
- guard(
12
- :rspec,
13
- all_on_start: true,
14
- all_after_pass: false,
15
- notification: :failed,
16
- cmd: 'bundle exec rspec'
17
- ) do
18
- watch(%r{^spec/.+_spec\.rb$})
19
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/units/#{m[1]}_spec.rb" }
20
- watch('spec/spec_helper.rb') { 'spec' }
21
- watch(%r{^spec/.+_shared\.rb$}) { 'spec' }
22
- end
23
- end
24
-
25
- group :rubocop do
26
- guard(
27
- :rubocop,
28
- all_on_start: true,
29
- all_after_pass: false,
30
- notification: :failed,
31
- keep_failed: false
32
- ) do
33
- watch(%r{^lib/(.+)\.rb$}) { |m| [m[0], "spec/units/#{m[1]}_spec.rb"] }
34
- watch(%r{^spec/.+?/(.+)_spec\.rb$}) { |m| [m[0], "lib/#{m[1]}.rb"] }
35
- watch(%r{^(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
36
- end
37
- end
38
- end
39
- # rubocop:enable Metrics/BlockLength
data/Rakefile DELETED
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- Dotenv.load
5
-
6
- unless ENV.key?('GANDI_API_KEY')
7
- puts 'YOU MUST SET YOUR API KEY -> GandiV5.api_key = \'…\''
8
- puts 'You can avoid having to do this by'
9
- puts 'setting the environment variable GANDI_API_KEY.'
10
- end
11
-
12
- require 'irb'
13
- IRB.start
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- $LOAD_PATH.push File.expand_path('lib', __dir__)
4
- require File.join(File.dirname(__FILE__), 'lib', 'gandi_v5', 'version')
5
-
6
- Gem::Specification.new do |gem|
7
- gem.name = 'gandi_v5'
8
- gem.license = 'BSD 3 clause'
9
- gem.version = GandiV5::VERSION
10
- gem.authors = ['Robert Gauld']
11
- gem.email = ['robert@robertgauld.co.uk']
12
- gem.homepage = 'https://github.com/robertgauld/gandi_v5'
13
- gem.summary = 'Make use of Gandi\'s V5 API.'
14
-
15
- gem.files = `git ls-files`.split("\n")
16
- gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
- gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
18
- gem.require_paths = ['lib']
19
-
20
- gem.required_ruby_version = '>= 2.4'
21
- gem.required_rubygems_version = '>= 2.6.14'
22
-
23
- gem.add_dependency 'dotenv', '~> 2.5'
24
- gem.add_dependency 'rest-client', '>= 2', '< 3'
25
- gem.add_dependency 'zeitwerk', '~> 2.1'
26
-
27
- gem.add_development_dependency 'coveralls', '~> 0.8'
28
- gem.add_development_dependency 'guard', '~> 2.15'
29
- gem.add_development_dependency 'guard-bundler', '~> 2.2'
30
- gem.add_development_dependency 'guard-rspec', '~> 4.2', '>= 4.2.5'
31
- gem.add_development_dependency 'guard-rubocop', '~> 1.3'
32
- gem.add_development_dependency 'rake', '~> 12.0'
33
- gem.add_development_dependency 'rb-inotify', '~> 0.9'
34
- gem.add_development_dependency 'rspec', '>= 3.7', '< 4'
35
- gem.add_development_dependency 'rspec-its', '~> 1.3'
36
- gem.add_development_dependency 'rubocop', '~> 0.73'
37
- gem.add_development_dependency 'rubocop-performance', '~> 1.1'
38
- gem.add_development_dependency 'simplecov', '~> 0.7'
39
- gem.add_development_dependency 'timecop', '~> 0.5'
40
- gem.add_development_dependency 'vcr', '~> 4.0'
41
- gem.add_development_dependency 'webmock', '~> 3.6'
42
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class GandiV5
4
- class Domain
5
- # Sharing space which contains a domain.
6
- # @!attribute [r] uuid
7
- # @return [String]
8
- # @!attribute [r] name
9
- # @return [String]
10
- # @!attribute [r] type
11
- # @return [String]
12
- # @!attribute [r] reseller
13
- # @return [nil, Boolean]
14
- # @!attribute [r] reseller_details
15
- # @return [nil, GandiV5::Domain::SharingSpace]
16
- class SharingSpace
17
- include GandiV5::Data
18
-
19
- members :name, :type, :reseller
20
- member :uuid, gandi_key: 'id'
21
- member(
22
- :reseller_details,
23
- gandi_key: 'sharing_space',
24
- converter: GandiV5::Domain::SharingSpace
25
- )
26
- alias sharing_space_uuid uuid
27
- end
28
- end
29
- end
@@ -1,153 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class GandiV5
4
- class LiveDNS
5
- # Methods for handling record related requests in both
6
- # GandiV5::LiveDNS::Domain and GandiV5::LiveDNS::Zone.
7
- module HasZoneRecords
8
- # @overload fetch_records()
9
- # Fetch all records for this domain.
10
- # @overload fetch_records(name)
11
- # Fetch records for a name.
12
- # @param name [String] the name to fetch records for.
13
- # @overload fetch_records(name, type)
14
- # Fetch records of a type for a name.
15
- # @param name [String] the name to fetch records for.
16
- # @param type [String] the record type to fetch.
17
- # @return [Array<GandiV5::LiveDNS::RecordSet>]
18
- # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
19
- def fetch_records(name = nil, type = nil)
20
- GandiV5::LiveDNS.require_valid_record_type type if type
21
-
22
- url_ = "#{url}/records"
23
- url_ += "/#{CGI.escape name}" if name
24
- url_ += "/#{CGI.escape type}" if type
25
-
26
- _response, data = GandiV5.get url_
27
- data = [data] unless data.is_a?(Array)
28
- data.map { |item| GandiV5::LiveDNS::RecordSet.from_gandi item }
29
- end
30
-
31
- # @overload fetch_zone_lines()
32
- # Fetch all records for this domain.
33
- # @overload fetch_zone_lines(name)
34
- # Fetch records for a name.
35
- # @param name [String] the name to fetch records for.
36
- # @overload fetch_zone_lines(name, type)
37
- # Fetch records of a type for a name.
38
- # @param name [String] the name to fetch records for.
39
- # @param type [String] the record type to fetch.
40
- # @return [String]
41
- # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
42
- def fetch_zone_lines(name = nil, type = nil)
43
- GandiV5::LiveDNS.require_valid_record_type type if type
44
-
45
- url_ = "#{url}/records"
46
- url_ += "/#{CGI.escape name}" if name
47
- url_ += "/#{CGI.escape type}" if type
48
-
49
- GandiV5.get(url_, accept: 'text/plain').last
50
- end
51
-
52
- # Add record to this domain.
53
- # @param name [String]
54
- # @param type [String]
55
- # @param ttl [Integer]
56
- # @param values [Array<String>]
57
- # @return [String] The confirmation message from Gandi.
58
- # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
59
- def add_record(name, type, ttl, *values)
60
- GandiV5::LiveDNS.require_valid_record_type type
61
- fail ArgumentError, 'ttl must be positive and non-zero' unless ttl.positive?
62
- fail ArgumentError, 'there must be at least one value' if values.none?
63
-
64
- body = {
65
- rrset_name: name,
66
- rrset_type: type,
67
- rrset_ttl: ttl,
68
- rrset_values: values
69
- }.to_json
70
- _response, data = GandiV5.post "#{url}/records", body
71
- data['message']
72
- end
73
-
74
- # @overload delete_records()
75
- # Delete all records for this domain.
76
- # @overload delete_records(name)
77
- # Delete records for a name.
78
- # @param name [String] the name to delete records for.
79
- # @overload delete_records(name, type)
80
- # Delete records of a type for a name.
81
- # @param name [String] the name to delete records for.
82
- # @param type [String] the record type to delete.
83
- # @return [nil]
84
- # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
85
- def delete_records(name = nil, type = nil)
86
- GandiV5::LiveDNS.require_valid_record_type(type) if type
87
-
88
- url_ = "#{url}/records"
89
- url_ += "/#{CGI.escape name}" if name
90
- url_ += "/#{CGI.escape type}" if type
91
- GandiV5.delete(url_).last
92
- end
93
-
94
- # Replace all records for this domain.
95
- # @param records
96
- # [Array<Hash<:name, :type => String, :ttl => Integer, :values => Array<String>>>]
97
- # the records to add.
98
- # @param text [String] zone file lines to replace the records with.
99
- # @return [String] The confirmation message from Gandi.
100
- # @raise [ArgumentError] if neither/both of records & test are passed.
101
- # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
102
- def replace_records(records: nil, text: nil)
103
- unless [records, text].count(&:nil?).eql?(1)
104
- fail ArgumentError, 'you must pass ONE of records: or text:'
105
- end
106
-
107
- if records
108
- body = {
109
- items: records.map { |r| r.transform_keys { |k| "rrset_#{k}" } }
110
- }.to_json
111
- _response, data = GandiV5.put "#{url}/records", body
112
- elsif text
113
- _response, data = GandiV5.put "#{url}/records", text, 'content-type': 'text/plain'
114
- end
115
- data['message']
116
- end
117
-
118
- # @override replace_records_for(name, records)
119
- # Replace records for a name in this domain.
120
- # @param name [String]
121
- # @param records
122
- # [Array<Hash<type: String, ttl: Integer, values: Array<String>>>]
123
- # the records to add.
124
- # @override replace_records_for(name, values, type: nil, ttl: nil)
125
- # Replace records for a name in this domain.
126
- # @param name [String]
127
- # @param type [String] the record type.
128
- # @param ttl [Integer] the TTL to set for the record.
129
- # @param values [Array<String>] the values to set for the record.
130
- # @raise [ArgumentError] if ttl is present and type is absent.
131
- # @return [String] The confirmation message from Gandi.
132
- # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
133
- def replace_records_for(name, records, type: nil, ttl: nil)
134
- fail ArgumentError, 'missing keyword: type' if ttl && type.nil?
135
-
136
- if type
137
- GandiV5::LiveDNS.require_valid_record_type type
138
- body = { rrset_values: records, rrset_ttl: ttl }
139
- # body[:rrset_ttl] = ttl if ttl
140
- _response, data = GandiV5.put "#{url}/records/#{name}/#{type}", body.to_json
141
-
142
- else
143
- body = {
144
- items: records.map { |r| r.transform_keys { |k| "rrset_#{k}" } }
145
- }
146
- _response, data = GandiV5.put "#{url}/records/#{name}", body.to_json
147
- end
148
-
149
- data['message']
150
- end
151
- end
152
- end
153
- end
@@ -1,79 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class GandiV5
4
- class LiveDNS
5
- # A record set which comes from either a domain or zone.
6
- # @!attribute [r] type
7
- # @return [String]
8
- # @!attribute [r] ttl
9
- # @return [Integer]
10
- # @!attribute [r] name
11
- # @return [String]
12
- # @!attribute [r] values
13
- # @return [Array<String>]
14
- class RecordSet
15
- include GandiV5::Data
16
-
17
- member :type, gandi_key: 'rrset_type'
18
- member :ttl, gandi_key: 'rrset_ttl', converter: GandiV5::Data::Converter::Integer
19
- member :name, gandi_key: 'rrset_name'
20
- member :values, gandi_key: 'rrset_values'
21
-
22
- # Generate zone file lines for the record.
23
- # @return [String]
24
- def to_s
25
- values.map do |value|
26
- "#{name}\t#{ttl}\tIN\t#{type}\t#{value}"
27
- end.join("\n")
28
- end
29
-
30
- GandiV5::LiveDNS::RECORD_TYPES.each do |t|
31
- # Check the record type.
32
- # @return [Boolean]
33
- define_method "#{t.downcase}?" do
34
- type.eql?(t)
35
- end
36
- end
37
-
38
- # Check the TTL's value in seconds.
39
- # @param number [Integer] the number of second(s) to check against.
40
- # @return [Boolean]
41
- def second?(number = 1)
42
- ttl == number
43
- end
44
- alias seconds? second?
45
-
46
- # Check the TTL's value in minutes.
47
- # @param number [Integer] the number of minute(s) to check against.
48
- # @return [Boolean]
49
- def minute?(number = 1)
50
- ttl == number * 60
51
- end
52
- alias minutes? minute?
53
-
54
- # Check the TTL's value in hours.
55
- # @param number [Integer] the number of hour(s) to check against.
56
- # @return [Boolean]
57
- def hour?(number = 1)
58
- ttl == number * 3_600
59
- end
60
- alias hours? hour?
61
-
62
- # Check the TTL's value in days.
63
- # @param number [Integer] the number of day(s) to check against.
64
- # @return [Boolean]
65
- def day?(number = 1)
66
- ttl == number * 86_400
67
- end
68
- alias days? day?
69
-
70
- # Check the TTL's value in weeks.
71
- # @param number [Integer] the number of week(s) to check against.
72
- # @return [Boolean]
73
- def week?(number = 1)
74
- ttl == number * 604_800
75
- end
76
- alias weeks? day?
77
- end
78
- end
79
- end