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,107 @@
1
+ module Dnsimple
2
+ class Client
3
+ module DomainsEmailForwards
4
+
5
+ # Lists the email forwards for the domain.
6
+ #
7
+ # @see https://developer.dnsimple.com/v2/domains/email-forwards/#list
8
+ #
9
+ # @example List email forwards in the first page
10
+ # client.domains.email_forwards(1010, "example.com")
11
+ #
12
+ # @example List email forwards, provide a specific page
13
+ # client.domains.email_forwards(1010, "example.com", query: { page: 2 })
14
+ #
15
+ # @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
16
+ # @param [#to_s] domain_id The domain ID or domain name
17
+ # @param [Hash] options the filtering and sorting option
18
+ # @return [Dnsimple::PaginatedResponse<Dnsimple::Struct::EmailForward>]
19
+ #
20
+ # @raise [Dnsimple::NotFoundError]
21
+ # @raise [Dnsimple::RequestError]
22
+ def email_forwards(account_id, domain_id, options = {})
23
+ response = client.get(Client.versioned("/%s/domains/%s/email_forwards" % [account_id, domain_id]), options)
24
+
25
+ Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::EmailForward.new(r) })
26
+ end
27
+
28
+ # Lists ALL the email forwards for the domain.
29
+ #
30
+ # This method is similar to {#email_forwards}, but instead of returning the results of a specific page
31
+ # it iterates all the pages and returns the entire collection.
32
+ #
33
+ # Please use this method carefully, as fetching the entire collection will increase the number of requests
34
+ # you send to the API server and you may eventually risk to hit the throttle limit.
35
+ #
36
+ # @see https://developer.dnsimple.com/v2/domains/email-forwards/#list
37
+ # @see #email_forwards
38
+ #
39
+ # @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
40
+ # @param [#to_s] domain_id The domain ID or domain name
41
+ # @param [Hash] options the filtering and sorting option
42
+ # @return [Dnsimple::CollectionResponse<Dnsimple::Struct::EmailForward>]
43
+ #
44
+ # @raise [Dnsimple::RequestError]
45
+ def all_email_forwards(account_id, domain_id, options = {})
46
+ paginate(:email_forwards, account_id, domain_id, options)
47
+ end
48
+
49
+ # Creates an email forward for the domain.
50
+ #
51
+ # @see https://developer.dnsimple.com/v2/domains/email-forwards/#create
52
+ #
53
+ # @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
54
+ # @param [#to_s] domain_id The domain ID or domain name
55
+ # @param [Hash] attributes
56
+ # @param [Hash] options
57
+ # @return [Dnsimple::Response<Dnsimple::Struct::EmailForward>]
58
+ #
59
+ # @raise [Dnsimple::RequestError]
60
+ def create_email_forward(account_id, domain_id, attributes, options = {})
61
+ Extra.validate_mandatory_attributes(attributes, [:from, :to])
62
+ response = client.post(Client.versioned("/%s/domains/%s/email_forwards" % [account_id, domain_id]), attributes, options)
63
+
64
+ Dnsimple::Response.new(response, Struct::EmailForward.new(response["data"]))
65
+ end
66
+
67
+ # Gets a email forward for the domain.
68
+ #
69
+ # @see https://developer.dnsimple.com/v2/domains/email-forwards/#get
70
+ #
71
+ # @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
72
+ # @param [#to_s] domain_id The domain ID or domain name
73
+ # @param [#to_s] email_forward_id The email forward ID
74
+ # @param [Hash] options
75
+ # @return [Dnsimple::Response<Dnsimple::Struct::EmailForward>]
76
+ #
77
+ # @raise [Dnsimple::NotFoundError]
78
+ # @raise [Dnsimple::RequestError]
79
+ def email_forward(account_id, domain_id, email_forward_id, options = {})
80
+ response = client.get(Client.versioned("/%s/domains/%s/email_forwards/%s" % [account_id, domain_id, email_forward_id]), options)
81
+
82
+ Dnsimple::Response.new(response, Struct::EmailForward.new(response["data"]))
83
+ end
84
+
85
+ # Deletes an email forward for the domain.
86
+ #
87
+ # WARNING: this cannot be undone.
88
+ #
89
+ # @see https://developer.dnsimple.com/v2/domains/email-forwards/#delete
90
+ #
91
+ # @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
92
+ # @param [#to_s] domain_id The domain ID or domain name
93
+ # @param [#to_s] email_forward_id The email forward ID
94
+ # @param [Hash] options
95
+ # @return [Dnsimple::Response<nil>]
96
+ #
97
+ # @raise [Dnsimple::NotFoundError]
98
+ # @raise [Dnsimple::RequestError]
99
+ def delete_email_forward(account_id, domain_id, email_forward_id, options = {})
100
+ response = client.delete(Client.versioned("/%s/domains/%s/email_forwards/%s" % [account_id, domain_id, email_forward_id]), nil, options)
101
+
102
+ Dnsimple::Response.new(response, nil)
103
+ end
104
+
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,38 @@
1
+ module Dnsimple
2
+ class Client
3
+ module Identity
4
+
5
+ # Gets the information about the current authenticated context.
6
+ #
7
+ # @see https://developer.dnsimple.com/v2/identity/#whoami
8
+ #
9
+ # @param [Hash] options
10
+ # @return [Dnsimple::Response<Hash>]
11
+ # @raise [Dnsimple::RequestError]
12
+ def whoami(options = {})
13
+ response = client.get(Client.versioned("/whoami"), options)
14
+
15
+ data = response["data"]
16
+ account = data["account"] ? Struct::Account.new(data["account"]) : nil
17
+ user = data["user"] ? Struct::User.new(data["user"]) : nil
18
+ Response.new(response, { account: account, user: user })
19
+ end
20
+
21
+
22
+ module StaticHelpers
23
+ # Calls {Identity#whoami} and directly returns the response data.
24
+ #
25
+ # @see https://developer.dnsimple.com/v2/identity/#whoami
26
+ #
27
+ # @param [Dnsimple::Client] client the DNSimple client instance to use
28
+ # @param [Array] args the args for the {Identity#whoami} call
29
+ # @return [Hash]
30
+ # @raise [Dnsimple::RequestError]
31
+ def whoami(client, *args)
32
+ client.identity.whoami(*args).data
33
+ end
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,42 @@
1
+ module Dnsimple
2
+ class Client
3
+ module Oauth
4
+
5
+ # Exchange the short-lived authorization code for an access token
6
+ # you can use to authenticate your API calls.
7
+ #
8
+ # @see https://developer.dnsimple.com/v2/oauth/
9
+ #
10
+ # @param client_id [String] Client Id you received when the application was registered with DNSimple.
11
+ # @param client_secret [String] Client Secret you received when the application was registered with DNSimple.
12
+ # @option options [String] :redirect_uri The redirect URL sent for the authorization, used to validate the request.
13
+ # @return [String] The url to redirect the user to authorize.
14
+ def exchange_authorization_for_token(code, client_id, client_secret, options = {})
15
+ attributes = { code: code, client_id: client_id, client_secret: client_secret, grant_type: "authorization_code" }
16
+ response = client.post(Client.versioned("/oauth/access_token"), attributes, options)
17
+ Struct::OauthToken.new(response)
18
+ end
19
+
20
+ # Gets the URL to authorize an user for an application via the OAuth2 flow.
21
+ #
22
+ # @see https://developer.dnsimple.com/v2/oauth/
23
+ #
24
+ # @param client_id [String] Client Id you received when the application was registered with DNSimple.
25
+ # @option options [String] :redirect_uri The URL to redirect to after authorizing.
26
+ # @option options [String] :scope The scopes to request from the user.
27
+ # @option options [String] :state A random string to protect against CSRF.
28
+ # @return [String] The URL to redirect the user to authorize.
29
+ def authorize_url(client_id, options = {})
30
+ site_url = client.base_url.sub("api.", "")
31
+ url = URI.join(site_url, "/oauth/authorize?client_id=#{client_id}")
32
+
33
+ options = options.merge(response_type: "code")
34
+ options.each do |key, value|
35
+ url.query += "&#{key}=#{value}"
36
+ end
37
+ url.to_s
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -2,119 +2,111 @@ module Dnsimple
2
2
  class Client
