dnsimple 2.2.0 → 3.0.0.pre.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (244) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +3 -1
  4. data/CHANGELOG.md +13 -2
  5. data/CONTRIBUTING.md +35 -0
  6. data/Gemfile +2 -0
  7. data/LICENSE.txt +1 -1
  8. data/README.md +30 -82
  9. data/dnsimple.gemspec +2 -1
  10. data/lib/dnsimple.rb +0 -2
  11. data/lib/dnsimple/client.rb +64 -64
  12. data/lib/dnsimple/client/clients.rb +82 -58
  13. data/lib/dnsimple/client/contacts.rb +74 -37
  14. data/lib/dnsimple/client/domains.rb +82 -28
  15. data/lib/dnsimple/client/domains_email_forwards.rb +107 -0
  16. data/lib/dnsimple/client/identity.rb +38 -0
  17. data/lib/dnsimple/client/oauth.rb +42 -0
  18. data/lib/dnsimple/client/registrar.rb +64 -72
  19. data/lib/dnsimple/client/registrar_auto_renewal.rb +41 -0
  20. data/lib/dnsimple/client/registrar_whois_privacy.rb +74 -0
  21. data/lib/dnsimple/client/tlds.rb +88 -0
  22. data/lib/dnsimple/client/webhooks.rb +82 -0
  23. data/lib/dnsimple/client/zones.rb +68 -0
  24. data/lib/dnsimple/client/zones_records.rb +127 -0
  25. data/lib/dnsimple/default.rb +10 -17
  26. data/lib/dnsimple/error.rb +5 -8
  27. data/lib/dnsimple/extra.rb +1 -1
  28. data/lib/dnsimple/response.rb +80 -0
  29. data/lib/dnsimple/struct.rb +13 -14
  30. data/lib/dnsimple/struct/account.rb +13 -0
  31. data/lib/dnsimple/struct/contact.rb +6 -3
  32. data/lib/dnsimple/struct/domain.rb +10 -10
  33. data/lib/dnsimple/struct/domain_check.rb +16 -0
  34. data/lib/dnsimple/struct/email_forward.rb +11 -1
  35. data/lib/dnsimple/struct/oauth_token.rb +19 -0
  36. data/lib/dnsimple/struct/record.rb +25 -7
  37. data/lib/dnsimple/struct/tld.rb +22 -0
  38. data/lib/dnsimple/struct/user.rb +3 -7
  39. data/lib/dnsimple/struct/webhook.rb +13 -0
  40. data/lib/dnsimple/struct/whois_privacy.rb +8 -5
  41. data/lib/dnsimple/struct/zone.rb +25 -0
  42. data/lib/dnsimple/version.rb +1 -1
  43. data/spec/dnsimple/client/client_service_spec.rb +37 -0
  44. data/spec/dnsimple/client/contacts_spec.rb +108 -78
  45. data/spec/dnsimple/client/domains_email_forwards_spec.rb +190 -0
  46. data/spec/dnsimple/client/domains_spec.rb +121 -58
  47. data/spec/dnsimple/client/identity_spec.rb +56 -0
  48. data/spec/dnsimple/client/oauth_spec.rb +48 -0
  49. data/spec/dnsimple/client/registrar_auto_renewal_spec.rb +80 -0
  50. data/spec/dnsimple/client/registrar_spec.rb +109 -122
  51. data/spec/dnsimple/client/registrar_whois_privacy_spec.rb +119 -0
  52. data/spec/dnsimple/client/tlds_spec.rb +139 -0
  53. data/spec/dnsimple/client/webhooks_spec.rb +142 -0
  54. data/spec/dnsimple/client/zones_records_spec.rb +277 -0
  55. data/spec/dnsimple/client/zones_spec.rb +109 -0
  56. data/spec/dnsimple/client_spec.rb +34 -46
  57. data/spec/dnsimple/extra_spec.rb +22 -0
  58. data/spec/{files → fixtures.http}/badgateway.http +14 -14
  59. data/spec/fixtures.http/checkDomain/success.http +17 -0
  60. data/spec/fixtures.http/createContact/created.http +17 -0
  61. data/spec/fixtures.http/createDomain/created.http +16 -0
  62. data/spec/fixtures.http/createEmailForward/created.http +17 -0
  63. data/spec/fixtures.http/createWebhook/created.http +17 -0
  64. data/spec/fixtures.http/createZoneRecord/created.http +17 -0
  65. data/spec/fixtures.http/deleteContact/success.http +13 -0
  66. data/spec/fixtures.http/deleteDomain/success.http +13 -0
  67. data/spec/fixtures.http/deleteEmailForward/success.http +12 -0
  68. data/spec/fixtures.http/deleteWebhook/success.http +13 -0
  69. data/spec/fixtures.http/deleteZoneRecord/success.http +13 -0
  70. data/spec/fixtures.http/disableAutoRenewal/success.http +12 -0
  71. data/spec/fixtures.http/disableWhoisPrivacy/success.http +17 -0
  72. data/spec/fixtures.http/enableAutoRenewal/success.http +12 -0
  73. data/spec/fixtures.http/enableWhoisPrivacy/created.http +17 -0
  74. data/spec/fixtures.http/enableWhoisPrivacy/success.http +17 -0
  75. data/spec/fixtures.http/getContact/success.http +17 -0
  76. data/spec/fixtures.http/getDomain/success.http +16 -0
  77. data/spec/fixtures.http/getEmailForward/success.http +17 -0
  78. data/spec/fixtures.http/getTld/success.http +17 -0
  79. data/spec/fixtures.http/getTldExtendedAttributes/success-noattributes.http +17 -0
  80. data/spec/fixtures.http/getTldExtendedAttributes/success.http +17 -0
  81. data/spec/fixtures.http/getWebhook/success.http +17 -0
  82. data/spec/fixtures.http/getWhoisPrivacy/success.http +17 -0
  83. data/spec/fixtures.http/getZone/success.http +17 -0
  84. data/spec/fixtures.http/getZoneRecord/success.http +17 -0
  85. data/spec/fixtures.http/listContacts/success.http +17 -0
  86. data/spec/fixtures.http/listDomains/success.http +16 -0
  87. data/spec/fixtures.http/listEmailForwards/success.http +17 -0
  88. data/spec/fixtures.http/listTlds/success.http +17 -0
  89. data/spec/fixtures.http/listWebhooks/success.http +17 -0
  90. data/spec/fixtures.http/listZoneRecords/success.http +17 -0
  91. data/spec/fixtures.http/listZones/success.http +17 -0
  92. data/spec/fixtures.http/notfound-contact.http +12 -0
  93. data/spec/fixtures.http/notfound-domain.http +12 -0
  94. data/spec/fixtures.http/notfound-emailforward.http +12 -0
  95. data/spec/fixtures.http/notfound-record.http +12 -0
  96. data/spec/fixtures.http/notfound-webhook.http +12 -0
  97. data/spec/fixtures.http/notfound-zone.http +12 -0
  98. data/spec/fixtures.http/oauthAccessToken/success.http +17 -0
  99. data/spec/fixtures.http/pages-1of3.http +16 -0
  100. data/spec/fixtures.http/pages-2of3.http +16 -0
  101. data/spec/fixtures.http/pages-3of3.http +16 -0
  102. data/spec/fixtures.http/registerDomain/success.http +17 -0
  103. data/spec/fixtures.http/renewDomain/error-tooearly.http +15 -0
  104. data/spec/fixtures.http/renewDomain/success.http +17 -0
  105. data/spec/fixtures.http/resetDomainToken/success.http +17 -0
  106. data/spec/fixtures.http/response.http +16 -0
  107. data/spec/fixtures.http/transferDomain/error-indnsimple.http +15 -0
  108. data/spec/fixtures.http/transferDomain/error-missing-authcode.http +15 -0
  109. data/spec/fixtures.http/transferDomain/success.http +17 -0
  110. data/spec/fixtures.http/transferDomainOut/success.http +13 -0
  111. data/spec/fixtures.http/updateContact/success.http +17 -0
  112. data/spec/fixtures.http/updateZoneRecord/success.http +17 -0
  113. data/spec/fixtures.http/whoami/success.http +16 -0
  114. data/spec/fixtures.http/whoami/success_account.http +16 -0
  115. data/spec/fixtures.http/whoami/success_user.http +16 -0
  116. data/spec/spec_helper.rb +0 -6
  117. data/spec/support/helpers.rb +4 -4
  118. metadata +161 -238
  119. data/lib/dnsimple/client/certificates.rb +0 -100
  120. data/lib/dnsimple/client/domains_autorenewal.rb +0 -35
  121. data/lib/dnsimple/client/domains_forwards.rb +0 -71
  122. data/lib/dnsimple/client/domains_privacy.rb +0 -35
  123. data/lib/dnsimple/client/domains_records.rb +0 -90
  124. data/lib/dnsimple/client/domains_sharing.rb +0 -54
  125. data/lib/dnsimple/client/domains_zones.rb +0 -22
  126. data/lib/dnsimple/client/name_servers.rb +0 -71
  127. data/lib/dnsimple/client/services.rb +0 -37
  128. data/lib/dnsimple/client/services_domains.rb +0 -68
  129. data/lib/dnsimple/client/templates.rb +0 -88
  130. data/lib/dnsimple/client/templates_domains.rb +0 -23
  131. data/lib/dnsimple/client/templates_records.rb +0 -88
  132. data/lib/dnsimple/client/users.rb +0 -39
  133. data/lib/dnsimple/client/vanity_name_servers.rb +0 -39
  134. data/lib/dnsimple/compatibility.rb +0 -46
  135. data/lib/dnsimple/struct/certificate.rb +0 -56
  136. data/lib/dnsimple/struct/membership.rb +0 -22
  137. data/lib/dnsimple/struct/price.rb +0 -16
  138. data/lib/dnsimple/struct/service.rb +0 -19
  139. data/lib/dnsimple/struct/template.rb +0 -19
  140. data/lib/dnsimple/struct/template_record.rb +0 -24
  141. data/lib/dnsimple/struct/transfer_order.rb +0 -10
  142. data/spec/dnsimple/client/certificates_spec.rb +0 -196
  143. data/spec/dnsimple/client/domains_autorenewals_spec.rb +0 -72
  144. data/spec/dnsimple/client/domains_forwards_spec.rb +0 -146
  145. data/spec/dnsimple/client/domains_privacy_spec.rb +0 -74
  146. data/spec/dnsimple/client/domains_records_spec.rb +0 -191
  147. data/spec/dnsimple/client/domains_sharing_spec.rb +0 -109
  148. data/spec/dnsimple/client/domains_zones_spec.rb +0 -40
  149. data/spec/dnsimple/client/name_servers_spec.rb +0 -131
  150. data/spec/dnsimple/client/services_domains_spec.rb +0 -101
  151. data/spec/dnsimple/client/services_spec.rb +0 -69
  152. data/spec/dnsimple/client/templates_domains_spec.rb +0 -38
  153. data/spec/dnsimple/client/templates_records_spec.rb +0 -180
  154. data/spec/dnsimple/client/templates_spec.rb +0 -166
  155. data/spec/dnsimple/client/users_spec.rb +0 -70
  156. data/spec/dnsimple/client/vanity_name_servers_spec.rb +0 -61
  157. data/spec/dnsimple/compatibility_spec.rb +0 -57
  158. data/spec/files/2fa/error-badtoken.http +0 -22
  159. data/spec/files/2fa/error-required.http +0 -23
  160. data/spec/files/2fa/exchange-token.http +0 -22
  161. data/spec/files/certificates/configure/success.http +0 -19
  162. data/spec/files/certificates/get/success.http +0 -19
  163. data/spec/files/certificates/list/success.http +0 -19
  164. data/spec/files/certificates/notfound.http +0 -19
  165. data/spec/files/certificates/purchase/success.http +0 -19
  166. data/spec/files/certificates/submit/success.http +0 -19
  167. data/spec/files/contacts/contact/success.http +0 -19
  168. data/spec/files/contacts/contacts/success.http +0 -23
  169. data/spec/files/contacts/create_contact/badrequest-missingcontact.http +0 -19
  170. data/spec/files/contacts/create_contact/badrequest-validationerror.http +0 -19
  171. data/spec/files/contacts/create_contact/created.http +0 -22
  172. data/spec/files/contacts/delete_contact/success-204.http +0 -18
  173. data/spec/files/contacts/delete_contact/success.http +0 -19
  174. data/spec/files/contacts/notfound-contact.http +0 -19
  175. data/spec/files/contacts/update_contact/success.http +0 -21
  176. data/spec/files/domains/create_domain/created.http +0 -21
  177. data/spec/files/domains/create_forward/created.http +0 -22
  178. data/spec/files/domains/create_membership/success.http +0 -21
  179. data/spec/files/domains/create_record/created.http +0 -21
  180. data/spec/files/domains/delete_domain/success-204.http +0 -18
  181. data/spec/files/domains/delete_domain/success.http +0 -19
  182. data/spec/files/domains/delete_forward/success.http +0 -17
  183. data/spec/files/domains/delete_membership/success.http +0 -17
  184. data/spec/files/domains/delete_record/success-204.http +0 -18
  185. data/spec/files/domains/delete_record/success.http +0 -19
  186. data/spec/files/domains/disable_auto_renewal/success.http +0 -21
  187. data/spec/files/domains/disable_whois_privacy/success.http +0 -21
  188. data/spec/files/domains/domain/success.http +0 -21
  189. data/spec/files/domains/domains/success.http +0 -21
  190. data/spec/files/domains/enable_auto_renewal/success.http +0 -21
  191. data/spec/files/domains/enable_whois_privacy/success.http +0 -22
  192. data/spec/files/domains/forward/success.http +0 -21
  193. data/spec/files/domains/forwards/success.http +0 -21
  194. data/spec/files/domains/memberships/success.http +0 -21
  195. data/spec/files/domains/notfound-domain.http +0 -19
  196. data/spec/files/domains/notfound-forward.http +0 -19
  197. data/spec/files/domains/notfound-membership.http +0 -19
  198. data/spec/files/domains/record/success.http +0 -19
  199. data/spec/files/domains/records/success.http +0 -19
  200. data/spec/files/domains/update_record/success.http +0 -21
  201. data/spec/files/domains/zone/success.http +0 -21
  202. data/spec/files/nameservers/change/success.http +0 -23
  203. data/spec/files/nameservers/deregister/success.http +0 -17
  204. data/spec/files/nameservers/name_servers/success.http +0 -23
  205. data/spec/files/nameservers/notfound-domain.http +0 -19
  206. data/spec/files/nameservers/register/badrequest-valueerror.http +0 -19
  207. data/spec/files/nameservers/register/success.http +0 -21
  208. data/spec/files/nameservers/vanity_name_servers/disabled.http +0 -23
  209. data/spec/files/nameservers/vanity_name_servers/enabled.http +0 -23
  210. data/spec/files/registrar/check/available.http +0 -19
  211. data/spec/files/registrar/check/registered.http +0 -21
  212. data/spec/files/registrar/extended_attributes/success.http +0 -21
  213. data/spec/files/registrar/prices/success.http +0 -21
  214. data/spec/files/registrar/register/badrequest-missingdomain.http +0 -19
  215. data/spec/files/registrar/register/badrequest-missingregistrant.http +0 -19
  216. data/spec/files/registrar/register/success.http +0 -21
  217. data/spec/files/registrar/renew/badrequest-missingrenewal.http +0 -19
  218. data/spec/files/registrar/renew/badrequest-unable.http +0 -19
  219. data/spec/files/registrar/renew/success.http +0 -21
  220. data/spec/files/registrar/transfer/success.http +0 -21
  221. data/spec/files/services/applied/success.http +0 -21
  222. data/spec/files/services/apply/success.http +0 -21
  223. data/spec/files/services/available/success.http +0 -21
  224. data/spec/files/services/notfound-service.http +0 -19
  225. data/spec/files/services/service/success.http +0 -21
  226. data/spec/files/services/services/success.http +0 -21
  227. data/spec/files/services/unapply/success.http +0 -21
  228. data/spec/files/subscriptions/subscription/success.http +0 -21
  229. data/spec/files/templates/apply_template/success.http +0 -21
  230. data/spec/files/templates/create_template/created.http +0 -22
  231. data/spec/files/templates/delete_template/success-204.http +0 -21
  232. data/spec/files/templates/delete_template/success.http +0 -21
  233. data/spec/files/templates/notfound-template.http +0 -19
  234. data/spec/files/templates/template/success.http +0 -21
  235. data/spec/files/templates/templates/success.http +0 -21
  236. data/spec/files/templates/update_template/success.http +0 -21
  237. data/spec/files/templates_records/create_record/created.http +0 -22
  238. data/spec/files/templates_records/delete_record/success-204.http +0 -19
  239. data/spec/files/templates_records/delete_record/success.http +0 -21
  240. data/spec/files/templates_records/notfound-template-record.http +0 -19
  241. data/spec/files/templates_records/record/success.http +0 -21
  242. data/spec/files/templates_records/records/success.http +0 -21
  243. data/spec/files/templates_records/update_record/success.http +0 -21
  244. data/spec/files/users/user/success.http +0 -21
