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
@@ -0,0 +1,18 @@
1
+ ---
2
+ - created_at: 2020-01-02T12:34:56+00
3
+ fqdn: vh.example.com
4
+ is_a_test_vhost: false
5
+ linked_dns_zone:
6
+ allow_alteration: true
7
+ last_checked_status: unknown
8
+ last_checked_at: 2020-02-03T23:45:56+00
9
+ status: running
10
+ application:
11
+ name: app-name
12
+ status: being_created
13
+ parameters: {}
14
+ certificates:
15
+ - href: example.com
16
+ id: cert-id
17
+ pending: true
18
+ https_strategy: redirect_HTTP_to_HTTPS
@@ -0,0 +1,41 @@
1
+ ---
2
+ description: description of template
3
+ editable: true
4
+ href: https://api.gandi.net/v5/template/templates/template-uuid
5
+ id: template-uuid
6
+ name: template name
7
+ namespaces:
8
+ - dns:record
9
+ - domain:mailboxes
10
+ - domain:nameservers
11
+ - domain:webredirs
12
+ orgname: org-name
13
+ sharing_space:
14
+ id: sharing-space-uuid
15
+ name: sharing-space-name
16
+ reseller: true
17
+ type: user
18
+ sharing_space:
19
+ id: reseller-uuid
20
+ name: reseller-name
21
+ variables: []
22
+ payload:
23
+ 'dns:records':
24
+ records:
25
+ - name: record-name
26
+ type: TXT
27
+ values: ['record-value']
28
+ ttl: 600
29
+ 'domain:mailboxes':
30
+ values:
31
+ - login: user-name
32
+ 'domain:nameservers':
33
+ addresses: ['1.1.1.1']
34
+ service: custom
35
+ 'domain:webredirs':
36
+ values:
37
+ - type: http301
38
+ url: https://example.com/here
39
+ host: here.example.com
40
+ override: true
41
+ protocol: https
@@ -0,0 +1,20 @@
1
+ ---
2
+ - description: description of template
3
+ editable: true
4
+ href: https://api.gandi.net/v5/template/templates/template-uuid
5
+ id: template-uuid
6
+ name: template name
7
+ namespaces:
8
+ - dns:record
9
+ - domain:mailboxes
10
+ - domain:nameservers
11
+ - domain:webredirs
12
+ orgname: org-name
13
+ sharing_space:
14
+ id: sharing-space-uuid
15
+ name: sharing-space-name
16
+ reseller: true
17
+ type: user
18
+ sharing_space:
19
+ id: reseller-uuid
20
+ name: reseller-name
@@ -0,0 +1,49 @@
1
+ ---
2
+ attempt: 1
3
+ created_at: '2020-11-29T14:57:14Z'
4
+ id: dispatch-uuid
5
+ sharing_id: sharing-uuid
6
+ state: 10
7
+ state_msg: state message
8
+ task_updated_at: '2020-11-29T14:57:15Z'
9
+ template_id: template-uuid
10
+ template_name: template
11
+ target:
12
+ name: domain-api-test1.net
13
+ type: domain
14
+ target_id: target-uuid
15
+ task_history:
16
+ - namespace: 'domain:nameservers'
17
+ date: '2020-11-29T16:57:47Z'
18
+ status: 20
19
+ message: ''
20
+ task_status:
21
+ 'dns:records':
22
+ status: 0
23
+ 'domain:mailboxes':
24
+ status: 10
25
+ 'domain:nameservers':
26
+ status: 20
27
+ 'domain:webredirs':
28
+ status: 30
29
+ payload:
30
+ 'dns:records':
31
+ default: false
32
+ records:
33
+ - name: record-name
34
+ type: TXT
35
+ values: ['record-value']
36
+ ttl: 600
37
+ 'domain:mailboxes':
38
+ values:
39
+ - login: user-name
40
+ 'domain:nameservers':
41
+ addresses: ['1.1.1.1']
42
+ service: custom
43
+ 'domain:webredirs':
44
+ values:
45
+ - type: http301
46
+ url: https://example.com/here
47
+ host: here.example.com
48
+ override: true
49
+ protocol: https
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.gandi.net/v5/domain/domains?page=1&per_page=100
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Authorization:
13
+ - Apikey abdce12345
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ Content-Length:
22
+ - '461'
23
+ body:
24
+ encoding: UTF-8
25
+ string: '[{"status":[],"dates":{"created_at":"2011-02-21T10:39:00Z","registry_created_at":"2003-03-12T12:02:11Z","registry_ends_at":"2021-03-12T12:02:11Z","updated_at":"2020-03-25T17:06:34Z"},"tags":[],"fqdn":"example.com","id":"domain-uuid","autorenew":false,"tld":"com","owner":"Mr. Example","orga_owner":"Example Org","domain_owner":"Owner","nameserver":{"current":"livedns"},"href":"https://api.gandi.net/v5/domain/domains/example.com","fqdn_unicode":"example.com"}]'
26
+ recorded_at: Mon, 17 Aug 2020 16:02:51 GMT
27
+
28
+ - request:
29
+ method: get
30
+ uri: https://api.gandi.net/v5/domain/check?currency=GBP&name=example.com&period=1&processes%5B%5D=renew
31
+ body:
32
+ encoding: US-ASCII
33
+ string: ''
34
+ headers:
35
+ Accept:
36
+ - application/json
37
+ Authorization:
38
+ - Apikey abcde12345
39
+ response:
40
+ status:
41
+ code: 200
42
+ message: OK
43
+ headers:
44
+ Content-Type:
45
+ - application/json; charset=utf-8
46
+ Content-Length:
47
+ - '353'
48
+ body:
49
+ encoding: UTF-8
50
+ string: '{"currency":"GBP","products":[{"name":"example.com","taxes":[{"rate":20,"name":"vat","type":"service"}],"process":"renew","prices":[{"min_duration":1,"discount":false,"price_after_taxes":8.87,"max_duration":9,"price_before_taxes":7.39,"duration_unit":"y"}],"status":"unavailable"}],"grid":"A","taxes":[{"rate":20,"name":"vat","type":"service"}]}'
51
+ http_version:
52
+ recorded_at: Mon, 17 Aug 2020 16:53:54 GMT
53
+
54
+ recorded_with: VCR 4.0.0
@@ -0,0 +1,103 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.gandi.net/v5/domain/domains?page=1&per_page=100
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Authorization:
13
+ - Apikey abdce12345
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ Content-Length:
22
+ - '461'
23
+ body:
24
+ encoding: UTF-8
25
+ string: '[{"status":[],"dates":{"created_at":"2011-02-21T10:39:00Z","registry_created_at":"2003-03-12T12:02:11Z","registry_ends_at":"2021-03-12T12:02:11Z","updated_at":"2020-03-25T17:06:34Z"},"tags":[],"fqdn":"example.com","id":"domain-uuid","autorenew":false,"tld":"com","owner":"Mr. Example","orga_owner":"Example Org","domain_owner":"Owner","nameserver":{"current":"livedns"},"href":"https://api.gandi.net/v5/domain/domains/example.com","fqdn_unicode":"example.com"}]'
26
+ recorded_at: Mon, 17 Aug 2020 16:02:51 GMT
27
+
28
+ - request:
29
+ method: get
30
+ uri: https://api.gandi.net/v5/email/mailboxes/example.com?page=1&per_page=100
31
+ body:
32
+ encoding: US-ASCII
33
+ string: ''
34
+ headers:
35
+ Accept:
36
+ - application/json
37
+ Authorization:
38
+ - Apikey abdce12345
39
+ response:
40
+ status:
41
+ code: 200
42
+ message: OK
43
+ headers:
44
+ Content-Type:
45
+ - application/json; charset=utf-8
46
+ Content-Length:
47
+ - '284'
48
+ body:
49
+ encoding: UTF-8
50
+ string: '[{"responder":{"message":"","enabled":false},"mailbox_type":"standard","login":"user","quota_used":3597,"domain":"example.com","aliases":["alias"],"address":"user@example.com","href":"https://api.gandi.net/v5/email/mailboxes/example.com/mailbox-uuid","id":"mailbox-uuid"}]'
51
+ recorded_at: Mon, 17 Aug 2020 16:02:51 GMT
52
+
53
+ - request:
54
+ method: get
55
+ uri: https://api.gandi.net/v5/email/mailboxes/example.com/mailbox-uuid
56
+ body:
57
+ encoding: US-ASCII
58
+ string: ''
59
+ headers:
60
+ Accept:
61
+ - application/json
62
+ Authorization:
63
+ - Apikey abdce12345
64
+ response:
65
+ status:
66
+ code: 200
67
+ message: OK
68
+ headers:
69
+ Content-Type:
70
+ - application/json; charset=utf-8
71
+ Content-Length:
72
+ - '270'
73
+ body:
74
+ encoding: UTF-8
75
+ string: '{"responder":{"message":"","enabled":false},"mailbox_type":"standard","login":"user","quota_used":3597,"domain":"example.com","aliases":["alias"],"address":"user@example.com","href":"https://api.gandi.net/v5/email/mailboxes/example.com/mailbox-uuid","id":"mailbox-uuid"}'
76
+ recorded_at: Mon, 17 Aug 2020 16:17:50 GMT
77
+
78
+ - request:
79
+ method: get
80
+ uri: https://api.gandi.net/v5/email/forwards/example.com?page=1&per_page=100
81
+ body:
82
+ encoding: US-ASCII
83
+ string: ''
84
+ headers:
85
+ Accept:
86
+ - application/json
87
+ Authorization:
88
+ - Apikey abdce12345
89
+ response:
90
+ status:
91
+ code: 200
92
+ message: OK
93
+ headers:
94
+ Content-Type:
95
+ - application/json; charset=utf-8
96
+ Content-Length:
97
+ - '127'
98
+ body:
99
+ encoding: UTF-8
100
+ string: '[{"destinations":["user@example.com"],"source":"forward","href":"https://api.gandi.net/v5/email/forwards/example.com/forward"}]'
101
+ recorded_at: Mon, 17 Aug 2020 16:02:52 GMT
102
+
103
+ recorded_with: VCR 4.0.0
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'dotenv'
4
- require 'coveralls'
5
4
  require 'rspec/its'