3
3
  module Registrar
4
4
 
5
- # Checks the availability of a domain name.
5
+ # Checks whether a domain is available to be registered.
6
6
  #
7
- # @see http://developer.dnsimple.com/v1/domains/registry/#check
7
+ # @see https://developer.dnsimple.com/v2/registrar/#check
8
8
  #
9
- # @param [#to_s] name The domain name to check.
10
- # @return [Hash] The response containing the status, price, and more details.
9
+ # @example Check whether example.com is available:
10
+ # client.registrar.check(1010, "example.com")
11
11
  #
12
- # @raise [RequestError] When the request fails.
13
- def check(name, options = {})
14
- response = begin
15
- client.get(Client.versioned("/domains/#{name}/check"), options)
16
- rescue NotFoundError => e
17
- e.response
18
- end
19
-
20
- response.parsed_response
21
- end
22
-
23
- # Checks the availability of a domain name.
24
- #
25
- # @see http://developer.dnsimple.com/v1/domains/registry/#check
26
- #
27
- # @param [#to_s] name The domain name to check.
28
- # @return [Boolean] true if the domain is available
12
+ # @param [Fixnum] account_id the account ID
13
+ # @param [#to_s] domain_name the domain name to check
14
+ # @param [Hash] options
15
+ # @return [Struct::DomainCheck]
29
16
  #
