gandi_v5 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +24 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +20 -0
  5. data/.travis.yml +23 -0
  6. data/CHANGELOG.md +3 -0
  7. data/Gemfile +6 -0
  8. data/Guardfile +40 -0
  9. data/LICENSE.md +32 -0
  10. data/README.md +94 -0
  11. data/Rakefile +3 -0
  12. data/TODO.md +29 -0
  13. data/bin/console +13 -0
  14. data/gandi_v5.gemspec +41 -0
  15. data/lib/gandi_v5/billing/info/prepaid.rb +33 -0
  16. data/lib/gandi_v5/billing/info.rb +26 -0
  17. data/lib/gandi_v5/billing.rb +28 -0
  18. data/lib/gandi_v5/data/converter/array_of.rb +35 -0
  19. data/lib/gandi_v5/data/converter/symbol.rb +26 -0
  20. data/lib/gandi_v5/data/converter/time.rb +28 -0
  21. data/lib/gandi_v5/data/converter.rb +41 -0
  22. data/lib/gandi_v5/data.rb +244 -0
  23. data/lib/gandi_v5/domain/auto_renew.rb +64 -0
  24. data/lib/gandi_v5/domain/contact.rb +102 -0
  25. data/lib/gandi_v5/domain/contract.rb +22 -0
  26. data/lib/gandi_v5/domain/dates.rb +44 -0
  27. data/lib/gandi_v5/domain/renewal_information.rb +41 -0
  28. data/lib/gandi_v5/domain/restore_information.rb +18 -0
  29. data/lib/gandi_v5/domain/sharing_space.rb +21 -0
  30. data/lib/gandi_v5/domain.rb +431 -0
  31. data/lib/gandi_v5/email/mailbox/responder.rb +36 -0
  32. data/lib/gandi_v5/email/mailbox.rb +236 -0
  33. data/lib/gandi_v5/email/offer.rb +27 -0
  34. data/lib/gandi_v5/email/slot.rb +134 -0
  35. data/lib/gandi_v5/email.rb +11 -0
  36. data/lib/gandi_v5/error/gandi_error.rb +21 -0
  37. data/lib/gandi_v5/error.rb +9 -0
  38. data/lib/gandi_v5/live_dns/domain.rb +211 -0
  39. data/lib/gandi_v5/live_dns/record_set.rb +79 -0
  40. data/lib/gandi_v5/live_dns/zone/snapshot.rb +62 -0
  41. data/lib/gandi_v5/live_dns/zone.rb +301 -0
  42. data/lib/gandi_v5/live_dns.rb +30 -0
  43. data/lib/gandi_v5/organization.rb +66 -0
  44. data/lib/gandi_v5/version.rb +5 -0
  45. data/lib/gandi_v5.rb +178 -0
  46. data/spec/.rubocop.yml +4 -0
  47. data/spec/features/domain_spec.rb +45 -0
  48. data/spec/features/livedns_domain_spec.rb +8 -0
  49. data/spec/features/livedns_zone_spec.rb +45 -0
  50. data/spec/features/mailbox_spec.rb +18 -0
  51. data/spec/fixtures/bodies/GandiV5_Billing/info.yaml +10 -0
  52. data/spec/fixtures/bodies/GandiV5_Domain/availability.yaml +15 -0
  53. data/spec/fixtures/bodies/GandiV5_Domain/fetch_contacts.yaml +8 -0
  54. data/spec/fixtures/bodies/GandiV5_Domain/get.yaml +37 -0
  55. data/spec/fixtures/bodies/GandiV5_Domain/list.yaml +20 -0
  56. data/spec/fixtures/bodies/GandiV5_Domain/renewal_info.yaml +12 -0
  57. data/spec/fixtures/bodies/GandiV5_Domain/restore_info.yaml +5 -0
  58. data/spec/fixtures/bodies/GandiV5_Domain/tld.yaml +10 -0
  59. data/spec/fixtures/bodies/GandiV5_Domain/tlds.yaml +7 -0
  60. data/spec/fixtures/bodies/GandiV5_Email_Mailbox/get.yaml +16 -0
  61. data/spec/fixtures/bodies/GandiV5_Email_Mailbox/list.yaml +8 -0
  62. data/spec/fixtures/bodies/GandiV5_Email_Slot/get.yaml +10 -0
  63. data/spec/fixtures/bodies/GandiV5_Email_Slot/list.yaml +8 -0
  64. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/get.yaml +4 -0
  65. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/list.yaml +2 -0
  66. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/get.yaml +11 -0
  67. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/list.yaml +11 -0
  68. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone_Snapshot/get.yaml +9 -0
  69. data/spec/fixtures/bodies/GandiV5_Organization/get.yaml +17 -0
  70. data/spec/fixtures/vcr/Domain_features/List_domains.yml +54 -0
  71. data/spec/fixtures/vcr/Domain_features/Renew_domain.yml +133 -0
  72. data/spec/fixtures/vcr/LiveDNS_Domain_features/List_domains.yml +32 -0
  73. data/spec/fixtures/vcr/LiveDNS_Zone_features/List_zones.yml +42 -0
  74. data/spec/fixtures/vcr/LiveDNS_Zone_features/Make_and_save_snapshot.yml +72 -0
  75. data/spec/fixtures/vcr/LiveDNS_Zone_features/Save_zone_to_file.yml +28 -0
  76. data/spec/fixtures/vcr/Mailbox_features/List_mailboxes.yml +39 -0
  77. data/spec/spec_helper.rb +60 -0
  78. data/spec/test.env +1 -0
  79. data/spec/units/gandi_v5/billing/info/prepaid_spec.rb +20 -0
  80. data/spec/units/gandi_v5/billing/info_spec.rb +4 -0
  81. data/spec/units/gandi_v5/billing_spec.rb +41 -0
  82. data/spec/units/gandi_v5/data/converter/array_of_spec.rb +18 -0
  83. data/spec/units/gandi_v5/data/converter/symbol_spec.rb +16 -0
  84. data/spec/units/gandi_v5/data/converter/time_spec.rb +16 -0
  85. data/spec/units/gandi_v5/data/converter_spec.rb +31 -0
  86. data/spec/units/gandi_v5/data_spec.rb +340 -0
  87. data/spec/units/gandi_v5/domain/auto_renew_spec.rb +70 -0
  88. data/spec/units/gandi_v5/domain/contact_spec.rb +36 -0
  89. data/spec/units/gandi_v5/domain/contract_spec.rb +4 -0
  90. data/spec/units/gandi_v5/domain/dates_spec.rb +4 -0
  91. data/spec/units/gandi_v5/domain/renewal_information_spec.rb +81 -0
  92. data/spec/units/gandi_v5/domain/restore_information_spec.rb +4 -0
  93. data/spec/units/gandi_v5/domain/sharing_space_spec.rb +4 -0
  94. data/spec/units/gandi_v5/domain_spec.rb +451 -0
  95. data/spec/units/gandi_v5/email/mailbox/responder_spec.rb +131 -0
  96. data/spec/units/gandi_v5/email/mailbox_spec.rb +384 -0
  97. data/spec/units/gandi_v5/email/offer_spec.rb +17 -0
  98. data/spec/units/gandi_v5/email/slot_spec.rb +102 -0
  99. data/spec/units/gandi_v5/error/gandi_error_spec.rb +30 -0
  100. data/spec/units/gandi_v5/error_spec.rb +4 -0
  101. data/spec/units/gandi_v5/live_dns/domain_spec.rb +247 -0
  102. data/spec/units/gandi_v5/live_dns/record_set_spec.rb +74 -0
  103. data/spec/units/gandi_v5/live_dns/zone/snapshot_spec.rb +37 -0
  104. data/spec/units/gandi_v5/live_dns/zone_spec.rb +329 -0
  105. data/spec/units/gandi_v5/live_dns_spec.rb +17 -0
  106. data/spec/units/gandi_v5/organization_spec.rb +30 -0
  107. data/spec/units/gandi_v5_spec.rb +204 -0
  108. metadata +406 -0
