dnsimple 2.0.0.alpha2 → 2.0.0.alpha3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.markdown +6 -2
  3. data/README.markdown +32 -30
  4. data/dnsimple.gemspec +1 -2
  5. data/lib/dnsimple.rb +2 -13
  6. data/lib/dnsimple/client.rb +164 -53
  7. data/lib/dnsimple/client/certificates_service.rb +98 -0
  8. data/lib/dnsimple/client/client_service.rb +8 -0
  9. data/lib/dnsimple/client/contacts_service.rb +82 -0
  10. data/lib/dnsimple/client/domains_service.rb +333 -0
  11. data/lib/dnsimple/client/name_servers_service.rb +69 -0
  12. data/lib/dnsimple/client/registrars_service.rb +105 -0
  13. data/lib/dnsimple/client/services_service.rb +95 -0
  14. data/lib/dnsimple/client/templates_service.rb +180 -0
  15. data/lib/dnsimple/client/users_service.rb +37 -0
  16. data/lib/dnsimple/compatibility.rb +46 -0
  17. data/lib/dnsimple/default.rb +86 -0
  18. data/lib/dnsimple/error.rb +7 -11
  19. data/lib/dnsimple/extra.rb +54 -0
  20. data/lib/dnsimple/struct.rb +29 -0
  21. data/lib/dnsimple/struct/certificate.rb +56 -0
  22. data/lib/dnsimple/struct/contact.rb +61 -0
  23. data/lib/dnsimple/struct/domain.rb +40 -0
  24. data/lib/dnsimple/struct/email_forward.rb +14 -0
  25. data/lib/dnsimple/struct/extended_attribute.rb +39 -0
  26. data/lib/dnsimple/struct/membership.rb +22 -0
  27. data/lib/dnsimple/struct/price.rb +16 -0
  28. data/lib/dnsimple/struct/record.rb +22 -0
  29. data/lib/dnsimple/struct/service.rb +19 -0
  30. data/lib/dnsimple/struct/template.rb +19 -0
  31. data/lib/dnsimple/struct/template_record.rb +24 -0
  32. data/lib/dnsimple/struct/transfer_order.rb +10 -0
  33. data/lib/dnsimple/struct/user.rb +17 -0
  34. data/lib/dnsimple/struct/whois_privacy.rb +19 -0
  35. data/lib/dnsimple/version.rb +1 -1
  36. data/spec/dnsimple/client/certificates_service_spec.rb +196 -0
  37. data/spec/dnsimple/client/contacts_service_spec.rb +179 -0
  38. data/spec/dnsimple/client/domains_service_spec.rb +662 -0
  39. data/spec/dnsimple/client/name_servers_service_spec.rb +131 -0
  40. data/spec/dnsimple/client/registrars_service_spec.rb +160 -0
  41. data/spec/dnsimple/client/services_service_spec.rb +162 -0
  42. data/spec/dnsimple/client/templates_service_spec.rb +371 -0
  43. data/spec/dnsimple/client/users_service_spec.rb +70 -0
  44. data/spec/dnsimple/client_spec.rb +108 -99
  45. data/spec/dnsimple/compatibility_spec.rb +57 -0
  46. data/spec/files/2fa/exchange-token.http +8 -11
  47. data/spec/files/badgateway.http +14 -0
  48. data/spec/files/certificates/configure/success.http +19 -0
  49. data/spec/files/certificates/index/success.http +1 -1
  50. data/spec/files/certificates/notfound.http +19 -0
  51. data/spec/files/certificates/purchase/success.http +19 -0
  52. data/spec/files/certificates/show/success.http +1 -1
  53. data/spec/files/certificates/submit/success.http +19 -0
  54. data/spec/files/contacts/create/badrequest-missingcontact.http +19 -0
  55. data/spec/files/contacts/create/badrequest-validationerror.http +19 -0
  56. data/spec/files/contacts/create/created.http +22 -0
  57. data/spec/files/contacts/delete/success-204.http +18 -0
  58. data/spec/files/{extended_attributes/com.http → contacts/delete/success.http} +5 -5
  59. data/spec/files/{domains/auto_renewal_enable → contacts/index}/success.http +6 -6
  60. data/spec/files/contacts/notfound.http +19 -0
  61. data/spec/files/contacts/update/success.http +21 -0
  62. data/spec/files/domains/create/created.http +21 -0
  63. data/spec/files/domains/index/success.http +11 -9
  64. data/spec/files/domains/notfound.http +11 -9
  65. data/spec/files/domains/show/success.http +12 -10
  66. data/spec/files/domains_autorenewal/disable/success.http +21 -0
  67. data/spec/files/domains_autorenewal/enable/success.http +21 -0
  68. data/spec/files/domains_autorenewal/notfound-domain.http +19 -0
  69. data/spec/files/domains_forwards/create/created.http +22 -0
  70. data/spec/files/domains_forwards/delete/success.http +17 -0
  71. data/spec/files/domains_forwards/get/success.http +21 -0
  72. data/spec/files/domains_forwards/list/success.http +21 -0
  73. data/spec/files/domains_forwards/notfound-domain.http +19 -0
  74. data/spec/files/domains_forwards/notfound.http +19 -0
  75. data/spec/files/domains_records/create/created.http +21 -0
  76. data/spec/files/domains_records/delete/success-204.http +18 -0
  77. data/spec/files/{contacts/show/notfound.http → domains_records/delete/success.http} +9 -7
  78. data/spec/files/{records → domains_records}/index/success.http +0 -0
  79. data/spec/files/{records/show → domains_records}/notfound.http +1 -1
  80. data/spec/files/{records → domains_records}/show/success.http +0 -0
  81. data/spec/files/domains_records/update/success.http +21 -0
  82. data/spec/files/domains_sharing/create/success.http +21 -0
  83. data/spec/files/domains_sharing/delete/success.http +17 -0
  84. data/spec/files/domains_sharing/list/success.http +21 -0
  85. data/spec/files/domains_sharing/notfound-domain.http +19 -0
  86. data/spec/files/domains_sharing/notfound.http +19 -0
  87. data/spec/files/domains_whois_privacy/disable/success.http +21 -0
  88. data/spec/files/domains_whois_privacy/enable/success.http +22 -0
  89. data/spec/files/domains_zones/get/success.http +21 -0
  90. data/spec/files/domains_zones/notfound-domain.http +19 -0
  91. data/spec/files/{domains/auto_renewal_disable/notfound.http → nameservers/change/success.http} +23 -21
  92. data/spec/files/nameservers/deregister/success.http +17 -0
  93. data/spec/files/{domains/auto_renewal_enable/notfound.http → nameservers/list/success.http} +23 -21
  94. data/spec/files/nameservers/notfound-domain.http +19 -0
  95. data/spec/files/nameservers/register/badrequest-valueerror.http +19 -0
  96. data/spec/files/nameservers/register/success.http +21 -0
  97. data/spec/files/registrars/check/available.http +19 -0
  98. data/spec/files/registrars/check/registered.http +21 -0
  99. data/spec/files/registrars/register/badrequest-missingdomain.http +19 -0
  100. data/spec/files/registrars/register/badrequest-missingregistrant.http +19 -0
  101. data/spec/files/registrars/register/success.http +21 -0
  102. data/spec/files/registrars/renew/badrequest-missingrenewal.http +19 -0
  103. data/spec/files/registrars/renew/badrequest-unable.http +19 -0
  104. data/spec/files/registrars/renew/success.http +21 -0
  105. data/spec/files/registrars/transfer/success.http +21 -0
  106. data/spec/files/registrars_extended_attributes/list/success.http +21 -0
  107. data/spec/files/registrars_prices/list/success.http +21 -0
  108. data/spec/files/services/applied/success.http +21 -0
  109. data/spec/files/services/apply/success.http +21 -0
  110. data/spec/files/services/available/success.http +21 -0
  111. data/spec/files/services/index/success.http +21 -0
  112. data/spec/files/services/notfound.http +19 -0
  113. data/spec/files/services/show/success.http +21 -0
  114. data/spec/files/services/unapply/success.http +21 -0
  115. data/spec/files/subscription/show/success.http +21 -0
  116. data/spec/files/templates/apply/success.http +21 -0
  117. data/spec/files/templates/create/created.http +22 -0
  118. data/spec/files/templates/delete/success-204.http +21 -0
  119. data/spec/files/templates/delete/success.http +21 -0
  120. data/spec/files/templates/index/success.http +21 -0
  121. data/spec/files/templates/notfound.http +19 -0
  122. data/spec/files/templates/show/success.http +12 -10
  123. data/spec/files/templates/update/success.http +21 -0
  124. data/spec/files/templates_records/create/created.http +22 -0
  125. data/spec/files/templates_records/delete/success-204.http +19 -0
  126. data/spec/files/templates_records/delete/success.http +21 -0
  127. data/spec/files/templates_records/index/success.http +21 -0
  128. data/spec/files/templates_records/notfound.http +19 -0
  129. data/spec/files/templates_records/show/success.http +21 -0
  130. data/spec/files/templates_records/update/success.http +21 -0
  131. data/spec/files/users/user/success.http +21 -0
  132. data/spec/spec_helper.rb +0 -2
  133. metadata +206 -73
  134. data/lib/dnsimple/base.rb +0 -10
  135. data/lib/dnsimple/certificate.rb +0 -143
  136. data/lib/dnsimple/contact.rb +0 -157
  137. data/lib/dnsimple/domain.rb +0 -252
  138. data/lib/dnsimple/extended_attribute.rb +0 -52
  139. data/lib/dnsimple/record.rb +0 -94
  140. data/lib/dnsimple/service.rb +0 -42
  141. data/lib/dnsimple/template.rb +0 -65
  142. data/lib/dnsimple/template_record.rb +0 -80
  143. data/lib/dnsimple/transfer_order.rb +0 -34
  144. data/lib/dnsimple/user.rb +0 -50
  145. data/spec/dnsimple/certificate_spec.rb +0 -59
  146. data/spec/dnsimple/contact_spec.rb +0 -45
  147. data/spec/dnsimple/domain_spec.rb +0 -241
  148. data/spec/dnsimple/extended_attributes_spec.rb +0 -54
  149. data/spec/dnsimple/record_spec.rb +0 -51
  150. data/spec/dnsimple/template_spec.rb +0 -31
  151. data/spec/dnsimple/user_spec.rb +0 -70
  152. data/spec/files/account/user/success.http +0 -19
  153. data/spec/files/certificates/show/notfound.http +0 -17
  154. data/spec/files/domains/auto_renewal_disable/success.http +0 -23
  155. data/spec/files/domains/create/success.http +0 -19
  156. data/spec/files/extended_attributes/ca.http +0 -19
  157. data/spec/files/extended_attributes/success.http +0 -19
  158. data/spec/files/templates/show/notfound.http +0 -17