30
17
  # @raise [RequestError] When the request fails.
31
- def available?(name, options = {})
32
- check(name, options)["status"] == "available"
18
+ def check_domain(account_id, domain_name, options = {})
19
+ endpoint = Client.versioned("/%s/registrar/domains/%s/check" % [account_id, domain_name])
20
+ response = client.get(endpoint, options)
21
+
22
+ Dnsimple::Response.new(response, Struct::DomainCheck.new(response["data"]))
33
23
  end
34
24
 
35
25
  # Registers a domain.
36
26
  #
37
- # @see http://developer.dnsimple.com/v1/domains/registry/#register
27
+ # @see https://developer.dnsimple.com/v2/registrar/#register
28
+ #
29
+ # @example Initiate the registration of example.com using the contact 1234 as registrant
30
+ # including WHOIS privacy for the domain and enabling auto renewal:
31
+ # client.registrar.register(1010, "example.com", registrant_id: 1234, privacy: true, auto_renew: true)
38
32
  #
39
- # @param [#to_s] name The domain name to register.
40
- # @param [Fixnum] registrant_id The id of the contact to use as registrant.
41
- # @param [Hash] extended_attributes
33
+ # @param [Fixnum] account_id the account ID
34
+ # @param [#to_s] domain_name the domain name to register
35
+ # @param [Hash] attributes
42
36
  # @param [Hash] options
43
37
  # @return [Struct::Domain]
44
38
  #
45
39
  # @raise [RequestError] When the request fails.
46
- def register(name, registrant_id, extended_attributes = {}, options = {})
47
- options = Extra.deep_merge(options, { domain: { name: name, registrant_id: registrant_id }, extended_attribute: extended_attributes })
48
- response = client.post(Client.versioned("/domain_registrations"), options)
40
+ def register_domain(account_id, domain_name, attributes, options = {})
41
+ Extra.validate_mandatory_attributes(attributes, [:registrant_id])
42
+ endpoint = Client.versioned("/%s/registrar/domains/%s/registration" % [account_id, domain_name])
43
+ response = client.post(endpoint, attributes, options)
49
44
 
50
- Struct::Domain.new(response["domain"])
45
+ Dnsimple::Response.new(response, Struct::Domain.new(response["data"]))
51
46
  end
52
47
 
53
- # Transfers a domain.
48
+ # Renews a domain.
54
49
  #
55
- # @see http://developer.dnsimple.com/v1/domains/registry/#transfer
50
+ # @see https://developer.dnsimple.com/v2/registrar/#renew
56
51
  #
57
- # @param [#to_s] name The domain name to register.
58
- # @param [String] auth_code
59
- # @param [Fixnum] registrant_id The id of the contact to use as registrant.
60
- # @param [Hash] extended_attributes
52
+ # @example Renew example.com for 3 years:
53
+ # client.registrar.renew(1010, "example.com", period: 3)
54
+ #
55
+ # @param [Fixnum] account_id the account ID
56
+ # @param [#to_s] domain_name the domain name to renew
57
+ # @param [Hash] attributes
61
58
  # @param [Hash] options
62
- # @return [Struct::TransferOrder]
59
+ # @return [Struct::Domain]
63
60
  #
64
61
  # @raise [RequestError] When the request fails.
65
- def transfer(name, auth_code, registrant_id, extended_attributes = {}, options = {})
66
- options = Extra.deep_merge(options, { domain: { name: name, registrant_id: registrant_id }, extended_attribute: extended_attributes, transfer_order: { authinfo: auth_code }})
67
- response = client.post(Client.versioned("/domain_transfers"), options)
62
+ def renew_domain(account_id, domain_name, attributes = nil, options = {})
63
+ endpoint = Client.versioned("/%s/registrar/domains/%s/renew" % [account_id, domain_name])
64
+ response = client.post(endpoint, attributes, options)
68
65
 