6
5
  require 'simplecov'
6
+ require 'simplecov-lcov'
7
7
  require 'timecop'
8
8
  require 'vcr'
9
9
  require 'webmock/rspec'
@@ -13,14 +13,15 @@ allow_http_connections_to = %w[localhost 127.0.0.1]
13
13
 
14
14
  Dotenv.load File.join(__dir__, 'test.env')
15
15
 
16
- SimpleCov.coverage_dir(File.join('tmp', 'coverage')) unless ENV.key?('TRAVIS')
16
+ if ENV.key?('GITHUB_ACTIONS')
17
+ SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
18
+ SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
19
+ else
20
+ SimpleCov.coverage_dir File.join('tmp', 'coverage')
21
+ end
17
22
  SimpleCov.start do
18
23
  add_filter 'spec/'
19
- end
20
-
21
- if ENV.key?('TRAVIS')
22
- Coveralls.wear!
23
- allow_http_connections_to.push 'coveralls.io'
24
+ add_filter '.github/'
24
25
  end
25
26
 
26
27
  RSpec.configure do |config|
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::Domain::TransferIn::Availability do
4
+ describe '.fetch' do
5
+ let(:body_fixture) do
6
+ File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Domain_TransferIn_Availability', 'fetch.yml'))
7
+ end
8
+
9
+ describe 'Without auth_code' do
10
+ subject { described_class.fetch 'example.com' }
11
+
12
+ before(:each) do
13
+ url = 'https://api.gandi.net/v5/domain/transferin/example.com/available'
14
+ expect(GandiV5).to receive(:post).with(url, {})
15
+ .and_return([nil, YAML.load_file(body_fixture)])
16
+ end
17
+
18
+ its('available') { should be true }
19
+ its('fqdn') { should eq 'example.com' }
20
+ its('fqdn_unicode') { should eq 'EXAMPLE.COM' }
21
+ its('corporate') { should be false }
22
+ its('internal') { should be false }
23
+ its('durations') { should eq [1, 2, 3] }
24
+ its('minimum_duration') { should eq 1 }
25
+ its('maximum_duration') { should eq 3 }
26
+ its('message') { should eq 'This is a message' }
27
+ end
28
+
29
+ describe 'With auth_code' do
30
+ subject { described_class.fetch 'example.com', 'auth-code' }
31
+
32
+ before(:each) do
33
+ url = 'https://api.gandi.net/v5/domain/transferin/example.com/available'
34
+ expect(GandiV5).to receive(:post).with(url, { 'authinfo' => 'auth-code' })
35
+ .and_return([nil, YAML.load_file(body_fixture)])
36
+ end
37
+
38
+ its('available') { should be true }
39
+ its('fqdn') { should eq 'example.com' }
40
+ its('fqdn_unicode') { should eq 'EXAMPLE.COM' }
41
+ its('corporate') { should be false }
42
+ its('internal') { should be false }
43
+ its('durations') { should eq [1, 2, 3] }
44
+ its('minimum_duration') { should eq 1 }
45
+ its('maximum_duration') { should eq 3 }
46
+ its('message') { should eq 'This is a message' }
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,143 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::Domain::TransferIn do
4
+ subject { described_class.new fqdn: 'example.com' }
5
+
6
+ describe '.fetch' do
7
+ subject { described_class.fetch 'example.com' }
8
+
9
+ before :each do
10
+ body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_Domain_TransferIn', 'fetch.yml'))
11
+ expect(GandiV5).to receive(:get).with('https://api.gandi.net/v5/domain/transferin/example.com')
12
+ .and_return([nil, YAML.load_file(body_fixture)])
13
+ end
14
+
15
+ its('fqdn') { should eq 'example.com' }
16
+ its('created_at') { should eq Time.new(2011, 2, 21, 10, 39, 0, 0) }
17
+ its('owner_contact') { should eq 'owner contact' }
18
+ its('duration') { should eq 1 }
19
+ its('reseller_uuid') { should eq 'reseller-uuid' }
20
+ its('version') { should eq 0 }
21
+ its('step') { should eq 'step text' }
22
+ its('step_number') { should eq 2 }
23
+ its('updated_at') { should eq Time.new(2011, 2, 22, 10, 39, 0, 0) }
24
+ its('errortype') { should eq 'error-type' }
25
+ its('errortype_label') { should eq 'error label' }
26
+ its('inner_step') { should eq 'inner-step' }
27
+ its('regac_at') { should eq Time.new(2011, 2, 23, 10, 39, 0, 0) }
28
+ its('start_at') { should eq Time.new(2011, 2, 24, 10, 39, 0, 0) }
29
+ its('transfer_procedure') { should eq 'transfer-procedure' }
30
+ its('foa_status') { should eq({ 'user@example.com' => 'ans' }) }
31
+ end
32
+
33
+ describe '.create' do
34
+ let(:url) { 'https://api.gandi.net/v5/domain/transferin' }
35
+
36
+ describe 'Sets dry-run header' do
37
+ let(:body) { '{"owner":{},"fqdn":"example.com"}' }
38
+
39
+ it 'False by default' do
40
+ expect(GandiV5).to receive(:post).with(url, body, 'Dry-Run': 0).and_return([nil, { 'message' => 'confirmation' }])
41
+ described_class.create 'example.com', owner: {}
42
+ end
43
+
44
+ it 'True' do
45
+ expect(GandiV5).to receive(:post).with(url, body, 'Dry-Run': 1).and_return([nil, nil])
46
+ described_class.create 'example.com', owner: {}, dry_run: true
47
+ end
48
+
49
+ it 'False' do
50
+ expect(GandiV5).to receive(:post).with(url, body, 'Dry-Run': 0).and_return([nil, { 'message' => 'confirmation' }])
51
+ described_class.create 'example.com', owner: {}, dry_run: false
52
+ end
53
+
54
+ it 'Dry run was successful' do
55
+ returns = { 'status' => 'success' }
56
+ expect(GandiV5).to receive(:post).with(url, body, 'Dry-Run': 1)
57
+ .and_return([nil, returns])
58
+ expect(described_class.create('example.com', owner: {}, dry_run: true)).to be returns
59
+ end
60
+
61
+ it 'Dry run has errors' do
62
+ returns = {
63
+ 'status' => 'error',
64
+ 'errors' => [{ 'description' => 'd', 'location' => 'l', 'name' => 'n' }]
65
+ }
66
+ expect(GandiV5).to receive(:post).with(url, body, 'Dry-Run': 1)
67
+ .and_return([nil, returns])
68
+ expect(described_class.create('example.com', owner: {}, dry_run: true)).to be returns
69
+ end
70
+ end
71
+
72
+ describe 'Sets sharing_id' do
73
+ it 'Absent by default' do
74
+ expect(GandiV5).to receive(:post).with(url, any_args).and_return([nil, { 'message' => 'confirmation' }])
75
+ described_class.create('example.com', owner: {})
76
+ end
77
+
78
+ it 'Paying as another organization' do
79
+ expect(GandiV5).to receive(:post).with("#{url}?sharing_id=organization_id", any_args)
80
+ .and_return([nil, { 'message' => 'confirmation' }])
81
+ described_class.create('example.com', sharing_id: 'organization_id', owner: {})
82
+ end
83
+
84
+ it 'Buy as a reseller' do
85
+ expect(GandiV5).to receive(:post).with("#{url}?sharing_id=reseller_id", any_args)
86
+ .and_return([nil, { 'message' => 'confirmation' }])
87
+ described_class.create('example.com', sharing_id: 'reseller_id', owner: {})
88
+ end
89
+ end
90
+
91
+ it 'Success' do
92
+ body = '{"owner":{},"fqdn":"example.com"}'
93
+ expect(GandiV5).to receive(:post).with(url, body, 'Dry-Run': 0)
94
+ .and_return([nil, { 'message' => 'confirmation' }])
95
+ expect(described_class.create('example.com', owner: {})).to eq 'confirmation'
96
+ end
97
+
98
+ it 'Errors on missing owner' do
99
+ expect { described_class.create 'example.com' }.to raise_error ArgumentError, 'missing keyword: owner'
100
+ end
101
+
102
+ it 'Given contact as hash' do
103
+ body = '{"owner":{"email":"owner@example.com"},"fqdn":"example.com"}'
104
+ expect(GandiV5).to receive(:post).with(url, body, 'Dry-Run': 0)
105
+ .and_return([nil, { 'message' => 'confirmation' }])
106
+ described_class.create 'example.com', owner: { email: 'owner@example.com' }
107
+ end
108
+
109
+ it 'Given contact as GandiV5::Domain::Contact' do
110
+ body = '{"owner":{"email":"owner@example.com"},"fqdn":"example.com"}'
111
+ expect(GandiV5).to receive(:post).with(url, body, 'Dry-Run': 0)
112
+ .and_return([nil, { 'message' => 'confirmation' }])
113
+ owner = double GandiV5::Domain::Contact, to_gandi: { 'email' => 'owner@example.com' }
114
+ described_class.create 'example.com', owner: owner
115
+ end
116
+ end
117
+
118
+ it '.relaunch' do
119
+ expect(GandiV5).to receive(:put).with('https://api.gandi.net/v5/domain/transferin/example.com')
120
+ .and_return([nil, { 'message' => 'confirmation' }])
121
+ expect(described_class.relaunch('example.com')).to eq 'confirmation'
122
+ end
123
+
124
+ it '.resend_foa_emails' do
125
+ url = 'https://api.gandi.net/v5/domain/transferin/example.com/foa'
126
+ body = '{"email":"user@example.com"}'
127
+ expect(GandiV5).to receive(:post).with(url, body)
128
+ .and_return([nil, { 'message' => 'confirmation' }])
129
+ expect(described_class.resend_foa_emails('example.com', 'user@example.com')).to eq 'confirmation'
130
+ end
131
+
132
+ it '#relaunch' do
133
+ returned = double String
134
+ expect(described_class).to receive(:relaunch).with('example.com').and_return(returned)
135
+ expect(subject.relaunch).to be returned
136
+ end
137
+
138
+ it '#resend_foa_emails' do
139
+ returned = double String
140
+ expect(described_class).to receive(:resend_foa_emails).with('example.com', 'user@example.com').and_return(returned)
141
+ expect(subject.resend_foa_emails('user@example.com')).to be returned
142
+ end
143
+ end