dnsimple 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -2
  3. data/README.md +5 -4
  4. data/dnsimple.gemspec +3 -3
  5. data/lib/dnsimple.rb +1 -0
  6. data/lib/dnsimple/client.rb +37 -11
  7. data/lib/dnsimple/client/accounts.rb +26 -0
  8. data/lib/dnsimple/client/clients.rb +15 -1
  9. data/lib/dnsimple/client/contacts.rb +16 -7
  10. data/lib/dnsimple/client/domains.rb +20 -6
  11. data/lib/dnsimple/client/domains_email_forwards.rb +17 -8
  12. data/lib/dnsimple/client/identity.rb +2 -5
  13. data/lib/dnsimple/client/registrar.rb +1 -1
  14. data/lib/dnsimple/client/registrar_auto_renewal.rb +2 -2
  15. data/lib/dnsimple/client/services.rb +15 -3
  16. data/lib/dnsimple/client/templates.rb +16 -4
  17. data/lib/dnsimple/client/templates_records.rb +135 -0
  18. data/lib/dnsimple/client/tlds.rb +13 -4
  19. data/lib/dnsimple/client/webhooks.rb +11 -2
  20. data/lib/dnsimple/client/zones.rb +19 -5
  21. data/lib/dnsimple/client/zones_records.rb +48 -11
  22. data/lib/dnsimple/default.rb +2 -2
  23. data/lib/dnsimple/extra.rb +3 -3
  24. data/lib/dnsimple/options.rb +53 -0
  25. data/lib/dnsimple/struct.rb +2 -0
  26. data/lib/dnsimple/struct/account.rb +3 -0
  27. data/lib/dnsimple/struct/contact.rb +0 -3
  28. data/lib/dnsimple/struct/record.rb +2 -2
  29. data/lib/dnsimple/struct/template_record.rb +34 -0
  30. data/lib/dnsimple/struct/whoami.rb +30 -0
  31. data/lib/dnsimple/version.rb +1 -1
  32. data/spec/dnsimple/client/accounts_spec.rb +31 -0
  33. data/spec/dnsimple/client/contacts_spec.rb +19 -2
  34. data/spec/dnsimple/client/domains_email_forwards_spec.rb +18 -1
  35. data/spec/dnsimple/client/domains_spec.rb +30 -1
  36. data/spec/dnsimple/client/identity_spec.rb +6 -6
  37. data/spec/dnsimple/client/services_spec.rb +30 -1
  38. data/spec/dnsimple/client/templates_records_spec.rb +226 -0
  39. data/spec/dnsimple/client/templates_spec.rb +30 -1
  40. data/spec/dnsimple/client/tlds_spec.rb +18 -1
  41. data/spec/dnsimple/client/webhooks_spec.rb +6 -0
  42. data/spec/dnsimple/client/zones_records_spec.rb +30 -1
  43. data/spec/dnsimple/client/zones_spec.rb +30 -1
  44. data/spec/dnsimple/client_spec.rb +35 -14
  45. data/spec/dnsimple/options/base_spec.rb +22 -0
  46. data/spec/dnsimple/options/list_options_spec.rb +100 -0
  47. data/spec/fixtures.http/accounts/success-account.http +21 -0
  48. data/spec/fixtures.http/accounts/success-user.http +21 -0
  49. data/spec/fixtures.http/createContact/created.http +1 -1
  50. data/spec/fixtures.http/createTemplateRecord/created.http +17 -0
  51. data/spec/fixtures.http/deleteTemplateRecord/success.http +13 -0
  52. data/spec/fixtures.http/getContact/success.http +1 -1
  53. data/spec/fixtures.http/getTemplateRecord/success.http +17 -0
  54. data/spec/fixtures.http/listContacts/success.http +1 -1
  55. data/spec/fixtures.http/listTemplateRecords/success.http +17 -0
  56. data/spec/fixtures.http/notfound-template.http +12 -0
  57. data/spec/fixtures.http/updateContact/success.http +1 -1
  58. data/spec/spec_helper.rb +0 -11
  59. metadata +35 -2