69
- Struct::TransferOrder.new(response["transfer_order"])
66
+ Dnsimple::Response.new(response, Struct::Domain.new(response["data"]))
70
67
  end
71
68
 
72
- # Renew a domain.
69
+ # Starts the transfer of a domain to DNSimple.
73
70
  #
74
- # @see http://developer.dnsimple.com/v1/domains/registry/#renew
71
+ # @see https://developer.dnsimple.com/v2/registrar/#transfer
75
72
  #
76
- # @param [#to_s] name The domain name to renew.
73
+ # @example Initiate the transfer for example.com using the contact 1234 as registrant:
74
+ # client.registrar.transfer(1010, "example.com", registrant_id: 1234, auth_info: "x1y2z3")
75
+ #
76
+ # @param [Fixnum] account_id the account ID
77
+ # @param [#to_s] domain_name the domain name to transfer
78
+ # @param [Hash] attributes
77
79
  # @param [Hash] options
78
80
  # @return [Struct::Domain]
79
81
  #
80
82
  # @raise [RequestError] When the request fails.
81
- def renew(name, options = {})
82
- options = Extra.deep_merge(options, { domain: { name: name }})
83
- response = client.post(Client.versioned("/domain_renewals"), options)
83
+ def transfer_domain(account_id, domain_name, attributes, options = {})
84
+ Extra.validate_mandatory_attributes(attributes, [:registrant_id])
85
+ endpoint = Client.versioned("/%s/registrar/domains/%s/transfer" % [account_id, domain_name])
86
+ response = client.post(endpoint, attributes, options)
84
87
 
85
- Struct::Domain.new(response["domain"])
88
+ Dnsimple::Response.new(response, Struct::Domain.new(response["data"]))
86
89
  end
87
90
 
88
-
89
- # List the extended attributes for a TLD.
90
- #
91
- # @see http://developer.dnsimple.com/v1/registrar/extended-attributes/#list
91
+ # Requests the transfer of a domain out of DNSimple.
92
92
  #
93
- # @param [#to_s] tld The TLD name.
94
- # @return [Array<Struct::ExtendedAttribute>]
95
- #
96
- # @raise [RequestError] When the request fails.
97
- def extended_attributes(tld, options = {})
98
- response = client.get(Client.versioned("/extended_attributes/#{tld}"), options)
99
-
100
- response.map { |r| Struct::ExtendedAttribute.new(r) }
101
- end
102
- alias :list_extended_attributes :extended_attributes
103
-
104
- # List all the TLD prices.
93
+ # @see https://developer.dnsimple.com/v2/registrar/#transfer_out
105
94
  #
106
- # @see http://developer.dnsimple.com/v1/registrar/prices/#list
95
+ # @example Request to transfer of example.com out of DNSimple:
96
+ # client.registrar.transfer_out(1010, "example.com")
107
97
  #
108
- # @return [Array<Struct::Price>]
98
+ # @param [Fixnum] account_id the account ID
99
+ # @param [#to_s] domain_name the domain name to transfer out
100
+ # @param [Hash] options
101
+ # @return [Dnsimple::Response<nil>]
109
102
  #
110
103
  # @raise [RequestError] When the request fails.
111
- def prices(options = {})
112
- response = client.get(Client.versioned("/prices"), options)
104
+ def transfer_domain_out(account_id, domain_name, options = {})
105
+ endpoint = Client.versioned("/%s/registrar/domains/%s/transfer_out" % [account_id, domain_name])
106
+ response = client.post(endpoint, nil, options)
113
107
 
114
- response.map { |r| Struct::Price.new(r["price"]) }
108
+ Dnsimple::Response.new(response, nil)
115
109
  end
116
- alias :list_prices :prices
117
-
118
110
  end
119
111
  end
120
112
  end