@@ -0,0 +1,88 @@
1
+ module Dnsimple
2
+ class Client
3
+ module Tlds
4
+ # Lists the tlds available for registration
5
+ #
6
+ # @see https://developer.dnsimple.com/v2/tlds/#list
7
+ #
8
+ # @example List TLDs in the first page
9
+ # client.tlds.list
10
+ #
11
+ # @example List TLDs, providing a specific page
12
+ # client.tlds.list(query: { page: 2 })
13
+ #
14
+ # @param [Hash] options the filtering and sorting option
15
+ # @return [Dnsimple::PaginatedResponse<Dnsimple::Struct::Tld>]
16
+ #
17
+ # @raise [Dnsimple::RequestError]
18
+ def tlds(options = {})
19
+ response = client.get(Client.versioned("/tlds"), options)
20
+
21
+ Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::Tld.new(r) })
22
+ end
23
+ alias :list :tlds
24
+ alias :list_tlds :tlds
25
+
26
+ # Lists ALL the TLDs in DNSimple.
27
+ #
28
+ # This method is similar to {#tlds}, but instead of returning the results of a specific page
29
+ # it iterates all the pages and returns the entire collection.
30
+ #
31
+ # Please use this method carefully, as fetching the entire collection will increase the number of requests
32
+ # you send to the API server and you may eventually risk to hit the throttle limit.
33
+ #
34
+ # @see https://developer.dnsimple.com/v2/tlds/#list
35
+ # @see #tlds
36
+ #
37
+ # @example List all TLDs in DNSimple
38
+ # client.tlds.all
39
+ #
40
+ # @param [Hash] options the filtering and sorting option
41
+ # @return [Dnsimple::CollectionResponse<Dnsimple::Struct::Tld>]
42
+ #
43
+ # @raise [Dnsimple::RequestError]
44
+ def all_tlds(options = {})
45
+ paginate(:tlds, options)
46
+ end
47
+ alias :all :all_tlds
48
+
49
+ # Gets a TLD's details
50
+ #
51
+ # @see https://developer.dnsimple.com/v2/tlds/#get
52
+ #
53
+ # @example Get information on a specific TLD
54
+ # client.tlds.tld('com')
55
+ #
56
+ # @param [#to_s] tld The TLD name.
57
+ # @param [Hash] options
58
+ # @return [Dnsimple::Response<Dnsimple::Struct::Tld>]
59
+ #
60
+ # @raise [Dnsimple::NotFoundError]
61
+ # @raise [Dnsimple::RequestError]
62
+ def tld(tld, options = {})
63
+ response = client.get(Client.versioned("/tlds/%s" % tld), options)
64
+
65
+ Dnsimple::Response.new(response, Struct::Tld.new(response["data"]))
66
+ end
67
+
68
+ # Gets the extended attributes for a TLD.
69
+ #
70
+ # @see https://developer.dnsimple.com/v2/tlds/#extended-attributes
71
+ #
72
+ # @example Get extended attributes for a specific TLD
73
+ # client.tlds.extended_attributes('uk')
74
+ #
75
+ # @param [#to_s] tld The TLD name.
76
+ # @param [Hash] options
77
+ # @return [Dnsimple::CollectionResponse<Dnsimple::Struct::ExtendedAttribute>]
78
+ #
79
+ # @raise [Dnsimple::NotFoundError]
80
+ # @raise [Dnsimple::RequestError]
81
+ def extended_attributes(tld, options = {})
82
+ response = client.get(Client.versioned("/tlds/%s/extended_attributes" % tld), options)
83
+
84
+ Dnsimple::CollectionResponse.new(response, response["data"].map { |r| Struct::ExtendedAttribute.new(r) })
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,82 @@
1
+ module Dnsimple
2
+ class Client
3
+ module Webhooks
4
+
5
+ # Lists ALL the webhooks in the account.
6
+ #
7
+ # @see https://developer.dnsimple.com/v2/webhooks/#list
8
+ #
9
+ # @example List all webhooks
10
+ # client.webhooks.list(1010)
11
+ #
12
+ # @param [Fixnum] account_id the account ID
13
+ # @param [Hash] options the filtering and sorting option
14
+ # @return [Dnsimple::CollectionResponse<Dnsimple::Struct::Webhook>]
15
+ #
16
+ # @raise [Dnsimple::RequestError]
17
+ def webhooks(account_id, options = {})
18
+ response = client.get(Client.versioned("/%s/webhooks" % [account_id]), options)
19
+
20
+ Dnsimple::CollectionResponse.new(response, response["data"].map { |r| Struct::Webhook.new(r) })
21
+ end
22
+ alias :list :webhooks
23
+ alias :list_webhooks :webhooks
24
+
25
+ # Creates a webhook in the account.
26
+ #
27
+ # @see https://developer.dnsimple.com/v2/webhooks/#create
28
+ #
29
+ # @param [Fixnum] account_id the account ID
30
+ # @param [Hash] attributes
31
+ # @param [Hash] options
32
+ # @return [Dnsimple::Response<Dnsimple::Struct::Webhook>]
33
+ #
34
+ # @raise [Dnsimple::RequestError]
35
+ def create_webhook(account_id, attributes, options = {})
36
+ Extra.validate_mandatory_attributes(attributes, [:url])
37
+ response = client.post(Client.versioned("/%s/webhooks" % [account_id]), attributes, options)
38
+
39
+ Dnsimple::Response.new(response, Struct::Webhook.new(response["data"]))
40
+ end
41
+ alias :create :create_webhook
42
+
43
+ # Gets a webhook from the account.
44
+ #
45
+ # @see https://developer.dnsimple.com/v2/webhooks/#get
46
+ #
47
+ # @param [Fixnum] account_id the account ID
48
+ # @param [#to_s] webhook_id The webhook ID
49
+ # @param [Hash] options
50
+ # @return [Dnsimple::Response<Dnsimple::Struct::Webhook>]
51
+ #
52
+ # @raise [Dnsimple::NotFoundError]
53
+ # @raise [Dnsimple::RequestError]
54
+ def webhook(account_id, webhook_id, options = {})
55
+ response = client.get(Client.versioned("/%s/webhooks/%s" % [account_id, webhook_id]), options)
56
+
57
+ Dnsimple::Response.new(response, Struct::Webhook.new(response["data"]))
58
+ end
59
+
60
+ # Deletes a webook from the account.
61
+ #
62
+ # WARNING: this cannot be undone.
63
+ #
64
+ # @see https://developer.dnsimple.com/v2/webooks/#delete
65
+ #
66
+ # @param [Fixnum] account_id the account ID
67
+ # @param [#to_s] webhook_id The webhook ID
68
+ # @param [Hash] options
69
+ # @return [Dnsimple::Response<nil>]
70
+ #
71
+ # @raise [Dnsimple::NotFoundError]
72
+ # @raise [Dnsimple::RequestError]
73
+ def delete_webhook(account_id, webhook_id, options = {})
74
+ response = client.delete(Client.versioned("/%s/webhooks/%s" % [account_id, webhook_id]), nil, options)
75
+
76
+ Dnsimple::Response.new(response, nil)
77
+ end
78
+ alias :delete :delete_webhook
79
+
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,68 @@
1
+ module Dnsimple
2
+ class Client
3
+ module Zones
4
+
5
+ # Lists the zones in the account.
6
+ #
7
+ # @see https://developer.dnsimple.com/v2/zones/#list
8
+ # @see #all_zones
9
+ #
10
+ # @example List zones in the first page
11
+ # client.zones.list(1010, "example.com")
12
+ #
13
+ # @example List zones, provide a specific page
14
+ # client.zones.list(1010, "example.com", query: { page: 2 })
15
+ #
16
+ # @param [Fixnum] account_id the account ID
17
+ # @param [Hash] options the filtering and sorting option
18
+ # @return [Dnsimple::PaginatedResponse<Dnsimple::Struct::Zone>]
19
+ #
20
+ # @raise [Dnsimple::RequestError]
21
+ def zones(account_id, options = {})
22
+ response = client.get(Client.versioned("/%s/zones" % [account_id]), options)
23
+
24
+ Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::Zone.new(r) })
25
+ end
26
+ alias :list :zones
27
+ alias :list_zones :zones
28
+
29
+ # Lists ALL the zones in the account.
30
+ #
31
+ # This method is similar to {#zones}, but instead of returning the results of a specific page
32
+ # it iterates all the pages and returns the entire collection.
33
+ #
34
+ # Please use this method carefully, as fetching the entire collection will increase the number of requests
35
+ # you send to the API server and you may eventually risk to hit the throttle limit.
36
+ #
37
+ # @see https://developer.dnsimple.com/v2/zones/#list
38
+ # @see #zones
39
+ #
40
+ # @param [Fixnum] account_id the account ID
41
+ # @param [Hash] options the filtering and sorting option
42
+ # @return [Dnsimple::CollectionResponse<Dnsimple::Struct::Zone>]
43
+ #
44
+ # @raise [Dnsimple::RequestError]
45
+ def all_zones(account_id, options = {})
46
+ paginate(:zones, account_id, options)
47
+ end
48
+
49
+ # Gets a zone from the account.
50
+ #
51
+ # @see https://developer.dnsimple.com/v2/zones/#get
52
+ #
53
+ # @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
54
+ # @param [#to_s] zone_id the zone name
55
+ # @param [Hash] options
56
+ # @return [Dnsimple::Response<Dnsimple::Struct::Zone>]
57
+ #
58
+ # @raise [Dnsimple::NotFoundError]
59
+ # @raise [Dnsimple::RequestError]
60
+ def zone(account_id, zone_id, options = {})
61
+ response = client.get(Client.versioned("/%s/zones/%s" % [account_id, zone_id]), options)
62
+
63
+ Dnsimple::Response.new(response, Struct::Zone.new(response["data"]))
64
+ end
65
+
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,127 @@
1
+ module Dnsimple
2
+ class Client
3
+ module ZonesRecords
4
+
5
+ # Lists the zone records in the account.
6
+ #
7
+ # @see https://developer.dnsimple.com/v2/zones/records/#list
8
+ # @see #all_records
9
+ #
10
+ # @example List records for the zone "example.com" in the first page
11
+ # client.zones.records(1010, "example.com")
12
+ #
13
+ # @example List records for the zone "example.com", provide a specific page
14
+ # client.zones.records(1010, "example.com", query: { page: 2 })
15
+ #
16
+ # @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
17
+ # @param [String] zone_id the zone name
18
+ # @param [Hash] options the filtering and sorting option
19
+ # @return [Dnsimple::PaginatedResponse<Dnsimple::Struct::Record>]
20
+ #
21
+ # @raise [Dnsimple::RequestError]
22
+ def records(account_id, zone_id, options = {})
23
+ response = client.get(Client.versioned("/%s/zones/%s/records" % [account_id, zone_id]), options)
24
+
25
+ Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::Record.new(r) })
26
+ end
27
+ alias :list_records :records
28
+
29
+ # Lists ALL the zone records in the account.
30
+ #
31
+ # This method is similar to {#records}, but instead of returning the results of a specific page
32
+ # it iterates all the pages and returns the entire collection.
33
+ #
34
+ # Please use this method carefully, as fetching the entire collection will increase the number of requests
35
+ # you send to the API server and you may eventually risk to hit the throttle limit.
36
+ #
37
+ # @see https://developer.dnsimple.com/v2/zones/records/#list
38
+ # @see #records
39
+ #
40
+ # @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
41
+ # @param [String] zone_id the zone name
42
+ # @param [Hash] options the filtering and sorting option
43
+ # @return [Dnsimple::CollectionResponse<Dnsimple::Struct::Record>]
44
+ #
45
+ # @raise [Dnsimple::RequestError]
46
+ def all_records(account_id, zone_id, options = {})
47
+ paginate(:records, account_id, zone_id, options)
48
+ end
49
+
50
+ # Creates a zone record in the account.
51
+ #
52
+ # @see https://developer.dnsimple.com/v2/zones/records/#create
53
+ #
54
+ # @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
55
+ # @param [String] zone_id the zone name
56
+ # @param [Hash] attributes
57
+ # @param [Hash] options
58
+ # @return [Dnsimple::Response<Dnsimple::Struct::Record>]
59
+ #
60
+ # @raise [Dnsimple::RequestError]
61
+ def create_record(account_id, zone_id, attributes, options = {})
62
+ Extra.validate_mandatory_attributes(attributes, [:type, :name, :content])
63
+ response = client.post(Client.versioned("/%s/zones/%s/records" % [account_id, zone_id]), attributes, options)
64
+
65
+ Dnsimple::Response.new(response, Struct::Record.new(response["data"]))
66
+ end
67
+
68
+ # Gets a zone record from the account.
69
+ #
70
+ # @see https://developer.dnsimple.com/v2/zones/records/#get
71
+ #
72
+ # @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
73
+ # @param [String] zone_id the zone name
74
+ # @param [Fixnum] record_id the record ID
75
+ # @param [Hash] options
76
+ # @return [Dnsimple::Response<Dnsimple::Struct::Domain>]
77
+ #
78
+ # @raise [Dnsimple::NotFoundError]
79
+ # @raise [Dnsimple::RequestError]
80
+ def record(account_id, zone_id, record_id, options = {})
81
+ response = client.get(Client.versioned("/%s/zones/%s/records/%s" % [account_id, zone_id, record_id]), options)
82
+
83
+ Dnsimple::Response.new(response, Struct::Record.new(response["data"]))
84
+ end
85
+
86
+ # Updates a zone record in the account.
87
+ #
88
+ # @see https://developer.dnsimple.com/v2/zones/records/#update
89
+ #
90
+ # @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
91
+ # @param [String] zone_id the zone name
92
+ # @param [Fixnum] record_id the record ID
93
+ # @param [Hash] attributes
94
+ # @param [Hash] options
95
+ # @return [Dnsimple::Response<Dnsimple::Struct::Record>]
96
+ #
97
+ # @raise [Dnsimple::NotFoundError]
98
+ # @raise [Dnsimple::RequestError]
99
+ def update_record(account_id, zone_id, record_id, attributes, options = {})
100
+ response = client.patch(Client.versioned("/%s/zones/%s/records/%s" % [account_id, zone_id, record_id]), attributes, options)
101
+
102
+ Dnsimple::Response.new(response, Struct::Record.new(response["data"]))
103
+ end
104
+
105
+ # Deletes a zone record from the account.
106
+ #
107
+ # WARNING: this cannot be undone.
108
+ #
109
+ # @see https://developer.dnsimple.com/v2/zones/records/#delete
110
+ #
111
+ # @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
112
+ # @param [String] zone_id the zone name
113
+ # @param [Fixnum] record_id the record ID
114
+ # @param [Hash] options
115
+ # @return [Dnsimple::Response<nil>]
116
+ #
117
+ # @raise [Dnsimple::NotFoundError]
118
+ # @raise [Dnsimple::RequestError]
119
+ def delete_record(account_id, zone_id, record_id, options = {})
120
+ response = client.delete(Client.versioned("/%s/zones/%s/records/%s" % [account_id, zone_id, record_id]), nil, options)
121
+
122
+ Dnsimple::Response.new(response, nil)
123
+ end
124
+
125
+ end
126
+ end
127
+ end
@@ -4,7 +4,7 @@ module Dnsimple
4
4
  module Default