@@ -0,0 +1,662 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dnsimple::Client, ".domains" do
4
+
5
+ subject { described_class.new(api_endpoint: "https://api.zone", username: "user", api_token: "token").domains }
6
+
7
+
8
+ describe "#list" do
9
+ before do
10
+ stub_request(:get, %r[/v1/domains$]).
11
+ to_return(read_fixture("domains/index/success.http"))
12
+ end
13
+
14
+ it "builds the correct request" do
15
+ subject.list
16
+
17
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains").
18
+ with(headers: { 'Accept' => 'application/json' })
19
+ end
20
+
21
+ it "returns the domains" do
22
+ results = subject.list
23
+
24
+ expect(results).to be_a(Array)
25
+ expect(results.size).to eq(2)
26
+
27
+ results.each do |result|
28
+ expect(result).to be_a(Dnsimple::Struct::Domain)
29
+ expect(result.id).to be_a(Fixnum)
30
+ end
31
+ end
32
+ end
33
+
34
+ describe "#create" do
35
+ before do
36
+ stub_request(:post, %r[/v1/domains]).
37
+ to_return(read_fixture("domains/create/created.http"))
38
+ end
39
+
40
+ let(:attributes) { { name: "example.com" } }
41
+
42
+ it "builds the correct request" do
43
+ subject.create(attributes)
44
+
45
+ expect(WebMock).to have_requested(:post, "https://api.zone/v1/domains").
46
+ with(body: { domain: attributes }).
47
+ with(headers: { 'Accept' => 'application/json' })
48
+ end
49
+
50
+ it "returns the domain" do
51
+ result = subject.create(attributes)
52
+
53
+ expect(result).to be_a(Dnsimple::Struct::Domain)
54
+ expect(result.id).to be_a(Fixnum)
55
+ end
56
+ end
57
+
58
+ describe "#find" do
59
+ before do
60
+ stub_request(:get, %r[/v1/domains/.+$]).
61
+ to_return(read_fixture("domains/show/success.http"))
62
+ end
63
+
64
+ it "builds the correct request" do
65
+ subject.find("example.com")
66
+
67
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com").
68
+ with(headers: { 'Accept' => 'application/json' })
69
+ end
70
+
71
+ it "returns the domain" do
72
+ result = subject.find("example.com")
73
+
74
+ expect(result).to be_a(Dnsimple::Struct::Domain)
75
+ expect(result.id).to eq(1)
76
+ expect(result.user_id).to eq(21)
77
+ expect(result.registrant_id).to eq(321)
78
+ expect(result.name).to eq("example.com")
79
+ expect(result.state).to eq("registered")
80
+ expect(result.auto_renew).to eq(true)
81
+ expect(result.whois_protected).to eq(false)
82
+ expect(result.expires_on).to eq("2015-09-27")
83
+ expect(result.created_at).to eq("2012-09-27T14:25:57.646Z")
84
+ expect(result.updated_at).to eq("2014-12-15T20:27:04.552Z")
85
+ end
86
+
87
+ context "when something does not exist" do
88
+ it "raises RecordNotFound" do
89
+ stub_request(:get, %r[/v1]).
90
+ to_return(read_fixture("domains/notfound.http"))
91
+
92
+ expect {
93
+ subject.find("example.com")
94
+ }.to raise_error(Dnsimple::RecordNotFound)
95
+ end
96
+ end
97
+ end
98
+
99
+ describe "#delete" do
100
+ before do
101
+ stub_request(:delete, %r[/v1/domains/.+$]).
102
+ to_return(read_fixture("domains/delete/success.http"))
103
+ end
104
+
105
+ it "builds the correct request" do
106
+ subject.delete("example.com")
107
+
108
+ expect(WebMock).to have_requested(:delete, "https://api.zone/v1/domains/example.com").
109
+ with(headers: { 'Accept' => 'application/json' })
110
+ end
111
+
112
+ it "returns nothing" do
113
+ result = subject.delete("example.com")
114
+
115
+ expect(result).to be_truthy
116
+ end
117
+
118
+ it "supports HTTP 204" do
119
+ stub_request(:delete, %r[/v1]).
120
+ to_return(read_fixture("domains/delete/success-204.http"))
121
+
122
+ result = subject.delete("example.com")
123
+
124
+ expect(result).to be_truthy
125
+ end
126
+
127
+ context "when something does not exist" do
128
+ it "raises RecordNotFound" do
129
+ stub_request(:delete, %r[/v1]).
130
+ to_return(read_fixture("domains/notfound.http"))
131
+
132
+ expect {
133
+ subject.delete("example.com")
134
+ }.to raise_error(Dnsimple::RecordNotFound)
135
+ end
136
+ end
137
+ end
138
+
139
+
140
+ describe "#list_records" do
141
+ before do
142
+ stub_request(:get, %r[/v1/domains/.+/records$]).
143
+ to_return(read_fixture("domains_records/index/success.http"))
144
+ end
145
+
146
+ it "builds the correct request" do
147
+ subject.list_records("example.com")
148
+
149
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com/records").
150
+ with(headers: { 'Accept' => 'application/json' })
151
+ end
152
+
153
+ it "returns the records" do
154
+ results = subject.list_records("example.com")
155
+
156
+ expect(results).to be_a(Array)
157
+ expect(results.size).to eq(7)
158
+
159
+ results.each do |result|
160
+ expect(result).to be_a(Dnsimple::Struct::Record)
161
+ expect(result.id).to be_a(Fixnum)
162
+ end
163
+ end
164
+
165
+ context "when something does not exist" do
166
+ it "raises RecordNotFound" do
167
+ stub_request(:get, %r[/v1]).
168
+ to_return(read_fixture("domains_records/notfound.http"))
169
+
170
+ expect {
171
+ subject.list_records("example.com")
172
+ }.to raise_error(Dnsimple::RecordNotFound)
173
+ end
174
+ end
175
+ end
176
+
177
+ describe "#create_record" do
178
+ before do
179
+ stub_request(:post, %r[/v1/domains/.+/records$]).
180
+ to_return(read_fixture("domains_records/create/created.http"))
181
+ end
182
+
183
+ it "builds the correct request" do
184
+ subject.create_record("example.com", { name: "", record_type: "A", content: "127.0.0.1", prio: "1" })
185
+
186
+ expect(WebMock).to have_requested(:post, "https://api.zone/v1/domains/example.com/records").
187
+ with(body: { record: { name: "", record_type: "A", content: "127.0.0.1", prio: "1" } }).
188
+ with(headers: { 'Accept' => 'application/json' })
189
+ end
190
+
191
+ it "returns the record" do
192
+ result = subject.create_record("example.com", { name: "", record_type: "", content: "" })
193
+
194
+ expect(result).to be_a(Dnsimple::Struct::Record)
195
+ expect(result.id).to be_a(Fixnum)
196
+ end
197
+
198
+ context "when something does not exist" do
199
+ it "raises RecordNotFound" do
200
+ stub_request(:post, %r[/v1]).
201
+ to_return(read_fixture("domains/notfound.http"))
202
+
203
+ expect {
204
+ subject.create_record("example.com", { name: "", record_type: "", content: "" })
205
+ }.to raise_error(Dnsimple::RecordNotFound)
206
+ end
207
+ end
208
+ end
209
+
210
+ describe "#find_record" do
211
+ before do
212
+ stub_request(:get, %r[/v1/domains/.+/records/.+$]).
213
+ to_return(read_fixture("domains_records/show/success.http"))
214
+ end
215
+
216
+ it "builds the correct request" do
217
+ subject.find_record("example.com", 2)
218
+
219
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com/records/2").
220
+ with(headers: { 'Accept' => 'application/json' })
221
+ end
222
+
223
+ it "returns the record" do
224
+ result = subject.find_record("example.com", 2)
225
+
226
+ expect(result).to be_a(Dnsimple::Struct::Record)
227
+ expect(result.id).to eq(1495)
228
+ expect(result.domain_id).to eq(6)
229
+ expect(result.name).to eq("www")
230
+ expect(result.content).to eq("1.2.3.4")
231
+ expect(result.ttl).to eq(3600)
232
+ expect(result.prio).to be_nil
233
+ expect(result.record_type).to eq("A")
234
+ expect(result.created_at).to eq("2014-01-14T18:25:56Z")
235
+ expect(result.updated_at).to eq("2014-01-14T18:26:04Z")
236
+ end
237
+
238
+ context "when something does not exist" do
239
+ it "raises RecordNotFound" do
240
+ stub_request(:get, %r[/v1]).
241
+ to_return(read_fixture("domains_records/notfound.http"))
242
+
243
+ expect {
244
+ subject.find_record("example.com", 2)
245
+ }.to raise_error(Dnsimple::RecordNotFound)
246
+ end
247
+ end
248
+ end
249
+
250
+ describe "#update_record" do
251
+ before do
252
+ stub_request(:put, %r[/v1/domains/.+/records/.+$]).
253
+ to_return(read_fixture("domains_records/update/success.http"))
254
+ end
255
+
256
+ it "builds the correct request" do
257
+ subject.update_record("example.com", 2, { content: "127.0.0.1", prio: "1" })
258
+
259
+ expect(WebMock).to have_requested(:put, "https://api.zone/v1/domains/example.com/records/2").
260
+ with(body: { record: { content: "127.0.0.1", prio: "1" } }).
261
+ with(headers: { 'Accept' => 'application/json' })
262
+ end
263
+
264
+ it "returns the record" do
265
+ result = subject.update_record("example.com", 2, {})
266
+
267
+ expect(result).to be_a(Dnsimple::Struct::Record)
268
+ expect(result.id).to be_a(Fixnum)
269
+ end
270
+
271
+ context "when something does not exist" do
272
+ it "raises RecordNotFound" do
273
+ stub_request(:put, %r[/v1]).
274
+ to_return(read_fixture("domains_records/notfound.http"))
275
+
276
+ expect {
277
+ subject.update_record("example.com", 2, {})
278
+ }.to raise_error(Dnsimple::RecordNotFound)
279
+ end
280
+ end
281
+ end
282
+
283
+ describe "#delete_record" do
284
+ before do
285
+ stub_request(:delete, %r[/v1/domains/.+/records/.+$]).
286
+ to_return(read_fixture("domains/delete/success.http"))
287
+ end
288
+
289
+ it "builds the correct request" do
290
+ subject.delete_record("example.com", 2)
291
+
292
+ expect(WebMock).to have_requested(:delete, "https://api.zone/v1/domains/example.com/records/2").
293
+ with(headers: { 'Accept' => 'application/json' })
294
+ end
295
+
296
+ it "returns nothing" do
297
+ result = subject.delete_record("example.com", 2)
298
+
299
+ expect(result).to be_truthy
300
+ end
301
+
302
+ it "supports HTTP 204" do
303
+ stub_request(:delete, %r[/v1]).
304
+ to_return(read_fixture("domains_records/delete/success-204.http"))
305
+
306
+ result = subject.delete_record("example.com", 2)
307
+
308
+ expect(result).to be_truthy
309
+ end
310
+
311
+ context "when something does not exist" do
312
+ it "raises RecordNotFound" do
313
+ stub_request(:delete, %r[/v1]).
314
+ to_return(read_fixture("domains_records/notfound.http"))
315
+
316
+ expect {
317
+ subject.delete_record("example.com", 2)
318
+ }.to raise_error(Dnsimple::RecordNotFound)
319
+ end
320
+ end
321
+ end
322
+
323
+
324
+ describe "#enable_auto_renewal" do
325
+ before do
326
+ stub_request(:post, %r[/v1/domains/.+/auto_renewal]).
327
+ to_return(read_fixture("domains_autorenewal/enable/success.http"))
328
+ end
329
+
330
+ it "builds the correct request" do
331
+ subject.enable_auto_renewal("example.com")
332
+
333
+ expect(WebMock).to have_requested(:post, "https://api.zone/v1/domains/example.com/auto_renewal").
334
+ with(headers: { 'Accept' => 'application/json' })
335
+ end
336
+
337
+ it "returns the domain" do
338
+ result = subject.enable_auto_renewal("example.com")
339
+
340
+ expect(result).to be_a(Dnsimple::Struct::Domain)
341
+ expect(result.id).to be_a(Fixnum)
342
+ end
343
+
344
+ context "when the domain does not exist" do
345
+ it "raises RecordNotFound" do
346
+ stub_request(:post, %r[/v1]).
347
+ to_return(read_fixture("domains_autorenewal/notfound-domain.http"))
348
+
349
+ expect {
350
+ subject.enable_auto_renewal("example.com")
351
+ }.to raise_error(Dnsimple::RecordNotFound)
352
+ end
353
+ end
354
+ end
355
+
356
+ describe "#disable_auto_renewal" do
357
+ before do
358
+ stub_request(:delete, %r[/v1/domains/.+/auto_renewal]).
359
+ to_return(read_fixture("domains_autorenewal/disable/success.http"))
360
+ end
361
+
362
+ it "builds the correct request" do
363
+ subject.disable_auto_renewal("example.com")
364
+
365
+ expect(WebMock).to have_requested(:delete, "https://api.zone/v1/domains/example.com/auto_renewal").
366
+ with(headers: { 'Accept' => 'application/json' })
367
+ end
368
+
369
+ it "returns the domain" do
370
+ result = subject.disable_auto_renewal("example.com")
371
+
372
+ expect(result).to be_a(Dnsimple::Struct::Domain)
373
+ expect(result.id).to be_a(Fixnum)
374
+ end
375
+
376
+ context "when the domain does not exist" do
377
+ it "raises RecordNotFound" do
378
+ stub_request(:delete, %r[/v1]).
379
+ to_return(read_fixture("domains_autorenewal/notfound-domain.http"))
380
+
381
+ expect {
382
+ subject.disable_auto_renewal("example.com")
383
+ }.to raise_error(Dnsimple::RecordNotFound)
384
+ end
385
+ end
386
+ end
387
+
388
+
389
+ describe "#list_memberships" do
390
+ before do
391
+ stub_request(:get, %r[/v1/domains/.+/memberships]).
392
+ to_return(read_fixture("domains_sharing/list/success.http"))
393
+ end
394
+
395
+ it "builds the correct request" do
396
+ subject.list_memberships("example.com")
397
+
398
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com/memberships").
399
+ with(headers: { 'Accept' => 'application/json' })
400
+ end
401
+
402
+ it "returns the records" do
403
+ results = subject.list_memberships("example.com")
404
+
405
+ expect(results).to be_a(Array)
406
+ expect(results.size).to eq(2)
407
+
408
+ results.each do |result|
409
+ expect(result).to be_a(Dnsimple::Struct::Membership)
410
+ expect(result.id).to be_a(Fixnum)
411
+ end
412
+ end
413
+
414
+ context "when the domain does not exist" do
415
+ it "raises RecordNotFound" do
416
+ stub_request(:get, %r[/v1]).
417
+ to_return(read_fixture("domains_sharing/notfound-domain.http"))
418
+
419
+ expect {
420
+ subject.list_memberships("example.com")
421
+ }.to raise_error(Dnsimple::RecordNotFound)
422
+ end
423
+ end
424
+ end
425
+
426
+ describe "#create_membership" do
427
+ before do
428
+ stub_request(:post, %r[/v1/domains/.+/memberships]).
429
+ to_return(read_fixture("domains_sharing/create/success.http"))
430
+ end
431
+
432
+ it "builds the correct request" do
433
+ subject.create_membership("example.com", "someone@example.com")
434
+
435
+ expect(WebMock).to have_requested(:post, "https://api.zone/v1/domains/example.com/memberships").
436
+ with(body: { membership: { email: "someone@example.com" } }).
437
+ with(headers: { 'Accept' => 'application/json' })
438
+ end
439
+
440
+ it "returns the record" do
441
+ result = subject.create_membership("example.com", "someone@example.com")
442
+
443
+ expect(result).to be_a(Dnsimple::Struct::Membership)
444
+ expect(result.id).to be_a(Fixnum)
445
+ end
446
+
447
+ context "when the domain does not exist" do
448
+ it "raises RecordNotFound" do
449
+ stub_request(:post, %r[/v1]).
450
+ to_return(read_fixture("domains_forwards/notfound-domain.http"))
451
+
452
+ expect {
453
+ subject.create_membership("example.com", "someone@example.com")
454
+ }.to raise_error(Dnsimple::RecordNotFound)
455
+ end
456
+ end
457
+ end
458
+
459
+ describe "#delete_membership" do
460
+ before do
461
+ stub_request(:delete, %r[/v1/domains/.+/memberships/.+$]).
462
+ to_return(read_fixture("domains_sharing/delete/success.http"))
463
+ end
464
+
465
+ it "builds the correct request" do
466
+ subject.delete_membership("example.com", 2)
467
+
468
+ expect(WebMock).to have_requested(:delete, "https://api.zone/v1/domains/example.com/memberships/2").
469
+ with(headers: { 'Accept' => 'application/json' })
470
+ end
471
+
472
+ it "returns nothing" do
473
+ result = subject.delete_membership("example.com", 2)
474
+
475
+ expect(result).to be_truthy
476
+ end
477
+
478
+ context "when the membership does not exist" do
479
+ it "raises RecordNotFound" do
480
+ stub_request(:delete, %r[/v1]).
481
+ to_return(read_fixture("domains_sharing/notfound.http"))
482
+
483
+ expect {
484
+ subject.delete_membership("example.com", 2)
485
+ }.to raise_error(Dnsimple::RecordNotFound)
486
+ end
487
+ end
488
+ end
489
+
490
+
491
+ describe "#list_email_forwards" do
492
+ before do
493
+ stub_request(:get, %r[/v1/domains/.+/email_forwards]).
494
+ to_return(read_fixture("domains_forwards/list/success.http"))
495
+ end
496
+
497
+ it "builds the correct request" do
498
+ subject.list_email_forwards("example.com")
499
+
500
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com/email_forwards").
501
+ with(headers: { 'Accept' => 'application/json' })
502
+ end
503
+
504
+ it "returns the records" do
505
+ results = subject.list_email_forwards("example.com")
506
+
507
+ expect(results).to be_a(Array)
508
+ expect(results.size).to eq(2)
509
+
510
+ results.each do |result|
511
+ expect(result).to be_a(Dnsimple::Struct::EmailForward)
512
+ expect(result.id).to be_a(Fixnum)
513
+ end
514
+ end
515
+
516
+ context "when the domain does not exist" do
517
+ it "raises RecordNotFound" do
518
+ stub_request(:get, %r[/v1]).
519
+ to_return(read_fixture("domains_forwards/notfound-domain.http"))
520
+
521
+ expect {
522
+ subject.list_email_forwards("example.com")
523
+ }.to raise_error(Dnsimple::RecordNotFound)
524
+ end
525
+ end
526
+ end
527
+
528
+ describe "#create_email_forward" do
529
+ before do
530
+ stub_request(:post, %r[/v1/domains/.+/email_forwards$]).
531
+ to_return(read_fixture("domains_forwards/create/created.http"))
532
+ end
533
+
534
+ it "builds the correct request" do
535
+ subject.create_email_forward("example.com", { from: "john", to: "someone@example.com" })
536
+
537
+ expect(WebMock).to have_requested(:post, "https://api.zone/v1/domains/example.com/email_forwards").
538
+ with(body: { email_forward: { from: "john", to: "someone@example.com" } }).
539
+ with(headers: { 'Accept' => 'application/json' })
540
+ end
541
+
542
+ it "returns the record" do
543
+ result = subject.create_email_forward("example.com", { from: "", to: "" })
544
+
545
+ expect(result).to be_a(Dnsimple::Struct::EmailForward)
546
+ expect(result.id).to be_a(Fixnum)
547
+ end
548
+
549
+ context "when the domain does not exist" do
550
+ it "raises RecordNotFound" do
551
+ stub_request(:post, %r[/v1]).
552
+ to_return(read_fixture("domains_forwards/notfound-domain.http"))
553
+
554
+ expect {
555
+ subject.create_email_forward("example.com", { from: "", to: "" })
556
+ }.to raise_error(Dnsimple::RecordNotFound)
557
+ end
558
+ end
559
+ end
560
+
561
+ describe "#find_email_forward" do
562
+ before do
563
+ stub_request(:get, %r[/v1/domains/.+/email_forwards/.+$]).
564
+ to_return(read_fixture("domains_forwards/get/success.http"))
565
+ end
566
+
567
+ it "builds the correct request" do
568
+ subject.find_email_forward("example.com", 2)
569
+
570
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com/email_forwards/2").
571
+ with(headers: { 'Accept' => 'application/json' })
572
+ end
573
+
574
+ it "returns the record" do
575
+ result = subject.find_email_forward("example.com", 2)
576
+
577
+ expect(result).to be_a(Dnsimple::Struct::EmailForward)
578
+ expect(result.id).to eq(1)
579
+ expect(result.domain_id).to eq(1111)
580
+ expect(result.from).to eq("sender@dnsimple-sandbox.com")
581
+ expect(result.to).to eq("receiver@example.com")
582
+ expect(result.created_at).to eq("2014-12-16T12:55:13.697Z")
583
+ expect(result.updated_at).to eq("2014-12-16T12:55:13.697Z")
584
+ end
585
+
586
+ context "when forward does not exist" do
587
+ it "raises RecordNotFound" do
588
+ stub_request(:get, %r[/v1]).
589
+ to_return(read_fixture("domains_forwards/notfound.http"))
590
+
591
+ expect {
592
+ subject.find_email_forward("example.com", 2)
593
+ }.to raise_error(Dnsimple::RecordNotFound)
594
+ end
595
+ end
596
+ end
597
+
598
+ describe "#delete_email_forward" do
599
+ before do
600
+ stub_request(:delete, %r[/v1/domains/.+/email_forwards/.+$]).
601
+ to_return(read_fixture("domains_forwards/delete/success.http"))
602
+ end
603
+
604
+ it "builds the correct request" do
605
+ subject.delete_email_forward("example.com", 2)
606
+
607
+ expect(WebMock).to have_requested(:delete, "https://api.zone/v1/domains/example.com/email_forwards/2").
608
+ with(headers: { 'Accept' => 'application/json' })
609
+ end
610
+
611
+ it "returns nothing" do
612
+ result = subject.delete_email_forward("example.com", 2)
613
+
614
+ expect(result).to be_truthy
615
+ end
616
+
617
+ context "when the forward does not exist" do
618
+ it "raises RecordNotFound" do
619
+ stub_request(:delete, %r[/v1]).
620
+ to_return(read_fixture("domains_forwards/notfound.http"))
621
+
622
+ expect {
623
+ subject.delete_email_forward("example.com", 2)
624
+ }.to raise_error(Dnsimple::RecordNotFound)
625
+ end
626
+ end
627
+ end
628
+
629
+
630
+ describe "#zone" do
631
+ before do
632
+ stub_request(:get, %r[/v1/domains/.+/zone$]).
633
+ to_return(read_fixture("domains_zones/get/success.http"))
634
+ end
635
+
636
+ it "builds the correct request" do
637
+ subject.zone("example.com")
638
+
639
+ expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com/zone").
640
+ with(headers: { 'Accept' => 'application/json' })
641
+ end
642
+
643
+ it "returns the record" do
644
+ result = subject.zone("example.com")
645
+
646
+ expect(result).to be_a(String)
647
+ expect(result).to match(/^#{Regexp.escape("$ORIGIN")}/)
648
+ end
649
+
650
+ context "when domain does not exist" do
651
+ it "raises RecordNotFound" do
652
+ stub_request(:get, %r[/v1]).
653
+ to_return(read_fixture("domains_zones/notfound-domain.http"))
654
+
655
+ expect {
656
+ subject.zone("example.com")
657
+ }.to raise_error(Dnsimple::RecordNotFound)
658
+ end
659
+ end
660
+ end
661
+
662
+ end