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,119 @@
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
+
8
+ describe "#whois_privacy" do
9
+ let(:account_id) { 1010 }
10
+
11
+ before do
12
+ stub_request(:get, %r[/v2/#{account_id}/registrar/domains/.+/whois_privacy$])
13
+ .to_return(read_http_fixture("getWhoisPrivacy/success.http"))
14
+ end
15
+
16
+ it "builds the correct request" do
17
+ subject.whois_privacy(account_id, domain_name = "example.com")
18
+
19
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/registrar/domains/#{domain_name}/whois_privacy")
20
+ .with(headers: { "Accept" => "application/json" })
21
+ end
22
+
23
+ it "returns the whois privacy" do
24
+ response = subject.whois_privacy(account_id, "example.com")
25
+ expect(response).to be_a(Dnsimple::Response)
26
+
27
+ result = response.data
28
+ expect(result).to be_a(Dnsimple::Struct::WhoisPrivacy)
29
+ expect(result.domain_id).to be_kind_of(Fixnum)
30
+ expect(result.enabled).to be_truthy
31
+ expect(result.expires_on).to be_kind_of(String)
32
+ end
33
+ end
34
+
35
+ describe "#enable_whois_privacy" do
36
+ let(:account_id) { 1010 }
37
+
38
+ context "when the whois privacy had already been purchased" do
39
+ before do
40
+ stub_request(:put, %r[/v2/#{account_id}/registrar/domains/.+/whois_privacy$])
41
+ .to_return(read_http_fixture("enableWhoisPrivacy/success.http"))
42
+ end
43
+
44
+ it "builds the correct request" do
45
+ subject.enable_whois_privacy(account_id, domain_name = "example.com")
46
+
47
+ expect(WebMock).to have_requested(:put, "https://api.dnsimple.test/v2/#{account_id}/registrar/domains/#{domain_name}/whois_privacy")
48
+ .with(headers: { "Accept" => "application/json" })
49
+ end
50
+
51
+ it "returns the whois privacy" do
52
+ response = subject.enable_whois_privacy(account_id, "example.com")
53
+ expect(response).to be_a(Dnsimple::Response)
54
+ expect(response.http_response.code).to eq(200)
55
+
56
+ result = response.data
57
+ expect(result).to be_a(Dnsimple::Struct::WhoisPrivacy)
58
+ expect(result.domain_id).to be_kind_of(Fixnum)
59
+ expect(result.enabled).to be_truthy
60
+ expect(result.expires_on).to be_kind_of(String)
61
+ end
62
+ end
63
+
64
+ context "when the whois privacy is newly purchased" do
65
+ before do
66
+ stub_request(:put, %r[/v2/#{account_id}/registrar/domains/.+/whois_privacy$])
67
+ .to_return(read_http_fixture("enableWhoisPrivacy/created.http"))
68
+ end
69
+
70
+ it "builds the correct request" do
71
+ subject.enable_whois_privacy(account_id, domain_name = "example.com")
72
+
73
+ expect(WebMock).to have_requested(:put, "https://api.dnsimple.test/v2/#{account_id}/registrar/domains/#{domain_name}/whois_privacy")
74
+ .with(headers: { "Accept" => "application/json" })
75
+ end
76
+
77
+ it "returns the whois privacy" do
78
+ response = subject.enable_whois_privacy(account_id, "example.com")
79
+ expect(response).to be_a(Dnsimple::Response)
80
+ expect(response.http_response.code).to eq(201)
81
+
82
+ result = response.data
83
+ expect(result).to be_a(Dnsimple::Struct::WhoisPrivacy)
84
+ expect(result.domain_id).to be_kind_of(Fixnum)
85
+ expect(result.enabled).to be_nil
86
+ expect(result.expires_on).to be_nil
87
+ end
88
+ end
89
+ end
90
+
91
+
92
+ describe "#disable_whois_privacy" do
93
+ let(:account_id) { 1010 }
94
+
95
+ before do
96
+ stub_request(:delete, %r[/v2/#{account_id}/registrar/domains/.+/whois_privacy$])
97
+ .to_return(read_http_fixture("disableWhoisPrivacy/success.http"))
98
+ end
99
+
100
+ it "builds the correct request" do
101
+ subject.disable_whois_privacy(account_id, domain_name = "example.com")
102
+
103
+ expect(WebMock).to have_requested(:delete, "https://api.dnsimple.test/v2/#{account_id}/registrar/domains/#{domain_name}/whois_privacy")
104
+ .with(headers: { "Accept" => "application/json" })
105
+ end
106
+
107
+ it "returns the whois privacy" do
108
+ response = subject.disable_whois_privacy(account_id, "example.com")
109
+ expect(response).to be_a(Dnsimple::Response)
110
+
111
+ result = response.data
112
+ expect(result).to be_a(Dnsimple::Struct::WhoisPrivacy)
113
+ expect(result.domain_id).to be_kind_of(Fixnum)
114
+ expect(result.enabled).to be_falsey
115
+ expect(result.expires_on).to be_kind_of(String)
116
+ end
117
+ end
118
+
119
+ end
@@ -0,0 +1,139 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dnsimple::Client, ".tlds" do
4
+ subject { described_class.new(base_url: "https://api.dnsimple.test", access_token: "a1b2c3").tlds }
5
+
6
+ describe "#tlds" do
7
+ before do
8
+ stub_request(:get, %r[/v2/tlds])
9
+ .to_return(read_http_fixture("listTlds/success.http"))
10
+ end
11
+
12
+ it "builds the correct request" do
13
+ subject.tlds
14
+
15
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/tlds")
16
+ .with(headers: { 'Accept' => 'application/json' })
17
+ end
18
+
19
+ it "supports pagination" do
20
+ subject.tlds(query: { page: 2 })
21
+
22
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/tlds?page=2")
23
+ end
24
+
25
+ it "supports additional options" do
26
+ subject.tlds(query: { foo: "bar" })
27
+
28
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/tlds?foo=bar")
29
+ end
30
+
31
+ it "returns the tlds" do
32
+ response = subject.tlds
33
+
34
+ expect(response).to be_a(Dnsimple::PaginatedResponse)
35
+ expect(response.data).to be_an(Array)
36
+ expect(response.data.size).to eq(2)
37
+
38
+ response.data.each do |result|
39
+ expect(result).to be_a(Dnsimple::Struct::Tld)
40
+ expect(result.tld_type).to be_a(Fixnum)
41
+ expect(result.tld).to be_a(String)
42
+ end
43
+ end
44
+
45
+ it "exposes the pagination information" do
46
+ response = subject.tlds
47
+
48
+ expect(response.respond_to?(:page)).to be_truthy
49
+ expect(response.page).to eq(1)
50
+ expect(response.per_page).to be_a(Fixnum)
51
+ expect(response.total_entries).to be_a(Fixnum)
52
+ expect(response.total_pages).to be_a(Fixnum)
53
+ end
54
+ end
55
+
56
+ describe "#all_tlds" do
57
+ it "delegates to client.paginate" do
58
+ expect(subject).to receive(:paginate).with(:tlds, { foo: "bar" })
59
+ subject.all_tlds({ foo: "bar" })
60
+ end
61
+ end
62
+
63
+ describe "#tld" do
64
+ before do
65
+ stub_request(:get, %r[/v2/tlds/.+$])
66
+ .to_return(read_http_fixture("getTld/success.http"))
67
+ end
68
+
69
+ it "builds the correct request" do
70
+ subject.tld(tld = "com")
71
+
72
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/tlds/#{tld}")
73
+ .with(headers: { 'Accept' => 'application/json' })
74
+ end
75
+
76
+ it "returns the tld" do
77
+ response = subject.tld("com")
78
+ expect(response).to be_a(Dnsimple::Response)
79
+
80
+ result = response.data
81
+ expect(result).to be_a(Dnsimple::Struct::Tld)
82
+ expect(result.tld).to eq('com')
83
+ expect(result.tld_type).to eq(1)
84
+ expect(result.whois_privacy).to eq(true)
85
+ expect(result.auto_renew_only).to eq(false)
86
+ expect(result.idn).to eq(true)
87
+ end
88
+ end
89
+
90
+ describe "#extended_attributes" do
91
+ before do
92
+ stub_request(:get, %r[/v2/tlds/uk/extended_attributes$])
93
+ .to_return(read_http_fixture("getTldExtendedAttributes/success.http"))
94
+ end
95
+
96
+ it "builds the correct request" do
97
+ subject.extended_attributes(tld = "uk")
98
+
99
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/tlds/#{tld}/extended_attributes")
100
+ .with(headers: { 'Accept' => 'application/json' })
101
+ end
102
+
103
+ it "returns the extended attributes" do
104
+ response = subject.extended_attributes("uk")
105
+ expect(response).to be_a(Dnsimple::CollectionResponse)
106
+
107
+ response.data.each do |result|
108
+ expect(result).to be_a(Dnsimple::Struct::ExtendedAttribute)
109
+ expect(result.name).to be_a(String)
110
+ expect(result.description).to be_a(String)
111
+ expect(result).to respond_to(:required)
112
+
113
+ if !result.options.empty?
114
+ result.options.each do |option|
115
+ expect(option).to be_a(Dnsimple::Struct::ExtendedAttribute::Option)
116
+ expect(option.title).to be_a(String)
117
+ expect(option.value).to be_a(String)
118
+ expect(option.description).to be_a(String)
119
+ end
120
+ end
121
+ end
122
+ end
123
+
124
+ context "when there are no extended attributes for a TLD" do
125
+ before do
126
+ stub_request(:get, %r[/v2/tlds/com/extended_attributes$])
127
+ .to_return(read_http_fixture("getTldExtendedAttributes/success-noattributes.http"))
128
+ end
129
+
130
+ it "returns an empty CollectionResponse" do
131
+ response = subject.extended_attributes("com")
132
+ expect(response).to be_a(Dnsimple::CollectionResponse)
133
+
134
+ result = response.data
135
+ expect(result).to be_empty
136
+ end
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,142 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dnsimple::Client, ".webhooks" do
4
+
5
+ subject { described_class.new(base_url: "https://api.dnsimple.test", access_token: "a1b2c3").webhooks }
6
+
7
+ describe "#webhooks" do
8
+ let(:account_id) { 1010 }
9
+
10
+ before do
11
+ stub_request(:get, %r[/v2/#{account_id}/webhooks])
12
+ .to_return(read_http_fixture("listWebhooks/success.http"))
13
+ end
14
+
15
+ it "builds the correct request" do
16
+ subject.webhooks(account_id)
17
+
18
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/webhooks")
19
+ .with(headers: { 'Accept' => 'application/json' })
20
+ end
21
+
22
+ it "supports extra request options" do
23
+ subject.webhooks(account_id, query: { foo: "bar" })
24
+
25
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/webhooks?foo=bar")
26
+ end
27
+
28
+ it "returns the webhooks" do
29
+ response = subject.webhooks(account_id)
30
+
31
+ expect(response).to be_a(Dnsimple::CollectionResponse)
32
+ expect(response.data).to be_a(Array)
33
+ expect(response.data.size).to eq(2)
34
+
35
+ response.data.each do |result|
36
+ expect(result).to be_a(Dnsimple::Struct::Webhook)
37
+ expect(result.id).to be_a(Fixnum)
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "#create_webhook" do
43
+ let(:account_id) { 1010 }
44
+
45
+ before do
46
+ stub_request(:post, %r[/v2/#{account_id}/webhooks$])
47
+ .to_return(read_http_fixture("createWebhook/created.http"))
48
+ end
49
+
50
+ let(:attributes) { {url: "https://webhook.test"} }
51
+
52
+ it "builds the correct request" do
53
+ subject.create_webhook(account_id, attributes)
54
+
55
+ expect(WebMock).to have_requested(:post, "https://api.dnsimple.test/v2/#{account_id}/webhooks")
56
+ .with(body: attributes)
57
+ .with(headers: { 'Accept' => 'application/json' })
58
+ end
59
+
60
+ it "returns the webhook" do
61
+ response = subject.create_webhook(account_id, attributes)
62
+ expect(response).to be_a(Dnsimple::Response)
63
+
64
+ result = response.data
65
+ expect(result).to be_a(Dnsimple::Struct::Webhook)
66
+ expect(result.id).to be_a(Fixnum)
67
+ end
68
+ end
69
+
70
+ describe "#webhook" do
71
+ let(:account_id) { 1010 }
72
+
73
+ before do
74
+ stub_request(:get, %r[/v2/#{account_id}/webhooks/.+$])
75
+ .to_return(read_http_fixture("getWebhook/success.http"))
76
+ end
77
+
78
+ it "builds the correct request" do
79
+ subject.webhook(account_id, webhook_id = "1")
80
+
81
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/webhooks/#{webhook_id}")
82
+ .with(headers: { 'Accept' => 'application/json' })
83
+ end
84
+
85
+ it "returns the webhook" do
86
+ response = subject.webhook(account_id, 1)
87
+ expect(response).to be_a(Dnsimple::Response)
88
+
89
+ result = response.data
90
+ expect(result).to be_a(Dnsimple::Struct::Webhook)
91
+ expect(result.id).to eq(1)
92
+ expect(result.url).to eq("https://webhook.test")
93
+ end
94
+
95
+ context "when the webhook does not exist" do
96
+ it "raises NotFoundError" do
97
+ stub_request(:get, %r[/v2])
98
+ .to_return(read_http_fixture("notfound-webhook.http"))
99
+
100
+ expect {
101
+ subject.webhook(account_id, 0)
102
+ }.to raise_error(Dnsimple::NotFoundError)
103
+ end
104
+ end
105
+ end
106
+
107
+ describe "#delete_webhook" do
108
+ let(:account_id) { 1010 }
109
+
110
+ before do
111
+ stub_request(:delete, %r[/v2/#{account_id}/webhooks/.+$])
112
+ .to_return(read_http_fixture("deleteWebhook/success.http"))
113
+ end
114
+
115
+ it "builds the correct request" do
116
+ subject.delete_webhook(account_id, webhook_id = "1")
117
+
118
+ expect(WebMock).to have_requested(:delete, "https://api.dnsimple.test/v2/#{account_id}/webhooks/#{webhook_id}")
119
+ .with(headers: { 'Accept' => 'application/json' })
120
+ end
121
+
122
+ it "returns nothing" do
123
+ response = subject.delete_webhook(account_id, 1)
124
+ expect(response).to be_a(Dnsimple::Response)
125
+
126
+ result = response.data
127
+ expect(result).to be_nil
128
+ end
129
+
130
+ context "when the webhook does not exist" do
131
+ it "raises NotFoundError" do
132
+ stub_request(:delete, %r[/v2])
133
+ .to_return(read_http_fixture("notfound-webhook.http"))
134
+
135
+ expect {
136
+ subject.delete_webhook(account_id, 0)
137
+ }.to raise_error(Dnsimple::NotFoundError)
138
+ end
139
+ end
140
+ end
141
+
142
+ end
@@ -0,0 +1,277 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dnsimple::Client, ".zones" do
4
+
5
+ subject { described_class.new(base_url: "https://api.dnsimple.test", access_token: "a1b2c3").zones }
6
+
7
+
8
+ describe "#records" do
9
+ let(:account_id) { 1010 }
10
+ let(:zone_id) { "example.com" }
11
+
12
+ before do
13
+ stub_request(:get, %r[/v2/#{account_id}/zones/#{zone_id}/records])
14
+ .to_return(read_http_fixture("listZoneRecords/success.http"))
15
+ end
16
+
17
+ it "builds the correct request" do
18
+ subject.records(account_id, zone_id)
19
+
20
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones/#{zone_id}/records")
21
+ .with(headers: { 'Accept' => 'application/json' })
22
+ end
23
+
24
+ it "supports pagination" do
25
+ subject.records(account_id, zone_id, query: { page: 2 })
26
+
27
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones/#{zone_id}/records?page=2")
28
+ end
29
+
30
+ it "supports extra request options" do
31
+ subject.records(account_id, zone_id, query: { foo: "bar" })
32
+
33
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones/#{zone_id}/records?foo=bar")
34
+ end
35
+
36
+ it "returns the records" do
37
+ response = subject.records(account_id, zone_id)
38
+
39
+ expect(response).to be_a(Dnsimple::PaginatedResponse)
40
+ expect(response.data).to be_a(Array)
41
+ expect(response.data.size).to eq(5)
42
+
43
+ response.data.each do |result|
44
+ expect(result).to be_a(Dnsimple::Struct::Record)
45
+ expect(result.id).to be_a(Fixnum)
46
+ end
47
+ end
48
+
49
+ it "exposes the pagination information" do
50
+ response = subject.records(account_id, zone_id)
51
+
52
+ expect(response.respond_to?(:page)).to be_truthy
53
+ expect(response.page).to eq(1)
54
+ expect(response.per_page).to be_a(Fixnum)
55
+ expect(response.total_entries).to be_a(Fixnum)
56
+ expect(response.total_pages).to be_a(Fixnum)
57
+ end
58
+
59
+ context "when the zone does not exist" do
60
+ it "raises NotFoundError" do
61
+ stub_request(:get, %r[/v2])
62
+ .to_return(read_http_fixture("notfound-zone.http"))
63
+
64
+ expect {
65
+ subject.records(account_id, zone_id)
66
+ }.to raise_error(Dnsimple::NotFoundError)
67
+ end
68
+ end
69
+ end
70
+
71
+ describe "#all_records" do
72
+ let(:account_id) { 1010 }
73
+ let(:zone_id) { "example.com" }
74
+
75
+ it "delegates to client.paginate" do
76
+ expect(subject).to receive(:paginate).with(:records, account_id, zone_id, { foo: "bar" })
77
+ subject.all_records(account_id, zone_id, { foo: "bar" })
78
+ end
79
+ end
80
+
81
+ describe "#create_record" do
82
+ let(:account_id) { 1010 }
83
+ let(:zone_id) { "example.com" }
84
+
85
+ before do
86
+ stub_request(:post, %r[/v2/#{account_id}/zones/#{zone_id}/records$])
87
+ .to_return(read_http_fixture("createZoneRecord/created.http"))
88
+ end
89
+
90
+ let(:attributes) { { type: "A", name: "www", content: "127.0.0.1" } }
91
+
92
+ it "builds the correct request" do
93
+ subject.create_record(account_id, zone_id, attributes)
94
+
95
+ expect(WebMock).to have_requested(:post, "https://api.dnsimple.test/v2/#{account_id}/zones/#{zone_id}/records")
96
+ .with(body: attributes)
97
+ .with(headers: { 'Accept' => 'application/json' })
98
+ end
99
+
100
+ it "returns the record" do
101
+ response = subject.create_record(account_id, zone_id, attributes)
102
+ expect(response).to be_a(Dnsimple::Response)
103
+
104
+ result = response.data
105
+ expect(result).to be_a(Dnsimple::Struct::Record)
106
+ expect(result.id).to eq(64784)
107
+ end
108
+
109
+ context "when the zone does not exist" do
110
+ it "raises NotFoundError" do
111
+ stub_request(:post, %r[/v2])
112
+ .to_return(read_http_fixture("notfound-zone.http"))
113
+
114
+ expect {
115
+ subject.create_record(account_id, zone_id, attributes)
116
+ }.to raise_error(Dnsimple::NotFoundError)
117
+ end
118
+ end
119
+ end
120
+
121
+ describe "#record" do
122
+ let(:account_id) { 1010 }
123
+ let(:zone_id) { "example.com" }
124
+
125
+ before do
126
+ stub_request(:get, %r[/v2/#{account_id}/zones/#{zone_id}/records/.+$])
127
+ .to_return(read_http_fixture("getZoneRecord/success.http"))
128
+ end
129
+
130
+ it "builds the correct request" do
131
+ subject.record(account_id, zone_id, record_id = 2)
132
+
133
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones/#{zone_id}/records/#{record_id}")
134
+ .with(headers: { 'Accept' => 'application/json' })
135
+ end
136
+
137
+ it "returns the record" do
138
+ response = subject.record(account_id, zone_id, 2)
139
+ expect(response).to be_a(Dnsimple::Response)
140
+
141
+ result = response.data
142
+ expect(result).to be_a(Dnsimple::Struct::Record)
143
+ expect(result.id).to eq(64784)
144
+ expect(result.zone_id).to eq("example.com")
145
+ expect(result.parent_id).to eq(nil)
146
+ expect(result.type).to eq("A")
147
+ expect(result.name).to eq("www")
148
+ expect(result.content).to eq("127.0.0.1")
149
+ expect(result.ttl).to eq(600)
150
+ expect(result.priority).to eq(nil)
151
+ expect(result.system_record).to eq(false)
152
+ expect(result.created_at).to eq("2016-01-07T17:45:13.653Z")
153
+ expect(result.updated_at).to eq("2016-01-07T17:45:13.653Z")
154
+ end
155
+
156
+ context "when the zone does not exist" do
157
+ it "raises NotFoundError" do
158
+ stub_request(:get, %r[/v2])
159
+ .to_return(read_http_fixture("notfound-zone.http"))
160
+
161
+ expect {
162
+ subject.record(account_id, zone_id, "0")
163
+ }.to raise_error(Dnsimple::NotFoundError)
164
+ end
165
+ end
166
+
167
+ context "when the record does not exist" do
168
+ it "raises NotFoundError" do
169
+ stub_request(:get, %r[/v2])
170
+ .to_return(read_http_fixture("notfound-record.http"))
171
+
172
+ expect {
173
+ subject.record(account_id, zone_id, "0")
174
+ }.to raise_error(Dnsimple::NotFoundError)
175
+ end
176
+ end
177
+ end
178
+
179
+ describe "#update_record" do
180
+ let(:account_id) { 1010 }
181
+ let(:zone_id) { "example.com" }
182
+
183
+ before do
184
+ stub_request(:patch, %r[/v2/#{account_id}/zones/#{zone_id}/records/.+$])
185
+ .to_return(read_http_fixture("updateZoneRecord/success.http"))
186
+ end
187
+
188
+ let(:attributes) { { content: "127.0.0.1", priority: "1" } }
189
+
190
+ it "builds the correct request" do
191
+ subject.update_record(account_id, zone_id, record_id = 2, attributes)
192
+
193
+ expect(WebMock).to have_requested(:patch, "https://api.dnsimple.test/v2/#{account_id}/zones/#{zone_id}/records/#{record_id}")
194
+ .with(body: attributes)
195
+ .with(headers: { 'Accept' => 'application/json' })
196
+ end
197
+
198
+ it "returns the record" do
199
+ response = subject.update_record(account_id, zone_id, 2, attributes)
200
+ expect(response).to be_a(Dnsimple::Response)
201
+
202
+ result = response.data
203
+ expect(result).to be_a(Dnsimple::Struct::Record)
204
+ expect(result.id).to eq(64784)
205
+ end
206
+
207
+ context "when the zone does not exist" do
208
+ it "raises NotFoundError" do
209
+ stub_request(:patch, %r[/v2])
210
+ .to_return(read_http_fixture("notfound-zone.http"))
211
+
212
+ expect {
213
+ subject.update_record(account_id, zone_id, "0", {})
214
+ }.to raise_error(Dnsimple::NotFoundError)
215
+ end
216
+ end
217
+
218
+ context "when the record does not exist" do
219
+ it "raises NotFoundError" do
220
+ stub_request(:patch, %r[/v2])
221
+ .to_return(read_http_fixture("notfound-record.http"))
222
+
223
+ expect {
224
+ subject.update_record(account_id, zone_id, "0", {})
225
+ }.to raise_error(Dnsimple::NotFoundError)
226
+ end
227
+ end
228
+ end
229
+
230
+ describe "#delete_record" do
231
+ let(:account_id) { 1010 }
232
+ let(:zone_id) { "example.com" }
233
+
234
+ before do
235
+ stub_request(:delete, %r[/v2/#{account_id}/zones/#{zone_id}/records/.+$])
236
+ .to_return(read_http_fixture("deleteZoneRecord/success.http"))
237
+ end
238
+
239
+ it "builds the correct request" do
240
+ subject.delete_record(account_id, zone_id, record_id = 2)
241
+
242
+ expect(WebMock).to have_requested(:delete, "https://api.dnsimple.test/v2/#{account_id}/zones/#{zone_id}/records/#{record_id}")
243
+ .with(headers: { 'Accept' => 'application/json' })
244
+ end
245
+
246
+ it "returns nothing" do
247
+ response = subject.delete_record(account_id, zone_id, 2)
248
+ expect(response).to be_a(Dnsimple::Response)
249
+
250
+ result = response.data
251
+ expect(result).to be_nil
252
+ end
253
+
254
+ context "when the zone does not exist" do
255
+ it "raises NotFoundError" do
256
+ stub_request(:delete, %r[/v2])
257
+ .to_return(read_http_fixture("notfound-zone.http"))
258
+
259
+ expect {
260
+ subject.delete_record(account_id, zone_id, "0")
261
+ }.to raise_error(Dnsimple::NotFoundError)
262
+ end
263
+ end
264
+
265
+ context "when the record does not exist" do
266
+ it "raises NotFoundError" do
267
+ stub_request(:delete, %r[/v2])
268
+ .to_return(read_http_fixture("notfound-record.http"))
269
+
270
+ expect {
271
+ subject.delete_record(account_id, zone_id, "0")
272
+ }.to raise_error(Dnsimple::NotFoundError)
273
+ end
274
+ end
275
+ end
276
+
277
+ end