@@ -0,0 +1,41 @@
1
+ module Dnsimple
2
+ class Client
3
+ module RegistrarAutoRenewal
4
+
5
+ # Enable auto renewal for the domain in the account.
6
+ #
7
+ # @see https://developer.dnsimple.com/v2/registrar/auto-renewal/
8
+ #
9
+ # @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
10
+ # @param [#to_s] domain_name the domain name
11
+ # @param [Hash] options
12
+ # @return [Dnsimple::Response<nil>]
13
+ #
14
+ # @raise [Dnsimple::NotFoundError]
15
+ # @raise [Dnsimple::RequestError]
16
+ def enable_auto_renewal(account_id, domain_name, options={})
17
+ response = client.put(Client.versioned("/%s/registrar/domains/%s/auto_renewal" % [account_id, domain_name]), nil, options)
18
+
19
+ Dnsimple::Response.new(response, nil)
20
+ end
21
+
22
+ # Disable auto renewal for the domain in the account.
23
+ #
24
+ # @see https://developer.dnsimple.com/v2/registrar/auto-renewal/
25
+ #
26
+ # @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
27
+ # @param [#to_s] domain_name the domain name
28
+ # @param [Hash] options
29
+ # @return [Dnsimple::Response<nil>]
30
+ #
31
+ # @raise [Dnsimple::NotFoundError]
32
+ # @raise [Dnsimple::RequestError]
33
+ def disable_auto_renewal(account_id, domain_name, options={})
34
+ response = client.delete(Client.versioned("/%s/registrar/domains/%s/auto_renewal" % [account_id, domain_name]), nil, options)
35
+
36
+ Dnsimple::Response.new(response, nil)
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,74 @@
1
+ module Dnsimple
2
+ class Client
3
+ module RegistrarWhoisPrivacy
4
+
5
+ # Gets the whois privacy for the domain.
6
+ #
7
+ # @see https://developer.dnsimple.com/v2/registrar/whois-privacy/#get
8
+ #
9
+ # @example Get the whois privacy for "example.com":
10
+ # client.registrar.get_whois_privacy(1010, "example.com")
11
+ #
12
+ # @param [Fixnum] account_id the account ID
13
+ # @param [#to_s] domain_name the domain name
14
+ # @param [Hash] options
15
+ # @return [Struct::WhoisPrivacy]
16
+ #
17
+ # @raise [RequestError] When the request fails.
18
+ def whois_privacy(account_id, domain_name, options = {})
19
+ endpoint = whois_privacy_endpoint(account_id, domain_name)
20
+ response = client.get(endpoint, options)
21
+
22
+ Dnsimple::Response.new(response, Struct::WhoisPrivacy.new(response["data"]))
23
+ end
24
+
25
+ # Enables whois privacy for the domain.
26
+ #
27
+ # @see https://developer.dnsimple.com/v2/registrar/whois-privacy/#enable
28
+ #
29
+ # @example Enable whois privacy for "example.com":
30
+ # client.registrar.enable_whois_privacy(1010, "example.com")
31
+ #
32
+ # @param [Fixnum] account_id the account ID
33
+ # @param [#to_s] domain_name the domain name
34
+ # @param [Hash] options
35
+ # @return [Struct::WhoisPrivacy]
36
+ #
37
+ # @raise [RequestError] When the request fails.
38
+ def enable_whois_privacy(account_id, domain_name, options = {})
39
+ endpoint = whois_privacy_endpoint(account_id, domain_name)
40
+ response = client.put(endpoint, nil, options)
41
+
42
+ Dnsimple::Response.new(response, Struct::WhoisPrivacy.new(response["data"]))
43
+ end
44
+
45
+ # Disables whois privacy for the domain.
46
+ #
47
+ # @see https://developer.dnsimple.com/v2/registrar/whois-privacy/#disable
48
+ #
49
+ # @example Disable whois privacy for "example.com":
50
+ # client.registrar.disable_whois_privacy(1010, "example.com")
51
+ #
52
+ # @param [Fixnum] account_id the account ID
53
+ # @param [#to_s] domain_name The domain name to check.
54
+ # @param [Hash] options
55
+ # @return [Struct::WhoisPrivacy]
56
+ #
57
+ # @raise [RequestError] When the request fails.
58
+ def disable_whois_privacy(account_id, domain_name, options = {})
59
+ endpoint = whois_privacy_endpoint(account_id, domain_name)
60
+ response = client.delete(endpoint, nil, options)
61
+
62
+ Dnsimple::Response.new(response, Struct::WhoisPrivacy.new(response["data"]))
63
+ end
64
+
65
+
66
+ private
67
+
68
+ def whois_privacy_endpoint(account_id, domain_name)
69
+ Client.versioned("/%s/registrar/domains/%s/whois_privacy" % [account_id, domain_name])
70
+ end
71
+
72
+ end
73
+ end
74
+ end