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
@@ -2,138 +2,201 @@ require 'spec_helper'
2
2
 
3
3
  describe Dnsimple::Client, ".domains" do
4
4
 
5
- subject { described_class.new(api_endpoint: "https://api.zone", username: "user", api_token: "token").domains }
5
+ subject { described_class.new(base_url: "https://api.dnsimple.test", access_token: "a1b2c3").domains }
6
6
 
7
7
 
8
8
  describe "#domains" do
9
+ let(:account_id) { 1010 }
10
+
9
11
  before do
10
- stub_request(:get, %r[/v1/domains$]).
11
- to_return(read_fixture("domains/domains/success.http"))
12
+ stub_request(:get, %r[/v2/#{account_id}/domains])
13
+ .to_return(read_http_fixture("listDomains/success.http"))
12
14
  end
13
15
 
14
16
  it "builds the correct request" do
15
- subject.domains
17
+ subject.domains(account_id)
18
+
19
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/domains")
20
+ .with(headers: { 'Accept' => 'application/json' })
21
+ end
22
+
23
+ it "supports pagination" do
24
+ subject.domains(account_id, query: { page: 2 })
25
+
26
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/domains?page=2")
27
+ end
28
+
29
+ it "supports extra request options" do
30
+ subject.domains(account_id, query: { foo: "bar" })
16
31
 
17
- expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains").
18
- with(headers: { 'Accept' => 'application/json' })
32
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/domains?foo=bar")
19
33
  end
20
34
 
21
35
  it "returns the domains" do
22
- results = subject.domains
36
+ response = subject.domains(account_id)
23
37
 
24
- expect(results).to be_a(Array)
25
- expect(results.size).to eq(2)
38
+ expect(response).to be_a(Dnsimple::PaginatedResponse)
39
+ expect(response.data).to be_a(Array)
40
+ expect(response.data.size).to eq(2)
26
41
 
27
- results.each do |result|
42
+ response.data.each do |result|
28
43
  expect(result).to be_a(Dnsimple::Struct::Domain)
29
44
  expect(result.id).to be_a(Fixnum)
30
45
  end
31
46
  end
47
+
48
+ it "exposes the pagination information" do
49
+ response = subject.domains(account_id)
50
+
51
+ expect(response.respond_to?(:page)).to be_truthy
52
+ expect(response.page).to eq(1)
53
+ expect(response.per_page).to be_a(Fixnum)
54
+ expect(response.total_entries).to be_a(Fixnum)
55
+ expect(response.total_pages).to be_a(Fixnum)
56
+ end
57
+ end
58
+
59
+ describe "#all_domains" do
60
+ let(:account_id) { 1010 }
61
+
62
+ it "delegates to client.paginate" do
63
+ expect(subject).to receive(:paginate).with(:domains, account_id, { foo: "bar" })
64
+ subject.all_domains(account_id, { foo: "bar" })
65
+ end
32
66
  end
33
67
 
34
68
  describe "#create_domain" do
69
+ let(:account_id) { 1010 }
70
+
35
71
  before do
36
- stub_request(:post, %r[/v1/domains$]).
37
- to_return(read_fixture("domains/create_domain/created.http"))
72
+ stub_request(:post, %r[/v2/#{account_id}/domains$])
73
+ .to_return(read_http_fixture("createDomain/created.http"))
38
74
  end
39
75
 
40
76
  let(:attributes) { { name: "example.com" } }
41
77
 
42
78
  it "builds the correct request" do
43
- subject.create_domain(attributes)
79
+ subject.create_domain(account_id, attributes)
44
80
 
45
- expect(WebMock).to have_requested(:post, "https://api.zone/v1/domains").
46
- with(body: { domain: attributes }).
47
- with(headers: { 'Accept' => 'application/json' })
81
+ expect(WebMock).to have_requested(:post, "https://api.dnsimple.test/v2/#{account_id}/domains")
82
+ .with(body: attributes)
83
+ .with(headers: { 'Accept' => 'application/json' })
48
84
  end
49
85
 
50
86
  it "returns the domain" do
51
- result = subject.create_domain(attributes)
87
+ response = subject.create_domain(account_id, attributes)
88
+ expect(response).to be_a(Dnsimple::Response)
52
89
 
90
+ result = response.data
53
91
  expect(result).to be_a(Dnsimple::Struct::Domain)
54
92
  expect(result.id).to be_a(Fixnum)
55
93
  end
56
94
  end
57
95
 
58
96
  describe "#domain" do
97
+ let(:account_id) { 1010 }
98
+
59
99
  before do
60
- stub_request(:get, %r[/v1/domains/.+$]).
61
- to_return(read_fixture("domains/domain/success.http"))
100
+ stub_request(:get, %r[/v2/#{account_id}/domains/.+$])
101
+ .to_return(read_http_fixture("getDomain/success.http"))
62
102
  end
63
103
 
64
104
  it "builds the correct request" do
65
- subject.domain("example.com")
105
+ subject.domain(account_id, domain = "example.com")
66
106
 
67
- expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com").
68
- with(headers: { 'Accept' => 'application/json' })
107
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/domains/#{domain}")
108
+ .with(headers: { 'Accept' => 'application/json' })
69
109
  end
70
110
 
71
111
  it "returns the domain" do
72
- result = subject.domain("example.com")
112
+ response = subject.domain(account_id, "example.com")
113
+ expect(response).to be_a(Dnsimple::Response)
73
114
 
115
+ result = response.data
74
116
  expect(result).to be_a(Dnsimple::Struct::Domain)
75
117
  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
118
+ expect(result.account_id).to eq(1010)
119
+ expect(result.registrant_id).to eq(nil)
120
+ expect(result.name).to eq("example-alpha.com")
121
+ expect(result.state).to eq("hosted")
122
+ expect(result.auto_renew).to eq(false)
123
+ expect(result.private_whois).to eq(false)
124
+ expect(result.expires_on).to eq(nil)
125
+ expect(result.created_at).to eq("2014-12-06T15:56:55.573Z")
126
+ expect(result.updated_at).to eq("2015-12-09T00:20:56.056Z")
127
+ end
128
+
129
+ context "when the domain does not exist" do
88
130
  it "raises NotFoundError" do
89
- stub_request(:get, %r[/v1]).
90
- to_return(read_fixture("domains/notfound-domain.http"))
131
+ stub_request(:get, %r[/v2])
132
+ .to_return(read_http_fixture("notfound-domain.http"))
91
133
 
92
134
  expect {
93
- subject.domain("example.com")
135
+ subject.domain(account_id, "example.com")
94
136
  }.to raise_error(Dnsimple::NotFoundError)
95
137
  end
96
138
  end
97
139
  end
98
140
 
99
141
  describe "#delete_domain" do
142
+ let(:account_id) { 1010 }
143
+
100
144
  before do
101
- stub_request(:delete, %r[/v1/domains/.+$]).
102
- to_return(read_fixture("domains/delete_domain/success.http"))
145
+ stub_request(:delete, %r[/v2/#{account_id}/domains/.+$])
146
+ .to_return(read_http_fixture("deleteDomain/success.http"))
103
147
  end
104
148
 
105
149
  it "builds the correct request" do
106
- subject.delete_domain("example.com")
150
+ subject.delete_domain(account_id, domain = "example.com")
107
151
 
108
- expect(WebMock).to have_requested(:delete, "https://api.zone/v1/domains/example.com").
109
- with(headers: { 'Accept' => 'application/json' })
152
+ expect(WebMock).to have_requested(:delete, "https://api.dnsimple.test/v2/#{account_id}/domains/#{domain}")
153
+ .with(headers: { 'Accept' => 'application/json' })
110
154
  end
111
155
 
112
156
  it "returns nothing" do
113
- result = subject.delete_domain("example.com")
157
+ response = subject.delete_domain(account_id, "example.com")
158
+ expect(response).to be_a(Dnsimple::Response)
114
159
 
115
- expect(result).to be_truthy
160
+ result = response.data
161
+ expect(result).to be_nil
116
162
  end
117
163
 
118
- it "supports HTTP 204" do
119
- stub_request(:delete, %r[/v1]).
120
- to_return(read_fixture("domains/delete_domain/success-204.http"))
121
-
122
- result = subject.delete_domain("example.com")
123
-
124
- expect(result).to be_truthy
125
- end
126
-
127
- context "when something does not exist" do
164
+ context "when the domain does not exist" do
128
165
  it "raises NotFoundError" do
129
- stub_request(:delete, %r[/v1]).
130
- to_return(read_fixture("domains/notfound-domain.http"))
166
+ stub_request(:delete, %r[/v2])
167
+ .to_return(read_http_fixture("notfound-domain.http"))
131
168
 
132
169
  expect {
133
- subject.delete_domain("example.com")
170
+ subject.delete_domain(account_id, "example.com")
134
171
  }.to raise_error(Dnsimple::NotFoundError)
135
172
  end
136
173
  end
137
174
  end
138
175
 
176
+ describe "#reset_domain_token" do
177
+ let(:account_id) { 1010 }
178
+ let(:domain_id) { "example.com" }
179
+
180
+ before do
181
+ stub_request(:post, %r[/v2/#{account_id}/domains/#{domain_id}/token])
182
+ .to_return(read_http_fixture("resetDomainToken/success.http"))
183
+ end
184
+
185
+ it "builds the correct request" do
186
+ subject.reset_domain_token(account_id, domain_id)
187
+
188
+ expect(WebMock).to have_requested(:post, "https://api.dnsimple.test/v2/#{account_id}/domains/#{domain_id}/token")
189
+ .with(headers: { 'Accept' => 'application/json' })
190
+ end
191
+
192
+ it "returns the domain" do
193
+ response = subject.reset_domain_token(account_id, domain_id)
194
+ expect(response).to be_a(Dnsimple::Response)
195
+
196
+ result = response.data
197
+ expect(result).to be_a(Dnsimple::Struct::Domain)
198
+ expect(result.id).to be_a(Fixnum)
199
+ end
200
+ end
201
+
139
202
  end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dnsimple::Client, ".identity" do
4
+
5
+ subject { described_class.new(base_url: "https://api.dnsimple.test", access_token: "a1b2c3").identity }
6
+
7
+
8
+ describe "#whoami" do
9
+ before do
10
+ stub_request(:get, %r[/v2/whoami$])
11
+ .to_return(read_http_fixture("whoami/success.http"))
12
+ end
13
+
14
+ it "builds the correct request" do
15
+ subject.whoami
16
+
17
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/whoami")
18
+ .with(headers: { 'Accept' => 'application/json' })
19
+ end
20
+
21
+ it "returns a response" do
22
+ response = subject.whoami
23
+ expect(response).to be_a(Dnsimple::Response)
24
+
25
+ result = response.data
26
+ expect(result).to be_a(Hash)
27
+ end
28
+
29
+ context "when authenticated as account" do
30
+ before do
31
+ stub_request(:get, %r[/v2/whoami$])
32
+ .to_return(read_http_fixture("whoami/success_account.http"))
33
+ end
34
+
35
+ it "sets the account" do
36
+ result = subject.whoami.data
37
+ expect(result[:account]).to be_a(Dnsimple::Struct::Account)
38
+ expect(result[:user]).to be_nil
39
+ end
40
+ end
41
+
42
+ context "when authenticated as user" do
43
+ before do
44
+ stub_request(:get, %r[/v2/whoami$])
45
+ .to_return(read_http_fixture("whoami/success_user.http"))
46
+ end
47
+
48
+ it "sets the user" do
49
+ result = subject.whoami.data
50
+ expect(result[:account]).to be_nil
51
+ expect(result[:user]).to be_a(Dnsimple::Struct::User)
52
+ end
53
+ end
54
+ end
55
+
56
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dnsimple::Client, ".oauth" do
4
+
5
+ subject { described_class.new(base_url: "https://api.dnsimple.test", access_token: "a1b2c3").oauth }
6
+
7
+
8
+ describe "#exchange_authorization_for_token" do
9
+ let(:client_id) { "super-client" }
10
+ let(:client_secret) { "super-secret" }
11
+ let(:code) { "super-code" }
12
+
13
+ before do
14
+ stub_request(:post, %r[/v2/oauth/access_token$])
15
+ .to_return(read_http_fixture("oauthAccessToken/success.http"))
16
+ end
17
+
18
+ it "builds the correct request" do
19
+ subject.exchange_authorization_for_token(code, client_id, client_secret)
20
+
21
+ expect(WebMock).to have_requested(:post, "https://api.dnsimple.test/v2/oauth/access_token")
22
+ .with(body: { client_id: client_id, client_secret: client_secret, code: code, grant_type: "authorization_code" })
23
+ .with(headers: { 'Accept' => 'application/json' })
24
+ end
25
+
26
+ it "returns oauth token" do
27
+ result = subject.exchange_authorization_for_token(code, client_id, client_secret)
28
+
29
+ expect(result).to be_a(Dnsimple::Struct::OauthToken)
30
+ expect(result.access_token).to eq("zKQ7OLqF5N1gylcJweA9WodA000BUNJD")
31
+ expect(result.token_type).to eq("Bearer")
32
+ expect(result.account_id).to eq(1)
33
+ end
34
+ end
35
+
36
+ describe "#authorize_url" do
37
+ it "builds the correct url" do
38
+ url = subject.authorize_url("great-app")
39
+ expect(url).to eq("https://dnsimple.test/oauth/authorize?client_id=great-app&response_type=code")
40
+ end
41
+
42
+ it "exposes the options in the query string" do
43
+ url = subject.authorize_url("great-app", secret: "1", redirect_uri: "http://example.com")
44
+ expect(url).to eq("https://dnsimple.test/oauth/authorize?client_id=great-app&secret=1&redirect_uri=http://example.com&response_type=code")
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dnsimple::Client, ".registrar" do
4
+
5
+ subject { described_class.new(base_url: "https://api.dnsimple.test", access_token: "a1b2c3").registrar }
6
+
7
+ describe "#enable_auto_renewal" do
8
+ let(:account_id) { 1010 }
9
+ let(:domain_id) { "example.com" }
10
+
11
+ before do
12
+ stub_request(:put, %r[/v2/#{account_id}/registrar/domains/#{domain_id}])
13
+ .to_return(read_http_fixture("enableAutoRenewal/success.http"))
14
+ end
15
+
16
+
17
+ it "builds the correct request" do
18
+ subject.enable_auto_renewal(account_id, domain_id)
19
+
20
+ expect(WebMock).to have_requested(:put, "https://api.dnsimple.test/v2/#{account_id}/registrar/domains/#{domain_id}/auto_renewal")
21
+ .with(headers: { 'Accept' => 'application/json' })
22
+ end
23
+
24
+ it "returns nothing" do
25
+ response = subject.enable_auto_renewal(account_id, domain_id)
26
+ expect(response).to be_a(Dnsimple::Response)
27
+
28
+ result = response.data
29
+ expect(result).to be_nil
30
+ end
31
+
32
+ context "when the domain does not exist" do
33
+ it "raises NotFoundError" do
34
+ stub_request(:put, %r[/v2])
35
+ .to_return(read_http_fixture("notfound-domain.http"))
36
+
37
+ expect {
38
+ subject.enable_auto_renewal(account_id, domain_id)
39
+ }.to raise_error(Dnsimple::NotFoundError)
40
+ end
41
+ end
42
+ end
43
+
44
+ describe "#disable_auto_renewal" do
45
+ let(:account_id) { 1010 }
46
+ let(:domain_id) { "example.com" }
47
+
48
+ before do
49
+ stub_request(:delete, %r[/v2/#{account_id}/registrar/domains/#{domain_id}])
50
+ .to_return(read_http_fixture("disableAutoRenewal/success.http"))
51
+ end
52
+
53
+
54
+ it "builds the correct request" do
55
+ subject.disable_auto_renewal(account_id, domain_id)
56
+
57
+ expect(WebMock).to have_requested(:delete, "https://api.dnsimple.test/v2/#{account_id}/registrar/domains/#{domain_id}/auto_renewal")
58
+ .with(headers: { 'Accept' => 'application/json' })
59
+ end
60
+
61
+ it "returns nothing" do
62
+ response = subject.disable_auto_renewal(account_id, domain_id)
63
+ expect(response).to be_a(Dnsimple::Response)
64
+
65
+ result = response.data
66
+ expect(result).to be_nil
67
+ end
68
+
69
+ context "when the domain does not exist" do
70
+ it "raises NotFoundError" do
71
+ stub_request(:delete, %r[/v2])
72
+ .to_return(read_http_fixture("notfound-domain.http"))
73
+
74
+ expect {
75
+ subject.disable_auto_renewal(account_id, domain_id)
76
+ }.to raise_error(Dnsimple::NotFoundError)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -2,200 +2,187 @@ require 'spec_helper'
2
2
 
3
3
  describe Dnsimple::Client, ".registrar" do
4
4
 
5
- subject { described_class.new(api_endpoint: "https://api.zone", username: "user", api_token: "token").registrar }
5
+ subject { described_class.new(base_url: "https://api.dnsimple.test", access_token: "a1b2c3").registrar }
6
6
 
7
7
 
8
- describe "#check" do
8
+ describe "#check_domain" do
9
+ let(:account_id) { 1010 }
10
+
9
11
  before do
10
- stub_request(:get, %r[/v1/domains/.+/check$]).
11
- to_return(read_fixture("registrar/check/registered.http"))
12
+ stub_request(:get, %r[/v2/#{account_id}/registrar/domains/.+/check$])
13
+ .to_return(read_http_fixture("checkDomain/success.http"))
12
14
  end
13
15
 
14
16
  it "builds the correct request" do
15
- subject.check("example.com")
16
-
17
- expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com/check").
18
- with(headers: { 'Accept' => 'application/json' })
19
- end
20
-
21
- context "the domain is registered" do
22
- before do
23
- stub_request(:get, %r[/v1/domains/.+/check$]).
24
- to_return(read_fixture("registrar/check/registered.http"))
25
- end
26
-
27
- it "returns the result" do
28
- result = subject.check("example.com")
17
+ subject.check_domain(account_id, domain_name = "example.com")
29
18
 
30
- expect(result).to be_a(Hash)
31
- expect(result['status']).to eq("unavailable")
32
- end
19
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/registrar/domains/#{domain_name}/check")
20
+ .with(headers: { "Accept" => "application/json" })
33
21
  end
34
22
 
35
- context "the domain is available" do
36
- before do
37
- stub_request(:get, %r[/v1/domains/.+/check$]).
38
- to_return(read_fixture("registrar/check/available.http"))
39
- end
40
-
41
- it "returns the result" do
42
- result = subject.check("example.com")
23
+ it "returns the availability" do
24
+ response = subject.check_domain(account_id, "example.com")
25
+ expect(response).to be_a(Dnsimple::Response)
43
26
 
44
- expect(result).to be_a(Hash)
45
- expect(result['status']).to eq("available")
46
- end
27
+ result = response.data
28
+ expect(result).to be_a(Dnsimple::Struct::DomainCheck)
29
+ expect(result.domain).to eq("example.com")
30
+ expect(result.available).to be_truthy
31
+ expect(result.premium).to be_falsey
47
32
  end
48
33
  end
49
34
 
50
- describe "#available?" do
35
+ describe "#register_domain" do
36
+ let(:account_id) { 1010 }
37
+
51
38
  before do
52
- stub_request(:get, %r[/v1/domains/.+/check$]).
53
- to_return(read_fixture("registrar/check/registered.http"))
39
+ stub_request(:post, %r[/v2/#{account_id}/registrar/domains/.+/registration$])
40
+ .to_return(read_http_fixture("registerDomain/success.http"))
54
41
  end
55
42
 
43
+ let(:attributes) { { registrant_id: "10" } }
44
+
56
45
  it "builds the correct request" do
57
- subject.check("example.com")
46
+ subject.register_domain(account_id, domain_name = "example.com", attributes)
58
47
 
59
- expect(WebMock).to have_requested(:get, "https://api.zone/v1/domains/example.com/check").
60
- with(headers: { 'Accept' => 'application/json' })
48
+ expect(WebMock).to have_requested(:post, "https://api.dnsimple.test/v2/#{account_id}/registrar/domains/#{domain_name}/registration")
49
+ .with(body: attributes)
50
+ .with(headers: { "Accept" => "application/json" })
61
51
  end
62
52
 
63
- context "the domain is registered" do
64
- before do
65
- stub_request(:get, %r[/v1/domains/.+/check$]).
66
- to_return(read_fixture("registrar/check/registered.http"))
67
- end
53
+ it "returns the domain" do
54
+ response = subject.register_domain(account_id, "example.com", attributes)
55
+ expect(response).to be_a(Dnsimple::Response)
68
56
 
69
- it "returns false" do
70
- expect(subject.available?("example.com")).to be_falsey
71
- end
57
+ result = response.data
58
+ expect(result).to be_a(Dnsimple::Struct::Domain)
59
+ expect(result.id).to be_a(Fixnum)
72
60
  end
73
61
 
74
- context "the domain is available" do
75
- before do
76
- stub_request(:get, %r[/v1/domains/.+/check$]).
77
- to_return(read_fixture("registrar/check/available.http"))
78
- end
79
-
80
- it "returns true" do
81
- expect(subject.available?("example.com")).to be_truthy
62
+ context "when the attributes are incomplete" do
63
+ it "raises ArgumentError" do
64
+ expect { subject.register_domain(account_id, "example.com") }.to raise_error(ArgumentError)
82
65
  end
83
66
  end
84
67
  end
85
68
 
86
- describe "#register" do
69
+ describe "#renew_domain" do
70
+ let(:account_id) { 1010 }
71
+
87
72
  before do
88
- stub_request(:post, %r[/v1/domain_registrations]).
89
- to_return(read_fixture("registrar/register/success.http"))
73
+ stub_request(:post, %r[/v2/#{account_id}/registrar/domains/.+/renew$])
74
+ .to_return(read_http_fixture("renewDomain/success.http"))
90
75
  end
91
76
 
77
+ let(:attributes) { { period: "3" } }
78
+
92
79
  it "builds the correct request" do
93
- subject.register("example.com", 10)
80
+ subject.renew_domain(account_id, domain_name = "example.com", attributes)
94
81
 
95
- expect(WebMock).to have_requested(:post, "https://api.zone/v1/domain_registrations").
96
- with(body: { domain: { name: "example.com", registrant_id: "10" }}).
97
- with(headers: { 'Accept' => 'application/json' })
82
+ expect(WebMock).to have_requested(:post, "https://api.dnsimple.test/v2/#{account_id}/registrar/domains/#{domain_name}/renew")
83
+ .with(body: attributes)
84
+ .with(headers: { "Accept" => "application/json" })
98
85
  end
99
86
 
100
87
  it "returns the domain" do
101
- result = subject.register("example.com", 10)
88
+ response = subject.renew_domain(account_id, "example.com", attributes)
89
+ expect(response).to be_a(Dnsimple::Response)
102
90
 
91
+ result = response.data
103
92
  expect(result).to be_a(Dnsimple::Struct::Domain)
104
93
  expect(result.id).to be_a(Fixnum)
105
94
  end
95
+
96
+ context "when it is too son for the domain to be renewed" do
97
+ it "raises a BadRequestError" do
98
+ stub_request(:post, %r[/v2/#{account_id}/registrar/domains/.+/renew$])
99
+ .to_return(read_http_fixture("renewDomain/error-tooearly.http"))
100
+
101
+ expect {
102
+ subject.renew_domain(account_id, "example.com", attributes)
103
+ }.to raise_error(Dnsimple::RequestError)
104
+ end
105
+ end
106
106
  end
107
107
 
108
- describe "#renew" do
108
+ describe "#transfer_domain" do
109
+ let(:account_id) { 1010 }
110
+
109
111
  before do
110
- stub_request(:post, %r[/v1/domain_renewals]).
111
- to_return(read_fixture("registrar/renew/success.http"))
112
+ stub_request(:post, %r[/v2/#{account_id}/registrar/domains/.+/transfer$])
113
+ .to_return(read_http_fixture("transferDomain/success.http"))
112
114
  end
113
115
 
116
+ let(:attributes) { { registrant_id: "10", auth_info: "x1y2z3" } }
117
+
114
118
  it "builds the correct request" do
115
- subject.renew("example.com")
119
+ subject.transfer_domain(account_id, domain_name = "example.com", attributes)
116
120
 
117
- expect(WebMock).to have_requested(:post, "https://api.zone/v1/domain_renewals").
118
- with(headers: { 'Accept' => 'application/json' })
121
+ expect(WebMock).to have_requested(:post, "https://api.dnsimple.test/v2/#{account_id}/registrar/domains/#{domain_name}/transfer")
122
+ .with(body: attributes)
123
+ .with(headers: { "Accept" => "application/json" })
119
124
  end
120
125
 
121
126
  it "returns the domain" do
122
- result = subject.renew("example.com")
127
+ response = subject.transfer_domain(account_id, "example.com", attributes)
128
+ expect(response).to be_a(Dnsimple::Response)
123
129
 
130
+ result = response.data
124
131
  expect(result).to be_a(Dnsimple::Struct::Domain)
125
- expect(result.id).to be_a(Fixnum)
132
+ expect(result.name).to eq("example.com")
133
+ expect(result.registrant_id).to eq(10)
126
134
  end
127
135
 
128
- context "when something does not exist" do
129
- it "raises NotFoundError" do
130
- stub_request(:post, %r[/v1]).
131
- to_return(read_fixture("domains/notfound-domain.http"))
132
-
133
- expect {
134
- subject.renew("example.com")
135
- }.to raise_error(Dnsimple::NotFoundError)
136
+ context "when the attributes are incomplete" do
137
+ it "raises ArgumentError" do
138
+ expect { subject.transfer_domain(account_id, "example.com", auth_info: "x1y2z3") }.to raise_error(ArgumentError)
136
139
  end
137
140
  end
138
- end
139
-
140
-
141
- describe "#extended_attributes" do
142
- before do
143
- stub_request(:get, %r[/v1/extended_attributes/.+$]).
144
- to_return(read_fixture("registrar/extended_attributes/success.http"))
145
- end
146
141
 
147
- it "builds the correct request" do
148
- subject.extended_attributes("uk")
142
+ context "when the domain is already in DNSimple" do
143
+ it "raises a BadRequestError" do
144
+ stub_request(:post, %r[/v2/#{account_id}/registrar/domains/.+/transfer$])
145
+ .to_return(read_http_fixture("transferDomain/error-indnsimple.http"))
149
146
 
150
- expect(WebMock).to have_requested(:get, "https://api.zone/v1/extended_attributes/uk").
151
- with(headers: { 'Accept' => 'application/json' })
147
+ expect {
148
+ subject.transfer_domain(account_id, "example.com", attributes)
149
+ }.to raise_error(Dnsimple::RequestError)
150
+ end
152
151
  end
153
152
 
154
- it "returns the extended attributes" do
155
- results = subject.extended_attributes("uk")
156
-
157
- expect(results).to be_a(Array)
158
- expect(results.size).to eq(4)
153
+ context "when :auth_info wasn't provided and is required by the TLD" do
154
+ it "raises a BadRequestError" do
155
+ stub_request(:post, %r[/v2/#{account_id}/registrar/domains/.+/transfer$])
156
+ .to_return(read_http_fixture("transferDomain/error-missing-authcode.http"))
159
157
 
160
- result = results[0]
161
- expect(result).to be_a(Dnsimple::Struct::ExtendedAttribute)
162
- expect(result.name).to eq("uk_legal_type")
163
- expect(result.description).to eq("Legal type of registrant contact")
164
- expect(result.required).to eq(false)
165
- expect(result.options).to be_a(Array)
166
- expect(result.options.size).to eq(17)
167
-
168
- option = result.options[0]
169
- expect(option.title).to eq("UK Individual")
170
- expect(option.value).to eq("IND")
171
- expect(option.description).to eq("UK Individual (our default value)")
158
+ expect {
159
+ subject.transfer_domain(account_id, "example.com", registrant_id: 10)
160
+ }.to raise_error(Dnsimple::RequestError)
161
+ end
172
162
  end
173
163
  end
174
164
 
165
+ describe "#transfer_domain_out" do
166
+ let(:account_id) { 1010 }
175
167
 
176
- describe "#prices" do
177
168
  before do
178
- stub_request(:get, %r[/v1/prices$]).
179
- to_return(read_fixture("registrar/prices/success.http"))
169
+ stub_request(:post, %r[/v2/#{account_id}/registrar/domains/.+/transfer_out$])
170
+ .to_return(read_http_fixture("transferDomainOut/success.http"))
180
171
  end
181
172
 
182
173
  it "builds the correct request" do
183
- subject.prices
174
+ subject.transfer_domain_out(account_id, domain_name = "example.com")
184
175
 
185
- expect(WebMock).to have_requested(:get, "https://api.zone/v1/prices").
186
- with(headers: { 'Accept' => 'application/json' })
176
+ expect(WebMock).to have_requested(:post, "https://api.dnsimple.test/v2/#{account_id}/registrar/domains/#{domain_name}/transfer_out")
177
+ .with(headers: { "Accept" => "application/json" })
187
178
  end
188
179
 
189
- it "returns the prices" do
190
- results = subject.prices
180
+ it "returns nothing" do
181
+ response = subject.transfer_domain_out(account_id, "example.com")
182
+ expect(response).to be_a(Dnsimple::Response)
191
183
 
192
- expect(results).to be_a(Array)
193
- expect(results.size).to be > 0
194
-
195
- results.each do |result|
196
- expect(result).to be_a(Dnsimple::Struct::Price)
197
- expect(result.tld).to be_a(String)
198
- end
184
+ result = response.data
185
+ expect(result).to be_nil
199
186
  end
200
187
  end
201
188