5
5
 
6
6
  # Default API endpoint
7
- API_ENDPOINT = "https://api.dnsimple.com/".freeze
7
+ BASE_URL = "https://api.dnsimple.com/".freeze
8
8
 
9
9
  # Default User Agent header
10
10
  USER_AGENT = "dnsimple-ruby/#{VERSION}".freeze
@@ -15,11 +15,10 @@ module Dnsimple
15
15
  # @return [Array] of option keys
16
16
  def keys
17
17
  @keys ||= [
18
- :api_endpoint,
18
+ :base_url,
19
19
  :username,
20
20
  :password,
21
- :exchange_token,
22
- :api_token,
21
+ :access_token,
23
22
  :domain_api_token,
24
23
  :user_agent,
25
24
  :proxy,
@@ -32,10 +31,10 @@ module Dnsimple
32
31
  Hash[keys.map { |key| [key, send(key)]}]
33
32
  end
34
33
 
35
- # Default API endpoint from ENV or {API_ENDPOINT}
34
+ # Default API endpoint from ENV or {BASE_URL}
36
35
  # @return [String]
37
- def api_endpoint
38
- ENV['DNSIMPLE_API_ENDPOINT'] || API_ENDPOINT
36
+ def base_url
37
+ ENV['DNSIMPLE_BASE_URL'] || BASE_URL
39
38
  end
40
39
 
41
40
  # Default DNSimple username for Basic Auth from ENV
@@ -50,10 +49,10 @@ module Dnsimple
50
49
  ENV['DNSIMPLE_PASSWORD']
51
50
  end
52
51
 
53
- # Default DNSimple Exchange Token for Basic Auth from ENV
52
+ # Default DNSimple access token for OAuth authentication from ENV
54
53
  # @return [String]
55
- def exchange_token
56
- ENV['DNSIMPLE_API_EXCHANGE_TOKEN']
54
+ def access_token
55
+ ENV['DNSIMPLE_ACCESS_TOKEN']
57
56
  end
58
57
 
59
58
  # Default DNSimple Domain API Token for Token Auth from ENV
@@ -62,12 +61,6 @@ module Dnsimple
62
61
  ENV['DNSIMPLE_API_DOMAIN_TOKEN']
63
62
  end
64
63
 
65
- # Default DNSimple API Token for Token Auth from ENV
66
- # @return [String]
67
- def api_token
68
- ENV['DNSIMPLE_API_TOKEN']
69
- end
70
-
71
64
  # Default User-Agent header string from ENV or {USER_AGENT}
72
65
  # @return [String]
73
66
  def user_agent
@@ -83,4 +76,4 @@ module Dnsimple
83
76
  end
84
77
  end
85
78
 
86
- end
79
+ end
@@ -3,12 +3,13 @@ module Dnsimple
3
3
  class Error < StandardError
4
4
  end
5
5
 
6
+ # RequestError is raised when an API request fails for an client, a server error or invalid request information.
6
7
  class RequestError < Error
7
- attr_reader :response
8
+ attr_reader :http_response
8
9
 
9
- def initialize(response)
10
- @response = response
11
- super("#{response.code}")
10
+ def initialize(http_response)
11
+ @http_response = http_response
12
+ super(http_response.code.to_s)
12
13
  end
13
14
  end
14
15
 
@@ -21,8 +22,4 @@ module Dnsimple
21
22
  class AuthenticationFailed < AuthenticationError
22
23
  end
23
24
 
24
- # An exception that is raised if a request is executed for an account that requires two-factor authentication.
25
- class TwoFactorAuthenticationRequired < AuthenticationError
26
- end
27
-
28
25
  end