@@ -0,0 +1,226 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dnsimple::Client, ".templates" do
4
+
5
+ subject { described_class.new(base_url: "https://api.dnsimple.test", access_token: "a1b2c3").templates }
6
+
7
+
8
+ describe "#list_records" do
9
+ let(:account_id) { 1010 }
10
+ let(:template_id) { "alpha" }
11
+
12
+ before do
13
+ stub_request(:get, %r{/v2/#{account_id}/templates/#{template_id}/records}).
14
+ to_return(read_http_fixture("listTemplateRecords/success.http"))
15
+ end
16
+
17
+ it "builds the correct request" do
18
+ subject.records(account_id, template_id)
19
+
20
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/templates/#{template_id}/records").
21
+ with(headers: { "Accept" => "application/json" })
22
+ end
23
+
24
+ it "supports pagination" do
25
+ subject.records(account_id, template_id, page: 2)
26
+
27
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/templates/#{template_id}/records?page=2")
28
+ end
29
+
30
+ it "supports extra request options" do
31
+ subject.records(account_id, template_id, query: { foo: "bar" })
32
+
33
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/templates/#{template_id}/records?foo=bar")
34
+ end
35
+
36
+ it "supports sorting" do
37
+ subject.records(account_id, template_id, sort: "type:asc")
38
+
39
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/templates/#{template_id}/records?sort=type:asc")
40
+ end
41
+
42
+ it "returns the list of template's records" do
43
+ response = subject.records(account_id, template_id)
44
+ expect(response).to be_a(Dnsimple::PaginatedResponse)
45
+
46
+ response.data.each do |result|
47
+ expect(result).to be_a(Dnsimple::Struct::TemplateRecord)
48
+ expect(result.id).to be_a(Fixnum)
49
+ expect(result.type).to be_a(String)
50
+ expect(result.name).to be_a(String)
51
+ expect(result.content).to be_a(String)
52
+ end
53
+ end
54
+ end
55
+
56
+ describe "#all_templates" do
57
+ before do
58
+ stub_request(:get, %r{/v2/#{account_id}/templates/#{template_id}/records}).
59
+ to_return(read_http_fixture("listTemplateRecords/success.http"))
60
+ end
61
+
62
+ let(:account_id) { 1010 }
63
+ let(:template_id) { "alpha" }
64
+
65
+ it "delegates to client.paginate" do
66
+ expect(subject).to receive(:paginate).with(:records, account_id, template_id, option: "value")
67
+ subject.all_records(account_id, template_id, option: "value")
68
+ end
69
+
70
+ it "supports sorting" do
71
+ subject.all_records(account_id, template_id, sort: "type:asc")
72
+
73
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/templates/#{template_id}/records?page=1&per_page=100&sort=type:asc")
74
+ end
75
+ end
76
+
77
+ describe "#create_record" do
78
+ let(:account_id) { 1010 }
79
+ let(:template_id) { "alpha" }
80
+
81
+ before do
82
+ stub_request(:post, %r{/v2/#{account_id}/templates/#{template_id}/records$}).
83
+ to_return(read_http_fixture("createTemplateRecord/created.http"))
84
+ end
85
+
86
+ let(:attributes) { { type: "MX", name: "", content: "mx.example.com", priority: 10, ttl: 600 } }
87
+
88
+ it "builds the correct request" do
89
+ subject.create_record(account_id, template_id, attributes)
90
+
91
+ expect(WebMock).to have_requested(:post, "https://api.dnsimple.test/v2/#{account_id}/templates/#{template_id}/records").
92
+ with(body: attributes).
93
+ with(headers: { 'Accept' => 'application/json' })
94
+ end
95
+
96
+ it "returns the record" do
97
+ response = subject.create_record(account_id, template_id, attributes)
98
+ expect(response).to be_a(Dnsimple::Response)
99
+
100
+ result = response.data
101
+ expect(result).to be_a(Dnsimple::Struct::TemplateRecord)
102
+ expect(result.id).to eq(300)
103
+ expect(result.template_id).to eq(268)
104
+ expect(result.name).to eq("")
105
+ expect(result.type).to eq("MX")
106
+ expect(result.content).to eq("mx.example.com")
107
+ expect(result.ttl).to eq(600)
108
+ expect(result.priority).to eq(10)
109
+ expect(result.created_at).to eq("2016-05-03T07:51:33.202Z")
110
+ expect(result.updated_at).to eq("2016-05-03T07:51:33.202Z")
111
+ end
112
+
113
+ context "with missing data" do
114
+ it "raises an error when the type is missing" do
115
+ expect {
116
+ subject.create_record(account_id, template_id, name: "", content: "192.168.1.1")
117
+ }.to raise_error(ArgumentError)
118
+ end
119
+
120
+ it "raises an error when the name is missing" do
121
+ expect {
122
+ subject.create_record(account_id, template_id, type: "A", content: "192.168.1.1")
123
+ }.to raise_error(ArgumentError)
124
+ end
125
+
126
+ it "raises an error when the content is missing" do
127
+ expect {
128
+ subject.create_record(account_id, template_id, type: "A", name: "")
129
+ }.to raise_error(ArgumentError)
130
+ end
131
+ end
132
+
133
+ context "when the template does not exist" do
134
+ it "raises NotFoundError" do
135
+ stub_request(:post, %r{/v2}).
136
+ to_return(read_http_fixture("notfound-template.http"))
137
+
138
+ expect {
139
+ subject.create_record(account_id, template_id, attributes)
140
+ }.to raise_error(Dnsimple::NotFoundError)
141
+ end
142
+ end
143
+ end
144
+
145
+ describe "#record" do
146
+ let(:account_id) { 1010 }
147
+ let(:template_id) { "alpha.com" }
148
+
149
+ before do
150
+ stub_request(:get, %r{/v2/#{account_id}/templates/#{template_id}/records/.+$}).
151
+ to_return(read_http_fixture("getTemplateRecord/success.http"))
152
+ end
153
+
154
+ it "builds the correct request" do
155
+ subject.record(account_id, template_id, record_id = 301)
156
+
157
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/templates/#{template_id}/records/#{record_id}").
158
+ with(headers: { 'Accept' => 'application/json' })
159
+ end
160
+
161
+ it "returns the record" do
162
+ response = subject.record(account_id, template_id, 301)
163
+ expect(response).to be_a(Dnsimple::Response)
164
+
165
+ result = response.data
166
+ expect(result).to be_a(Dnsimple::Struct::TemplateRecord)
167
+ expect(result.id).to eq(301)
168
+ expect(result.template_id).to eq(268)
169
+ expect(result.type).to eq("MX")
170
+ expect(result.name).to eq("")
171
+ expect(result.content).to eq("mx.example.com")
172
+ expect(result.ttl).to eq(600)
173
+ expect(result.priority).to eq(10)
174
+ expect(result.created_at).to eq("2016-05-03T08:03:26.444Z")
175
+ expect(result.updated_at).to eq("2016-05-03T08:03:26.444Z")
176
+ end
177
+ end
178
+
179
+ describe "#delete_record" do
180
+ let(:account_id) { 1010 }
181
+ let(:template_id) { "example.com" }
182
+
183
+ before do
184
+ stub_request(:delete, %r{/v2/#{account_id}/templates/#{template_id}/records/.+$}).
185
+ to_return(read_http_fixture("deleteTemplateRecord/success.http"))
186
+ end
187
+
188
+ it "builds the correct request" do
189
+ subject.delete_record(account_id, template_id, record_id = 301)
190
+
191
+ expect(WebMock).to have_requested(:delete, "https://api.dnsimple.test/v2/#{account_id}/templates/#{template_id}/records/#{record_id}").
192
+ with(headers: { 'Accept' => 'application/json' })
193
+ end
194
+
195
+ it "returns nothing" do
196
+ response = subject.delete_record(account_id, template_id, 301)
197
+ expect(response).to be_a(Dnsimple::Response)
198
+
199
+ result = response.data
200
+ expect(result).to be_nil
201
+ end
202
+
203
+ context "when the template does not exist" do
204
+ it "raises NotFoundError" do
205
+ stub_request(:delete, %r{/v2}).
206
+ to_return(read_http_fixture("notfound-template.http"))
207
+
208
+ expect {
209
+ subject.delete_record(account_id, template_id, 0)
210
+ }.to raise_error(Dnsimple::NotFoundError)
211
+ end
212
+ end
213
+
214
+ context "when the record does not exist" do
215
+ it "raises NotFoundError" do
216
+ stub_request(:delete, %r{/v2}).
217
+ to_return(read_http_fixture("notfound-record.http"))
218
+
219
+ expect {
220
+ subject.delete_record(account_id, template_id, 0)
221
+ }.to raise_error(Dnsimple::NotFoundError)
222
+ end
223
+ end
224
+ end
225
+
226
+ end
@@ -9,7 +9,7 @@ describe Dnsimple::Client, ".templates" do
9
9
  let(:account_id) { 1010 }
10
10
 
11
11
  before do
12
- stub_request(:get, %r{/v2/#{account_id}/templates$}).
12
+ stub_request(:get, %r{/v2/#{account_id}/templates}).
13
13
  to_return(read_http_fixture("listTemplates/success.http"))
14
14
  end
15
15
 
@@ -20,6 +20,24 @@ describe Dnsimple::Client, ".templates" do
20
20
  with(headers: { "Accept" => "application/json" })
21
21
  end
22
22
 
23
+ it "supports pagination" do
24
+ subject.templates(account_id, page: 2)
25
+
26
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/templates?page=2")
27
+ end
28
+
29
+ it "supports extra request options" do
30
+ subject.templates(account_id, query: { foo: "bar" })
31
+
32
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/templates?foo=bar")
33
+ end
34
+
35
+ it "supports sorting" do
36
+ subject.templates(account_id, sort: "short_name:desc")
37
+
38
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/templates?sort=short_name:desc")
39
+ end
40
+
23
41
  it "returns the list of templates" do
24
42
  response = subject.list_templates(account_id)
25
43
  expect(response).to be_a(Dnsimple::CollectionResponse)
@@ -36,12 +54,23 @@ describe Dnsimple::Client, ".templates" do
36
54
  end
37
55
 
38
56
  describe "#all_templates" do
57
+ before do
58
+ stub_request(:get, %r{/v2/#{account_id}/templates}).
59
+ to_return(read_http_fixture("listTemplates/success.http"))
60
+ end
61
+
39
62
  let(:account_id) { 1010 }
40
63
 
41
64
  it "delegates to client.paginate" do
42
65
  expect(subject).to receive(:paginate).with(:templates, account_id, foo: "bar")
43
66
  subject.all_templates(account_id, foo: "bar")
44
67
  end
68
+
69
+ it "supports sorting" do
70
+ subject.all_templates(account_id, sort: "short_name:desc")
71
+
72
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/templates?page=1&per_page=100&sort=short_name:desc")
73
+ end
45
74
  end
46
75
 
47
76
  describe "#create_template" do
@@ -17,7 +17,7 @@ describe Dnsimple::Client, ".tlds" do
17
17
  end
18
18
 
19
19
  it "supports pagination" do
20
- subject.tlds(query: { page: 2 })
20
+ subject.tlds(page: 2)
21
21
 
22
22
  expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/tlds?page=2")
23
23
  end
@@ -28,6 +28,12 @@ describe Dnsimple::Client, ".tlds" do
28
28
  expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/tlds?foo=bar")
29
29
  end
30
30
 
31
+ it "supports sorting" do
32
+ subject.tlds(sort: "tld:asc")
33
+
34
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/tlds?sort=tld:asc")
35
+ end
36
+
31
37
  it "returns the tlds" do
32
38
  response = subject.tlds
33
39
 
@@ -54,10 +60,21 @@ describe Dnsimple::Client, ".tlds" do
54
60
  end
55
61
 
56
62
  describe "#all_tlds" do
63
+ before do
64
+ stub_request(:get, %r{/v2/tlds}).
65
+ to_return(read_http_fixture("listTlds/success.http"))
66
+ end
67
+
57
68
  it "delegates to client.paginate" do
58
69
  expect(subject).to receive(:paginate).with(:tlds, foo: "bar")
59
70
  subject.all_tlds(foo: "bar")
60
71
  end
72
+
73
+ it "supports sorting" do
74
+ subject.all_tlds(sort: "tld:asc")
75
+
76
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/tlds?page=1&per_page=100&sort=tld:asc")
77
+ end
61
78
  end
62
79
 
63
80
  describe "#tld" do
@@ -25,6 +25,12 @@ describe Dnsimple::Client, ".webhooks" do
25
25
  expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/webhooks?foo=bar")
26
26
  end
27
27
 
28
+ it "supports sorting" do
29
+ subject.webhooks(account_id, sort: "id:asc")
30
+
31
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/webhooks?sort=id:asc")
32
+ end
33
+
28
34
  it "returns the webhooks" do
29
35
  response = subject.webhooks(account_id)
30
36
 
@@ -22,7 +22,7 @@ describe Dnsimple::Client, ".zones" do
22
22
  end
23
23
 
24
24
  it "supports pagination" do
25
- subject.records(account_id, zone_id, query: { page: 2 })
25
+ subject.records(account_id, zone_id, page: 2)
26
26
 
27
27
  expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones/#{zone_id}/records?page=2")
28
28
  end
@@ -33,6 +33,18 @@ describe Dnsimple::Client, ".zones" do
33
33
  expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones/#{zone_id}/records?foo=bar")
34
34
  end
35
35
 
36
+ it "supports sorting" do
37
+ subject.records(account_id, zone_id, sort: "type:asc")
38
+
39
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones/#{zone_id}/records?sort=type:asc")
40
+ end
41
+
42
+ it "supports filtering" do
43
+ subject.records(account_id, zone_id, filter: { type: "A" })
44
+
45
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones/#{zone_id}/records?type=A")
46
+ end
47
+
36
48
  it "returns the records" do
37
49
  response = subject.records(account_id, zone_id)
38
50
 
@@ -69,6 +81,11 @@ describe Dnsimple::Client, ".zones" do
69
81
  end
70
82
 
71
83
  describe "#all_records" do
84
+ before do
85
+ stub_request(:get, %r{/v2/#{account_id}/zones/#{zone_id}/records}).
86
+ to_return(read_http_fixture("listZoneRecords/success.http"))
87
+ end
88
+
72
89
  let(:account_id) { 1010 }
73
90
  let(:zone_id) { "example.com" }
74
91
 
@@ -76,6 +93,18 @@ describe Dnsimple::Client, ".zones" do
76
93
  expect(subject).to receive(:paginate).with(:records, account_id, zone_id, foo: "bar")
77
94
  subject.all_records(account_id, zone_id, foo: "bar")
78
95
  end
96
+
97
+ it "supports sorting" do
98
+ subject.all_records(account_id, zone_id, sort: "type:asc")
99
+
100
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones/#{zone_id}/records?page=1&per_page=100&sort=type:asc")
101
+ end
102
+
103
+ it "supports filtering" do
104
+ subject.all_records(account_id, zone_id, filter: { name: "foo", type: "AAAA" })
105
+
106
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones/#{zone_id}/records?page=1&per_page=100&name=foo&type=AAAA")
107
+ end
79
108
  end
80
109
 
81
110
  describe "#create_record" do
@@ -21,7 +21,7 @@ describe Dnsimple::Client, ".zones" do
21
21
  end
22
22
 
23
23
  it "supports pagination" do
24
- subject.zones(account_id, query: { page: 2 })
24
+ subject.zones(account_id, page: 2)
25
25
 
26
26
  expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones?page=2")
27
27
  end
@@ -32,6 +32,18 @@ describe Dnsimple::Client, ".zones" do
32
32
  expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones?foo=bar")
33
33
  end
34
34
 
35
+ it "supports sorting" do
36
+ subject.zones(account_id, sort: "name:desc")
37
+
38
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones?sort=name:desc")
39
+ end
40
+
41
+ it "supports filtering" do
42
+ subject.zones(account_id, filter: { name_like: "example" })
43
+
44
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones?name_like=example")
45
+ end
46
+
35
47
  it "returns the zones" do
36
48
  response = subject.zones(account_id)
37
49
 
@@ -57,12 +69,29 @@ describe Dnsimple::Client, ".zones" do
57
69
  end
58
70
 
59
71
  describe "#all_zones" do
72
+ before do
73
+ stub_request(:get, %r{/v2/#{account_id}/zones}).
74
+ to_return(read_http_fixture("listZones/success.http"))
75
+ end
76
+
60
77
  let(:account_id) { 1010 }
61
78
 
62
79
  it "delegates to client.paginate" do
63
80
  expect(subject).to receive(:paginate).with(:zones, account_id, foo: "bar")
64
81
  subject.all_zones(account_id, foo: "bar")
65
82
  end
83
+
84
+ it "supports sorting" do
85
+ subject.all_zones(account_id, sort: "name:desc")
86
+
87
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones?page=1&per_page=100&sort=name:desc")
88
+ end
89
+
90
+ it "supports sorting" do
91
+ subject.all_zones(account_id, filter: { name_like: "zone.test" })
92
+
93
+ expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones?page=1&per_page=100&name_like=zone.test")
94
+ end
66
95
  end
67
96
 
68
97
  describe "#zone" do