@@ -0,0 +1,247 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::LiveDNS::Domain do
4
+ subject do
5
+ described_class.new fqdn: 'example.com', zone_uuid: 'zone-uuid'
6
+ end
7
+
8
+ describe '#refresh' do
9
+ before :each do
10
+ body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain', 'get.yaml'))
11
+ expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains/example.com')
12
+ .and_return(YAML.load_file(body_fixture))
13
+ subject.refresh
14
+ end
15
+
16
+ its('fqdn') { should eq 'example.com' }
17
+ its('zone_uuid') { should eq 'zone-uuid' }
18
+ end
19
+
20
+ describe '#fetch_records' do
21
+ it 'All of them' do
22
+ expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains/example.com/records')
23
+ .and_return([])
24
+
25
+ expect(subject.fetch_records).to eq []
26
+ end
27
+
28
+ it 'All for a name' do
29
+ expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains/example.com/records/name')
30
+ .and_return([])
31
+
32
+ expect(subject.fetch_records('name')).to eq []
33
+ end
34
+
35
+ it 'A type for a name' do
36
+ expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains/example.com/records/name/TXT')
37
+ .and_return(
38
+ [
39
+ {
40
+ 'rrset_type' => 'TXT',
41
+ 'rrset_name' => 'name',
42
+ 'rrset_ttl' => 600,
43
+ 'rrset_values' => %w[a b]
44
+ }
45
+ ]
46
+ )
47
+
48
+ records = subject.fetch_records('name', 'TXT')
49
+ expect(records.count).to eq 1
50
+ expect(records.first.type).to eq 'TXT'
51
+ expect(records.first.ttl).to eq 600
52
+ expect(records.first.name).to eq 'name'
53
+ expect(records.first.values).to match_array %w[a b]
54
+ end
55
+
56
+ it 'Invalid type' do
57
+ expect { subject.fetch_records 'name', 'INVALID-TYPE' }.to raise_error ArgumentError
58
+ end
59
+ end
60
+
61
+ describe '#fetch_zone_lines' do
62
+ it 'All of them' do
63
+ url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records'
64
+ expect(GandiV5).to receive(:get).with(url, accept: 'text/plain').and_return('returned')
65
+ expect(subject.fetch_zone_lines).to eq 'returned'
66
+ end
67
+
68
+ it 'All for a name' do
69
+ url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name'
70
+ expect(GandiV5).to receive(:get).with(url, accept: 'text/plain').and_return('returned')
71
+ expect(subject.fetch_zone_lines('name')).to eq 'returned'
72
+ end
73
+
74
+ it 'A type for a name' do
75
+ url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name/TXT'
76
+ expect(GandiV5).to receive(:get).with(url, accept: 'text/plain').and_return('returned')
77
+ expect(subject.fetch_zone_lines('name', 'TXT')).to eq 'returned'
78
+ end
79
+
80
+ it 'Invalid type' do
81
+ expect { subject.fetch_zone_lines 'name', 'INVALID-TYPE' }.to raise_error ArgumentError
82
+ end
83
+ end
84
+
85
+ describe '#add_record' do
86
+ it 'Success' do
87
+ url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records'
88
+ body = '{"rrset_name":"name","rrset_type":"TXT","rrset_ttl":900,"rrset_values":["a","b"]}'
89
+ expect(GandiV5).to receive(:post).with(url, body).and_return('message' => 'Confirmation message.')
90
+ expect(subject.add_record('name', 'TXT', 900, 'a', 'b')).to eq 'Confirmation message.'
91
+ end
92
+
93
+ it 'Bad type' do
94
+ expect { subject.add_record 'name', 'INVALID-TYPE', 900, 'a' }.to raise_error ArgumentError
95
+ end
96
+
97
+ it 'Bad TTL' do
98
+ expect { subject.add_record 'name', 'TXT', -900, 'a' }.to raise_error(
99
+ ArgumentError,
100
+ 'ttl must be positive and non-zero'
101
+ )
102
+ end
103
+
104
+ it 'No values' do
105
+ expect { subject.add_record 'name', 'TXT', 900 }.to raise_error(
106
+ ArgumentError,
107
+ 'there must be at least one value'
108
+ )
109
+ end
110
+ end
111
+
112
+ describe '#delete_records' do
113
+ it 'All of them' do
114
+ url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records'
115
+ expect(GandiV5).to receive(:delete).with(url)
116
+ subject.delete_records
117
+ end
118
+
119
+ it 'All for a name' do
120
+ url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name'
121
+ expect(GandiV5).to receive(:delete).with(url)
122
+ subject.delete_records 'name'
123
+ end
124
+
125
+ it 'A type for a name' do
126
+ url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name/TXT'
127
+ expect(GandiV5).to receive(:delete).with(url)
128
+ subject.delete_records 'name', 'TXT'
129
+ end
130
+
131
+ it 'Invalid type' do
132
+ expect { subject.delete_records 'name', 'INVALID-TYPE' }.to raise_error ArgumentError
133
+ end
134
+ end
135
+
136
+ describe '#replace_records' do
137
+ it 'Given array of GandiV5::LiveDNS::RecordSet' do
138
+ records = [
139
+ { name: 'name', ttl: 600, type: 'TXT', values: ['a'] }
140
+ ]
141
+
142
+ url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records'
143
+ body = '{"items":[{"rrset_name":"name","rrset_ttl":600,"rrset_type":"TXT","rrset_values":["a"]}]}'
144
+ expect(GandiV5).to receive(:put).with(url, body)
145
+ .and_return('message' => 'Confirmation message.')
146
+ expect(subject.replace_records(records: records)).to eq 'Confirmation message.'
147
+ end
148
+
149
+ it 'Given string' do
150
+ records = [
151
+ '@ 86400 IN A 192.168.0.1',
152
+ '* 86400 IN A 192.168.0.1'
153
+ ].join("\n")
154
+
155
+ url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records'
156
+ expect(GandiV5).to receive(:put).with(url, records, 'content-type': 'text/plain')
157
+ .and_return('message' => 'Confirmation message.')
158
+ expect(subject.replace_records(text: records)).to eq 'Confirmation message.'
159
+ end
160
+
161
+ it 'Given both' do
162
+ expect { subject.replace_records text: '', records: [] }.to raise_error(
163
+ ArgumentError,
164
+ 'you must pass ONE of records: or text:'
165
+ )
166
+ end
167
+
168
+ it 'Given nothing' do
169
+ expect { subject.replace_records }.to raise_error ArgumentError, 'you must pass ONE of records: or text:'
170
+ end
171
+ end
172
+
173
+ it '#replace_records_for' do
174
+ url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name'
175
+ body = '{"items":[{"rrset_type":"TXT","rrset_values":["a"]}]}'
176
+ expect(GandiV5).to receive(:put).with(url, body)
177
+ .and_return('message' => 'Confirmation message.')
178
+ records = { type: 'TXT', values: ['a'] }
179
+ expect(subject.replace_records_for('name', records)).to eq 'Confirmation message.'
180
+ end
181
+
182
+ describe '#replace_??_records_for' do
183
+ it '#replace_a_records_for' do
184
+ url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name/A'
185
+ body = '{"rrset_ttl":600,"rrset_values":["192.168.0.1","192.168.0.2"]}'
186
+ expect(GandiV5).to receive(:put).with(url, body)
187
+ .and_return('message' => 'Confirmation message.')
188
+ expect(subject.replace_a_records_for('name', 600, '192.168.0.1', '192.168.0.2')).to eq 'Confirmation message.'
189
+ end
190
+
191
+ it '#replace_txt_records_for' do
192
+ url = 'https://dns.api.gandi.net/api/v5/domains/example.com/records/name/TXT'
193
+ body = '{"rrset_ttl":600,"rrset_values":["a","b"]}'
194
+ expect(GandiV5).to receive(:put).with(url, body)
195
+ .and_return('message' => 'Confirmation message.')
196
+ expect(subject.replace_txt_records_for('name', 600, 'a', 'b')).to eq 'Confirmation message.'
197
+ end
198
+ end
199
+
200
+ describe '#change_zone' do
201
+ it 'Given a uuid' do
202
+ url = 'https://dns.api.gandi.net/api/v5/domains/example.com'
203
+ body = '{"zone_uuid":"zone-uuid"}'
204
+ expect(GandiV5).to receive(:patch).with(url, body)
205
+ .and_return('message' => 'Confirmation message.')
206
+ expect(subject.change_zone('zone-uuid')).to eq 'Confirmation message.'
207
+ expect(subject.zone_uuid).to eq 'zone-uuid'
208
+ end
209
+
210
+ it 'Given something with a uuid method' do
211
+ url = 'https://dns.api.gandi.net/api/v5/domains/example.com'
212
+ body = '{"zone_uuid":"zone-uuid"}'
213
+ expect(GandiV5).to receive(:patch).with(url, body)
214
+ .and_return('message' => 'Confirmation message.')
215
+ zone = double GandiV5::LiveDNS::Zone, uuid: 'zone-uuid'
216
+ expect(subject.change_zone(zone)).to eq 'Confirmation message.'
217
+ expect(subject.zone_uuid).to eq 'zone-uuid'
218
+ end
219
+ end
220
+
221
+ describe '.list' do
222
+ subject { described_class.list }
223
+
224
+ before :each do
225
+ body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain', 'list.yaml'))
226
+ expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains')
227
+ .and_return(YAML.load_file(body_fixture))
228
+ end
229
+
230
+ its('count') { should eq 1 }
231
+ its('first.fqdn') { should eq 'example.com' }
232
+ its('first.zone_uuid') { should be nil }
233
+ end
234
+
235
+ describe '.fetch' do
236
+ subject { described_class.fetch 'example.com' }
237
+
238
+ before :each do
239
+ body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Domain', 'get.yaml'))
240
+ expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/domains/example.com')
241
+ .and_return(YAML.load_file(body_fixture))
242
+ end
243
+
244
+ its('fqdn') { should eq 'example.com' }
245
+ its('zone_uuid') { should eq 'zone-uuid' }
246
+ end
247
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::LiveDNS::RecordSet do
4
+ subject do
5
+ described_class.new type: 'A', ttl: 900, name: 'www', values: %w[192.168.0.1 192.168.0.2]
6
+ end
7
+
8
+ it '#to_s' do
9
+ expect(subject.to_s).to eq "www\t900\tIN\tA\t192.168.0.1\n" \
10
+ "www\t900\tIN\tA\t192.168.0.2"
11
+ end
12
+
13
+ describe 'Record type helpers' do
14
+ it '#a?' do
15
+ expect(subject.a?).to be true
16
+ end
17
+
18
+ it '#aaaa?' do
19
+ expect(subject.aaaa?).to be false
20
+ end
21
+ end
22
+
23
+ describe 'TTL helpers' do
24
+ describe 'second?' do
25
+ it 'Default of 1' do
26
+ expect(subject.second?).to be false
27
+ end
28
+
29
+ it 'Passed value' do
30
+ expect(subject.seconds?(3)).to be false
31
+ end
32
+ end
33
+
34
+ describe 'minute?' do
35
+ it 'Default of 1' do
36
+ expect(subject.minute?).to be false
37
+ end
38
+
39
+ it 'Passed value' do
40
+ expect(subject.minutes?(3)).to be false
41
+ end
42
+ end
43
+
44
+ describe 'hour?' do
45
+ it 'Default of 1' do
46
+ expect(subject.hour?).to be false
47
+ end
48
+
49
+ it 'Passed value' do
50
+ expect(subject.hours?(3)).to be false
51
+ end
52
+ end
53
+
54
+ describe 'day?' do
55
+ it 'Default of 1' do
56
+ expect(subject.day?).to be false
57
+ end
58
+
59
+ it 'Passed value' do
60
+ expect(subject.days?(3)).to be false
61
+ end
62
+ end
63
+
64
+ describe 'week?' do
65
+ it 'Default of 1' do
66
+ expect(subject.week?).to be false
67
+ end
68
+
69
+ it 'Passed value' do
70
+ expect(subject.weeks?(3)).to be false
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe GandiV5::LiveDNS::Zone::Snapshot do
4
+ subject do
5
+ described_class.new(
6
+ created_at: Time.new(2016, 12, 16, 16, 51, 26, 0),
7
+ uuid: 'snapshot-uuid',
8
+ zone_uuid: 'zone-uuid',
9
+ records: []
10
+ )
11
+ end
12
+
13
+ it '#delete' do
14
+ expect(GandiV5).to receive(:delete).with('https://dns.api.gandi.net/api/v5/zones/zone-uuid/snapshots/snapshot-uuid')
15
+ .and_return('message' => 'Confirmation message.')
16
+ expect(subject.delete).to eq 'Confirmation message.'
17
+ end
18
+
19
+ describe '.fetch' do
20
+ subject { described_class.fetch 'zone-uuid', 'snapshot-uuid' }
21
+
22
+ before :each do
23
+ body_fixture = File.expand_path(File.join('spec', 'fixtures', 'bodies', 'GandiV5_LiveDNS_Zone_Snapshot', 'get.yaml'))
24
+ expect(GandiV5).to receive(:get).with('https://dns.api.gandi.net/api/v5/zones/zone-uuid/snapshots/snapshot-uuid')
25
+ .and_return(YAML.load_file(body_fixture))
26
+ end
27
+
28
+ its('created_at') { should eq Time.new(2016, 12, 16, 16, 51, 26, 0) }
29
+ its('uuid') { should eq 'snapshot-uuid' }
30
+ its('zone_uuid') { should eq 'zone-uuid' }
31
+ its('records.count') { should eq 1 }
32
+ its('records.first.type') { should eq 'A' }
33
+ its('records.first.ttl') { should eq 10_800 }
34
+ its('records.first.name') { should eq 'www' }
35
+ its('records.first.values') { should match_array ['10.0.1.42'] }
36
+ end
37
+ end