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,8 @@
1
+ module Dnsimple
2
+ class Client
3
+
4
+ class ClientService < ::Struct.new(:client)
5
+ end
6
+
7
+ end
8
+ end
@@ -0,0 +1,82 @@
1
+ module Dnsimple
2
+ class Client
3
+ class ContactsService < ClientService
4
+
5
+ # Lists the contacts in the account.
6
+ #
7
+ # @see http://developer.dnsimple.com/contacts/#list
8
+ #
9
+ # @return [Array<Struct::Contact>]
10
+ # @raise [RequestError] When the request fails.
11
+ def list
12
+ response = client.get("v1/contacts")
13
+
14
+ response.map { |r| Struct::Contact.new(r["contact"]) }
15
+ end
16
+
17
+ # Creates a contact in the account.
18
+ #
19
+ # @see http://developer.dnsimple.com/contacts/#create
20
+ #
21
+ # @param [Hash] attributes
22
+ #
23
+ # @return [Struct::Contact]
24
+ # @raise [RequestError] When the request fails.
25
+ def create(attributes = {})
26
+ Extra.validate_mandatory_attributes(attributes, [:first_name, :last_name, :address1, :city, :state_province, :postal_code, :country, :phone, :email_address])
27
+ options = { contact: attributes }
28
+ response = client.post("v1/contacts", options)
29
+
30
+ Struct::Contact.new(response["contact"])
31
+ end
32
+
33
+ # Gets a contact from the account.
34
+ #
35
+ # @see http://developer.dnsimple.com/contacts/#get
36
+ #
37
+ # @param [Fixnum] contact The contact id.
38
+ #
39
+ # @return [Struct::Contact]
40
+ # @raise [RecordNotFound]
41
+ # @raise [RequestError] When the request fails.
42
+ def find(contact)
43
+ response = client.get("v1/contacts/#{contact}")
44
+
45
+ Struct::Contact.new(response["contact"])
46
+ end
47
+
48
+ # Updates a contact in the account.
49
+ #
50
+ # @see http://developer.dnsimple.com/contacts/#update
51
+ #
52
+ # @param [Fixnum] contact The contact id.
53
+ # @param [Hash] attributes
54
+ #
55
+ # @return [Struct::Contact]
56
+ # @raise [RecordNotFound]
57
+ # @raise [RequestError] When the request fails.
58
+ def update(contact, attributes = {})
59
+ options = { contact: attributes }
60
+ response = client.put("v1/contacts/#{contact}", options)
61
+
62
+ Struct::Contact.new(response["contact"])
63
+ end
64
+
65
+ # Deletes a contact from the account.
66
+ #
67
+ # WARNING: this cannot be undone.
68
+ #
69
+ # @see http://developer.dnsimple.com/contacts/#delete
70
+ #
71
+ # @param [Fixnum] contact The contact id.
72
+ #
73
+ # @return [void]
74
+ # @raise [RecordNotFound]
75
+ # @raise [RequestError] When the request fails.
76
+ def delete(contact)
77
+ client.delete("v1/contacts/#{contact}")
78
+ end
79
+
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,333 @@
1
+ module Dnsimple
2
+ class Client
3
+ class DomainsService < ClientService
4
+
5
+ # Lists the domains in the account.
6
+ #
7
+ # @see http://developer.dnsimple.com/domains/#list
8
+ #
9
+ # @return [Array<Struct::Domain>]
10
+ # @raise [RequestError] When the request fails.
11
+ def list(options = {})
12
+ response = client.get("v1/domains", options)
13
+
14
+ response.map { |r| Struct::Domain.new(r["domain"]) }
15
+ end
16
+
17
+ # Gets a domain from the account.
18
+ #
19
+ # @see http://developer.dnsimple.com/domains/#get
20
+ #
21
+ # @param [#to_s] domain The domain id or domain name.
22
+ #
23
+ # @return [Struct::Domain]
24
+ # @raise [RecordNotFound]
25
+ # @raise [RequestError] When the request fails.
26
+ def find(domain)
27
+ response = client.get("v1/domains/#{domain}")
28
+
29
+ Struct::Domain.new(response["domain"])
30
+ end
31
+
32
+ # Creates a domain in the account.
33
+ #
34
+ # @see http://developer.dnsimple.com/domains/#create
35
+ #
36
+ # @param [Hash] attributes
37
+ #
38
+ # @return [Struct::Domain]
39
+ # @raise [RequestError] When the request fails.
40
+ def create(attributes = {})
41
+ Extra.validate_mandatory_attributes(attributes, [:name])
42
+ options = { domain: attributes }
43
+ response = client.post("v1/domains", options)
44
+
45
+ Struct::Domain.new(response["domain"])
46
+ end
47
+
48
+ # Deletes a domain from the account.
49
+ #
50
+ # WARNING: this cannot be undone.
51
+ #
52
+ # @see http://developer.dnsimple.com/domains/#delete
53
+ #
54
+ # @param [#to_s] domain The domain id or domain name.
55
+ #
56
+ # @return [void]
57
+ # @raise [RecordNotFound]
58
+ # @raise [RequestError] When the request fails.
59
+ def delete(domain)
60
+ client.delete("v1/domains/#{domain}")
61
+ end
62
+
63
+
64
+ # Lists the records for a domain.
65
+ #
66
+ # @see http://developer.dnsimple.com/domains/records/#list
67
+ #
68
+ # @param [#to_s] domain The domain id or domain name.
69
+ # @param [Hash] options
70
+ #
71
+ # @return [Array<Struct::Record>]
72
+ # @raise [RecordNotFound]
73
+ # @raise [RequestError] When the request fails.
74
+ def list_records(domain, options = {})
75
+ response = client.get("v1/domains/#{domain}/records", options)
76
+
77
+ response.map { |r| Struct::Record.new(r["record"]) }
78
+ end
79
+
80
+ # Creates a record for a domain.
81
+ #
82
+ # @see http://developer.dnsimple.com/domains/records/#create
83
+ #
84
+ # @param [#to_s] domain The domain id or domain name.
85
+ # @param [Hash] attributes
86
+ #
87
+ # @return [Struct::Record]
88
+ # @raise [RecordNotFound]
89
+ # @raise [RequestError] When the request fails.
90
+ def create_record(domain, attributes = {})
91
+ Extra.validate_mandatory_attributes(attributes, [:name, :record_type, :content])
92
+ options = { record: attributes }
93
+ response = client.post("v1/domains/#{domain}/records", options)
94
+
95
+ Struct::Record.new(response["record"])
96
+ end
97
+
98
+ # Gets a record for a domain.
99
+ #
100
+ # @see http://developer.dnsimple.com/domains/records/#get
101
+ #
102
+ # @param [#to_s] domain The domain id or domain name.
103
+ # @param [Fixnum] record The record id.
104
+ #
105
+ # @return [Struct::Record]
106
+ # @raise [RecordNotFound]
107
+ # @raise [RequestError] When the request fails.
108
+ def find_record(domain, record)
109
+ response = client.get("v1/domains/#{domain}/records/#{record}")
110
+
111
+ Struct::Record.new(response["record"])
112
+ end
113
+
114
+ # Updates a record for a domain.
115
+ #
116
+ # @see http://developer.dnsimple.com/domains/records/#update
117
+ #
118
+ # @param [#to_s] domain The domain id or domain name.
119
+ # @param [Fixnum] record The record id.
120
+ # @param [Hash] attributes
121
+ #
122
+ # @return [Struct::Record]
123
+ # @raise [RecordNotFound]
124
+ # @raise [RequestError] When the request fails.
125
+ def update_record(domain, record, attributes = {})
126
+ options = { record: attributes }
127
+ response = client.put("v1/domains/#{domain}/records/#{record}", options)
128
+
129
+ Struct::Record.new(response["record"])
130
+ end
131
+
132
+ # Deletes a record for a domain.
133
+ #
134
+ # @see http://developer.dnsimple.com/domains/records/#delete
135
+ #
136
+ # @param [#to_s] domain The domain id or domain name.
137
+ # @param [Fixnum] record The record id.
138
+ #
139
+ # @return [void]
140
+ # @raise [RecordNotFound]
141
+ # @raise [RequestError] When the request fails.
142
+ def delete_record(domain, record)
143
+ client.delete("v1/domains/#{domain}/records/#{record}")
144
+ end
145
+
146
+
147
+ # Enables auto-renewal for a domain.
148
+ #
149
+ # @see http://developer.dnsimple.com/domains/autorenewal/#enable
150
+ #
151
+ # @param [#to_s] domain The domain id or domain name.
152
+ #
153
+ # @return [Struct::Domain]
154
+ # @raise [RequestError] When the request fails.
155
+ def enable_auto_renewal(domain)
156
+ response = client.post("v1/domains/#{domain}/auto_renewal")
157
+
158
+ Struct::Domain.new(response["domain"])
159
+ end
160
+
161
+ # Disables auto-renewal for a domain.
162
+ #
163
+ # @see http://developer.dnsimple.com/domains/autorenewal/#disable
164
+ #
165
+ # @param [#to_s] domain The domain id or domain name.
166
+ #
167
+ # @return [Struct::Domain]
168
+ # @raise [RequestError] When the request fails.
169
+ def disable_auto_renewal(domain)
170
+ response = client.delete("v1/domains/#{domain}/auto_renewal")
171
+
172
+ Struct::Domain.new(response["domain"])
173
+ end
174
+
175
+
176
+ # Enables WHOIS privacy for a domain.
177
+ #
178
+ # @see http://developer.dnsimple.com/domains/privacy/#enable
179
+ #
180
+ # @param [#to_s] domain The domain id or domain name.
181
+ #
182
+ # @return [Struct::WhoisPrivacy]
183
+ # @raise [RequestError] When the request fails.
184
+ def enable_whois_privacy(domain)
185
+ response = client.post("v1/domains/#{domain}/whois_privacy")
186
+
187
+ Struct::WhoisPrivacy.new(response["whois_privacy"])
188
+ end
189
+
190
+ # Disables WHOIS privacy for a domain.
191
+ #
192
+ # @see http://developer.dnsimple.com/domains/privacy/#disable
193
+ #
194
+ # @param [#to_s] domain The domain id or domain name.
195
+ #
196
+ # @return [Struct::WhoisPrivacy]
197
+ # @raise [RequestError] When the request fails.
198
+ def disable_whois_privacy(domain)
199
+ response = client.delete("v1/domains/#{domain}/whois_privacy")
200
+
201
+ Struct::WhoisPrivacy.new(response["whois_privacy"])
202
+ end
203
+
204
+
205
+ # Lists the memberships.
206
+ #
207
+ # @see http://developer.dnsimple.com/domains/sharing/#list
208
+ #
209
+ # @param [#to_s] domain The domain id or domain name.
210
+ #
211
+ # @return [Array<Struct::Membership>]
212
+ # @raise [RecordNotFound]
213
+ # @raise [RequestError] When the request fails.
214
+ def list_memberships(domain)
215
+ response = client.get("v1/domains/#{domain}/memberships")
216
+
217
+ response.map { |r| Struct::Membership.new(r["membership"]) }
218
+ end
219
+
220
+ # Shares a domain.
221
+ #
222
+ # @see http://developer.dnsimple.com/domains/sharing/#create
223
+ #
224
+ # @param [#to_s] domain The domain id or domain name.
225
+ # @param [String] email
226
+ #
227
+ # @return [Struct::Membership]
228
+ # @raise [RecordNotFound]
229
+ # @raise [RequestError] When the request fails.
230
+ def create_membership(domain, email)
231
+ options = { membership: { email: email }}
232
+ response = client.post("v1/domains/#{domain}/memberships", options)
233
+
234
+ Struct::Membership.new(response["membership"])
235
+ end
236
+
237
+ # Un-shares a domain.
238
+ #
239
+ # @see http://developer.dnsimple.com/domains/sharing/#delete
240
+ #
241
+ # @param [#to_s] domain The domain id or domain name.
242
+ # @param [Fixnum] membership The membership id.
243
+ #
244
+ # @return [void]
245
+ # @raise [RecordNotFound]
246
+ # @raise [RequestError] When the request fails.
247
+ def delete_membership(domain, membership)
248
+ client.delete("v1/domains/#{domain}/memberships/#{membership}")
249
+ end
250
+
251
+
252
+ # Lists the email forwards for a domain.
253
+ #
254
+ # @see http://developer.dnsimple.com/domains/forwards/#list
255
+ #
256
+ # @param [#to_s] domain The domain id or domain name.
257
+ #
258
+ # @return [Array<Struct::EmailForward>]
259
+ # @raise [RecordNotFound]
260
+ # @raise [RequestError] When the request fails.
261
+ def list_email_forwards(domain)
262
+ response = client.get("v1/domains/#{domain}/email_forwards")
263
+
264
+ response.map { |r| Struct::EmailForward.new(r["email_forward"]) }
265
+ end
266
+
267
+ # Creates an email forward for a domain.
268
+ #
269
+ # @see http://developer.dnsimple.com/domains/forwards/#create
270
+ #
271
+ # @param [#to_s] domain The domain id or domain name.
272
+ # @param [Hash] attributes
273
+ #
274
+ # @return [Struct::EmailForward]
275
+ # @raise [RecordNotFound]
276
+ # @raise [RequestError] When the request fails.
277
+ def create_email_forward(domain, attributes = {})
278
+ Extra.validate_mandatory_attributes(attributes, [:from, :to])
279
+ options = { email_forward: attributes }
280
+ response = client.post("v1/domains/#{domain}/email_forwards", options)
281
+
282
+ Struct::EmailForward.new(response["email_forward"])
283
+ end
284
+
285
+ # Gets an email forward for a domain.
286
+ #
287
+ # @see http://developer.dnsimple.com/domains/forwards/#get
288
+ #
289
+ # @param [#to_s] domain The domain id or domain name.
290
+ # @param [Fixnum] forward The forward id.
291
+ #
292
+ # @return [Struct::EmailForward]
293
+ # @raise [RecordNotFound]
294
+ # @raise [RequestError] When the request fails.
295
+ def find_email_forward(domain, forward)
296
+ response = client.get("v1/domains/#{domain}/email_forwards/#{forward}")
297
+
298
+ Struct::EmailForward.new(response["email_forward"])
299
+ end
300
+
301
+ # Deletes an email forward for a domain.
302
+ #
303
+ # @see http://developer.dnsimple.com/domains/forwards/#delete
304
+ #
305
+ # @param [#to_s] domain The domain id or domain name.
306
+ # @param [Fixnum] forward The forward id.
307
+ #
308
+ # @return [void]
309
+ # @raise [RecordNotFound]
310
+ # @raise [RequestError] When the request fails.
311
+ def delete_email_forward(domain, forward)
312
+ client.delete("v1/domains/#{domain}/email_forwards/#{forward}")
313
+ end
314
+
315
+
316
+ # Gets a domain zone as zone file.
317
+ #
318
+ # @see http://developer.dnsimple.com/domains/zones/#get
319
+ #
320
+ # @param [#to_s] domain The domain id or domain name.
321
+ #
322
+ # @return [String]
323
+ # @raise [RecordNotFound]
324
+ # @raise [RequestError] When the request fails.
325
+ def zone(domain)
326
+ response = client.get("v1/domains/#{domain}/zone")
327
+
328
+ response["zone"]
329
+ end
330
+
331
+ end
332
+ end
333
+ end
@@ -0,0 +1,69 @@
1
+ module Dnsimple
2
+ class Client
3
+ class NameServersService < ClientService
4
+
5
+ # Lists the name servers for a domain.
6
+ #
7
+ # @see http://developer.dnsimple.com/domains/nameservers/#list
8
+ #
9
+ # @param [#to_s] domain The domain id or domain name.
10
+ #
11
+ # @return [Array<String>] The delegates name servers.
12
+ # @raise [RecordNotFound]
13
+ # @raise [RequestError] When the request fails.
14
+ def list(domain)
15
+ response = client.get("v1/domains/#{domain}/name_servers")
16
+
17
+ response.parsed_response
18
+ end
19
+
20
+ # Changes the name servers for a domain.
21
+ #
22
+ # @see http://developer.dnsimple.com/domains/nameservers/#change
23
+ #
24
+ # @param [#to_s] domain The domain id or domain name.
25
+ # @param [Array<String>] servers The name server list.
26
+ #
27
+ # @return [Array<String>] The delegates name servers.
28
+ # @raise [RecordNotFound]
29
+ # @raise [RequestError] When the request fails.
30
+ def change(domain, servers)
31
+ servers = servers.inject({}) { |hash, server| hash.merge("ns#{hash.length + 1}" => server) }
32
+ options = { name_servers: servers }
33
+ response = client.post("v1/domains/#{domain}/name_servers", options)
34
+
35
+ response.parsed_response
36
+ end
37
+
38
+
39
+ # Registers a name server at the registry.
40
+ #
41
+ # @see http://developer.dnsimple.com/nameservers/#register
42
+ #
43
+ # @param [#to_s] domain The domain id or domain name.
44
+ # @param [String] name The hostname to register.
45
+ # @param [String] ip The hostname IP address.
46
+ #
47
+ # @return [void]
48
+ # @raise [RequestError] When the request fails.
49
+ def register(domain, name, ip)
50
+ options = { name_server: { name: name, ip: ip } }
51
+ client.post("v1/domains/#{domain}/registry_name_servers", options)
52
+ end
53
+
54
+ # De-registers a name server at the registry.
55
+ #
56
+ # @see http://developer.dnsimple.com/nameservers/#deregister
57
+ #
58
+ # @param [#to_s] domain The domain id or domain name.
59
+ # @param [String] name The hostname to register.
60
+ #
61
+ # @return [void]
62
+ # @raise [RequestError] When the request fails.
63
+ def deregister(domain, name)
64
+ client.delete("v1/domains/#{domain}/registry_name_servers/#{name}")
65
+ end
66
+
67
+ end
68
+ end
69
+ end