dnsimple 3.0.0.pre.beta2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +13 -0
- data/.rubocop_dnsimple.yml +216 -0
- data/.rubocop_todo.yml +14 -0
- data/CHANGELOG.md +16 -1
- data/Gemfile +1 -0
- data/Rakefile +8 -3
- data/lib/dnsimple/client.rb +9 -12
- data/lib/dnsimple/client/clients.rb +36 -2
- data/lib/dnsimple/client/contacts.rb +6 -6
- data/lib/dnsimple/client/domains.rb +5 -5
- data/lib/dnsimple/client/identity.rb +2 -2
- data/lib/dnsimple/client/oauth.rb +2 -2
- data/lib/dnsimple/client/registrar.rb +1 -1
- data/lib/dnsimple/client/registrar_auto_renewal.rb +2 -2
- data/lib/dnsimple/client/registrar_delegation.rb +49 -0
- data/lib/dnsimple/client/registrar_whois_privacy.rb +1 -1
- data/lib/dnsimple/client/services.rb +68 -0
- data/lib/dnsimple/client/templates.rb +139 -0
- data/lib/dnsimple/client/tlds.rb +3 -3
- data/lib/dnsimple/client/webhooks.rb +4 -4
- data/lib/dnsimple/client/zones.rb +2 -2
- data/lib/dnsimple/client/zones_records.rb +1 -1
- data/lib/dnsimple/default.rb +2 -2
- data/lib/dnsimple/error.rb +14 -1
- data/lib/dnsimple/struct.rb +3 -1
- data/lib/dnsimple/struct/contact.rb +2 -2
- data/lib/dnsimple/struct/extended_attribute.rb +5 -1
- data/lib/dnsimple/struct/service.rb +64 -0
- data/lib/dnsimple/struct/template.rb +22 -0
- data/lib/dnsimple/struct/tld.rb +1 -1
- data/lib/dnsimple/version.rb +1 -1
- data/spec/dnsimple/client/client_service_spec.rb +6 -6
- data/spec/dnsimple/client/contacts_spec.rb +30 -30
- data/spec/dnsimple/client/domains_email_forwards_spec.rb +25 -25
- data/spec/dnsimple/client/domains_spec.rb +27 -27
- data/spec/dnsimple/client/identity_spec.rb +8 -8
- data/spec/dnsimple/client/oauth_spec.rb +9 -9
- data/spec/dnsimple/client/registrar_auto_renewal_spec.rb +13 -13
- data/spec/dnsimple/client/registrar_delegation_spec.rb +55 -0
- data/spec/dnsimple/client/registrar_spec.rb +29 -29
- data/spec/dnsimple/client/registrar_whois_privacy_spec.rb +16 -16
- data/spec/dnsimple/client/services_spec.rb +78 -0
- data/spec/dnsimple/client/templates_spec.rb +163 -0
- data/spec/dnsimple/client/tlds_spec.rb +22 -23
- data/spec/dnsimple/client/webhooks_spec.rb +22 -22
- data/spec/dnsimple/client/zones_records_spec.rb +40 -40
- data/spec/dnsimple/client/zones_spec.rb +12 -12
- data/spec/dnsimple/client_spec.rb +52 -44
- data/spec/dnsimple/extra_spec.rb +3 -3
- data/spec/fixtures.http/changeDomainDelegation/success.http +17 -0
- data/spec/fixtures.http/createTemplate/created.http +17 -0
- data/spec/fixtures.http/deleteTemplate/success.http +13 -0
- data/spec/fixtures.http/getDomainDelegation/success-empty.http +17 -0
- data/spec/fixtures.http/getDomainDelegation/success.http +17 -0
- data/spec/fixtures.http/getService/success.http +17 -0
- data/spec/fixtures.http/getTemplate/success.http +17 -0
- data/spec/fixtures.http/listServices/success.http +17 -0
- data/spec/fixtures.http/listTemplates/success.http +17 -0
- data/spec/fixtures.http/method-not-allowed.http +11 -0
- data/spec/fixtures.http/updateTemplate/success.http +17 -0
- metadata +41 -5
@@ -10,15 +10,15 @@ describe Dnsimple::Client, ".zones" do
|
|
10
10
|
let(:zone_id) { "example.com" }
|
11
11
|
|
12
12
|
before do
|
13
|
-
stub_request(:get, %r
|
14
|
-
|
13
|
+
stub_request(:get, %r{/v2/#{account_id}/zones/#{zone_id}/records}).
|
14
|
+
to_return(read_http_fixture("listZoneRecords/success.http"))
|
15
15
|
end
|
16
16
|
|
17
17
|
it "builds the correct request" do
|
18
18
|
subject.records(account_id, zone_id)
|
19
19
|
|
20
|
-
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones/#{zone_id}/records")
|
21
|
-
|
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
22
|
end
|
23
23
|
|
24
24
|
it "supports pagination" do
|
@@ -58,8 +58,8 @@ describe Dnsimple::Client, ".zones" do
|
|
58
58
|
|
59
59
|
context "when the zone does not exist" do
|
60
60
|
it "raises NotFoundError" do
|
61
|
-
stub_request(:get, %r
|
62
|
-
|
61
|
+
stub_request(:get, %r{/v2}).
|
62
|
+
to_return(read_http_fixture("notfound-zone.http"))
|
63
63
|
|
64
64
|
expect {
|
65
65
|
subject.records(account_id, zone_id)
|
@@ -73,8 +73,8 @@ describe Dnsimple::Client, ".zones" do
|
|
73
73
|
let(:zone_id) { "example.com" }
|
74
74
|
|
75
75
|
it "delegates to client.paginate" do
|
76
|
-
expect(subject).to receive(:paginate).with(:records, account_id, zone_id,
|
77
|
-
subject.all_records(account_id, zone_id,
|
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
78
|
end
|
79
79
|
end
|
80
80
|
|
@@ -83,8 +83,8 @@ describe Dnsimple::Client, ".zones" do
|
|
83
83
|
let(:zone_id) { "example.com" }
|
84
84
|
|
85
85
|
before do
|
86
|
-
stub_request(:post, %r
|
87
|
-
|
86
|
+
stub_request(:post, %r{/v2/#{account_id}/zones/#{zone_id}/records$}).
|
87
|
+
to_return(read_http_fixture("createZoneRecord/created.http"))
|
88
88
|
end
|
89
89
|
|
90
90
|
let(:attributes) { { type: "A", name: "www", content: "127.0.0.1" } }
|
@@ -92,9 +92,9 @@ describe Dnsimple::Client, ".zones" do
|
|
92
92
|
it "builds the correct request" do
|
93
93
|
subject.create_record(account_id, zone_id, attributes)
|
94
94
|
|
95
|
-
expect(WebMock).to have_requested(:post, "https://api.dnsimple.test/v2/#{account_id}/zones/#{zone_id}/records")
|
96
|
-
|
97
|
-
|
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
98
|
end
|
99
99
|
|
100
100
|
it "returns the record" do
|
@@ -108,8 +108,8 @@ describe Dnsimple::Client, ".zones" do
|
|
108
108
|
|
109
109
|
context "when the zone does not exist" do
|
110
110
|
it "raises NotFoundError" do
|
111
|
-
stub_request(:post, %r
|
112
|
-
|
111
|
+
stub_request(:post, %r{/v2}).
|
112
|
+
to_return(read_http_fixture("notfound-zone.http"))
|
113
113
|
|
114
114
|
expect {
|
115
115
|
subject.create_record(account_id, zone_id, attributes)
|
@@ -123,15 +123,15 @@ describe Dnsimple::Client, ".zones" do
|
|
123
123
|
let(:zone_id) { "example.com" }
|
124
124
|
|
125
125
|
before do
|
126
|
-
stub_request(:get, %r
|
127
|
-
|
126
|
+
stub_request(:get, %r{/v2/#{account_id}/zones/#{zone_id}/records/.+$}).
|
127
|
+
to_return(read_http_fixture("getZoneRecord/success.http"))
|
128
128
|
end
|
129
129
|
|
130
130
|
it "builds the correct request" do
|
131
131
|
subject.record(account_id, zone_id, record_id = 2)
|
132
132
|
|
133
|
-
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones/#{zone_id}/records/#{record_id}")
|
134
|
-
|
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
135
|
end
|
136
136
|
|
137
137
|
it "returns the record" do
|
@@ -155,8 +155,8 @@ describe Dnsimple::Client, ".zones" do
|
|
155
155
|
|
156
156
|
context "when the zone does not exist" do
|
157
157
|
it "raises NotFoundError" do
|
158
|
-
stub_request(:get, %r
|
159
|
-
|
158
|
+
stub_request(:get, %r{/v2}).
|
159
|
+
to_return(read_http_fixture("notfound-zone.http"))
|
160
160
|
|
161
161
|
expect {
|
162
162
|
subject.record(account_id, zone_id, "0")
|
@@ -166,8 +166,8 @@ describe Dnsimple::Client, ".zones" do
|
|
166
166
|
|
167
167
|
context "when the record does not exist" do
|
168
168
|
it "raises NotFoundError" do
|
169
|
-
stub_request(:get, %r
|
170
|
-
|
169
|
+
stub_request(:get, %r{/v2}).
|
170
|
+
to_return(read_http_fixture("notfound-record.http"))
|
171
171
|
|
172
172
|
expect {
|
173
173
|
subject.record(account_id, zone_id, "0")
|
@@ -181,8 +181,8 @@ describe Dnsimple::Client, ".zones" do
|
|
181
181
|
let(:zone_id) { "example.com" }
|
182
182
|
|
183
183
|
before do
|
184
|
-
stub_request(:patch, %r
|
185
|
-
|
184
|
+
stub_request(:patch, %r{/v2/#{account_id}/zones/#{zone_id}/records/.+$}).
|
185
|
+
to_return(read_http_fixture("updateZoneRecord/success.http"))
|
186
186
|
end
|
187
187
|
|
188
188
|
let(:attributes) { { content: "127.0.0.1", priority: "1" } }
|
@@ -190,9 +190,9 @@ describe Dnsimple::Client, ".zones" do
|
|
190
190
|
it "builds the correct request" do
|
191
191
|
subject.update_record(account_id, zone_id, record_id = 2, attributes)
|
192
192
|
|
193
|
-
expect(WebMock).to have_requested(:patch, "https://api.dnsimple.test/v2/#{account_id}/zones/#{zone_id}/records/#{record_id}")
|
194
|
-
|
195
|
-
|
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
196
|
end
|
197
197
|
|
198
198
|
it "returns the record" do
|
@@ -206,8 +206,8 @@ describe Dnsimple::Client, ".zones" do
|
|
206
206
|
|
207
207
|
context "when the zone does not exist" do
|
208
208
|
it "raises NotFoundError" do
|
209
|
-
stub_request(:patch, %r
|
210
|
-
|
209
|
+
stub_request(:patch, %r{/v2}).
|
210
|
+
to_return(read_http_fixture("notfound-zone.http"))
|
211
211
|
|
212
212
|
expect {
|
213
213
|
subject.update_record(account_id, zone_id, "0", {})
|
@@ -217,8 +217,8 @@ describe Dnsimple::Client, ".zones" do
|
|
217
217
|
|
218
218
|
context "when the record does not exist" do
|
219
219
|
it "raises NotFoundError" do
|
220
|
-
stub_request(:patch, %r
|
221
|
-
|
220
|
+
stub_request(:patch, %r{/v2}).
|
221
|
+
to_return(read_http_fixture("notfound-record.http"))
|
222
222
|
|
223
223
|
expect {
|
224
224
|
subject.update_record(account_id, zone_id, "0", {})
|
@@ -232,15 +232,15 @@ describe Dnsimple::Client, ".zones" do
|
|
232
232
|
let(:zone_id) { "example.com" }
|
233
233
|
|
234
234
|
before do
|
235
|
-
stub_request(:delete, %r
|
236
|
-
|
235
|
+
stub_request(:delete, %r{/v2/#{account_id}/zones/#{zone_id}/records/.+$}).
|
236
|
+
to_return(read_http_fixture("deleteZoneRecord/success.http"))
|
237
237
|
end
|
238
238
|
|
239
239
|
it "builds the correct request" do
|
240
240
|
subject.delete_record(account_id, zone_id, record_id = 2)
|
241
241
|
|
242
|
-
expect(WebMock).to have_requested(:delete, "https://api.dnsimple.test/v2/#{account_id}/zones/#{zone_id}/records/#{record_id}")
|
243
|
-
|
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
244
|
end
|
245
245
|
|
246
246
|
it "returns nothing" do
|
@@ -253,8 +253,8 @@ describe Dnsimple::Client, ".zones" do
|
|
253
253
|
|
254
254
|
context "when the zone does not exist" do
|
255
255
|
it "raises NotFoundError" do
|
256
|
-
stub_request(:delete, %r
|
257
|
-
|
256
|
+
stub_request(:delete, %r{/v2}).
|
257
|
+
to_return(read_http_fixture("notfound-zone.http"))
|
258
258
|
|
259
259
|
expect {
|
260
260
|
subject.delete_record(account_id, zone_id, "0")
|
@@ -264,8 +264,8 @@ describe Dnsimple::Client, ".zones" do
|
|
264
264
|
|
265
265
|
context "when the record does not exist" do
|
266
266
|
it "raises NotFoundError" do
|
267
|
-
stub_request(:delete, %r
|
268
|
-
|
267
|
+
stub_request(:delete, %r{/v2}).
|
268
|
+
to_return(read_http_fixture("notfound-record.http"))
|
269
269
|
|
270
270
|
expect {
|
271
271
|
subject.delete_record(account_id, zone_id, "0")
|
@@ -9,15 +9,15 @@ describe Dnsimple::Client, ".zones" do
|
|
9
9
|
let(:account_id) { 1010 }
|
10
10
|
|
11
11
|
before do
|
12
|
-
stub_request(:get, %r
|
13
|
-
|
12
|
+
stub_request(:get, %r{/v2/#{account_id}/zones}).
|
13
|
+
to_return(read_http_fixture("listZones/success.http"))
|
14
14
|
end
|
15
15
|
|
16
16
|
it "builds the correct request" do
|
17
17
|
subject.zones(account_id)
|
18
18
|
|
19
|
-
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones")
|
20
|
-
|
19
|
+
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones").
|
20
|
+
with(headers: { 'Accept' => 'application/json' })
|
21
21
|
end
|
22
22
|
|
23
23
|
it "supports pagination" do
|
@@ -60,8 +60,8 @@ describe Dnsimple::Client, ".zones" do
|
|
60
60
|
let(:account_id) { 1010 }
|
61
61
|
|
62
62
|
it "delegates to client.paginate" do
|
63
|
-
expect(subject).to receive(:paginate).with(:zones, account_id,
|
64
|
-
subject.all_zones(account_id,
|
63
|
+
expect(subject).to receive(:paginate).with(:zones, account_id, foo: "bar")
|
64
|
+
subject.all_zones(account_id, foo: "bar")
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -69,15 +69,15 @@ describe Dnsimple::Client, ".zones" do
|
|
69
69
|
let(:account_id) { 1010 }
|
70
70
|
|
71
71
|
before do
|
72
|
-
stub_request(:get, %r
|
73
|
-
|
72
|
+
stub_request(:get, %r{/v2/#{account_id}/zones/.+$}).
|
73
|
+
to_return(read_http_fixture("getZone/success.http"))
|
74
74
|
end
|
75
75
|
|
76
76
|
it "builds the correct request" do
|
77
77
|
subject.zone(account_id, zone = "example.com")
|
78
78
|
|
79
|
-
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones/#{zone}")
|
80
|
-
|
79
|
+
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/zones/#{zone}").
|
80
|
+
with(headers: { 'Accept' => 'application/json' })
|
81
81
|
end
|
82
82
|
|
83
83
|
it "returns the zone" do
|
@@ -96,8 +96,8 @@ describe Dnsimple::Client, ".zones" do
|
|
96
96
|
|
97
97
|
context "when the zone does not exist" do
|
98
98
|
it "raises NotFoundError" do
|
99
|
-
stub_request(:get, %r
|
100
|
-
|
99
|
+
stub_request(:get, %r{/v2}).
|
100
|
+
to_return(read_http_fixture("notfound-zone.http"))
|
101
101
|
|
102
102
|
expect {
|
103
103
|
subject.zone(account_id, "example.com")
|
@@ -26,7 +26,7 @@ describe Dnsimple::Client do
|
|
26
26
|
|
27
27
|
describe "authentication" do
|
28
28
|
it "uses HTTP authentication if there's a password provided" do
|
29
|
-
stub_request(:any, %r
|
29
|
+
stub_request(:any, %r{/test})
|
30
30
|
|
31
31
|
subject = described_class.new(username: "user", password: "pass")
|
32
32
|
subject.execute(:get, "test", {})
|
@@ -34,24 +34,14 @@ describe Dnsimple::Client do
|
|
34
34
|
expect(WebMock).to have_requested(:get, "https://user:pass@api.dnsimple.com/test")
|
35
35
|
end
|
36
36
|
|
37
|
-
it "uses header authentication if there's a domain api token provided" do
|
38
|
-
stub_request(:any, %r[/test])
|
39
|
-
|
40
|
-
subject = described_class.new(domain_api_token: "domaintoken")
|
41
|
-
subject.execute(:get, "test", {})
|
42
|
-
|
43
|
-
expect(WebMock).to have_requested(:get, "https://api.dnsimple.com/test").
|
44
|
-
with { |req| req.headers["X-Dnsimple-Domain-Token"] == "domaintoken" }
|
45
|
-
end
|
46
|
-
|
47
37
|
it "uses access token if there's an access token provided" do
|
48
|
-
stub_request(:any, %r
|
38
|
+
stub_request(:any, %r{/test})
|
49
39
|
|
50
40
|
subject = described_class.new(access_token: "access-token")
|
51
41
|
subject.execute(:get, "test", {})
|
52
42
|
|
53
43
|
expect(WebMock).to have_requested(:get, "https://api.dnsimple.com/test").
|
54
|
-
|
44
|
+
with { |req| req.headers["Authorization"] == "Bearer access-token" }
|
55
45
|
end
|
56
46
|
|
57
47
|
it "raises an error if there's no password, domain token or access token provided" do
|
@@ -65,7 +55,7 @@ describe Dnsimple::Client do
|
|
65
55
|
|
66
56
|
describe "#get" do
|
67
57
|
it "delegates to #request" do
|
68
|
-
expect(subject).to receive(:execute).with(:get, "path", nil,
|
58
|
+
expect(subject).to receive(:execute).with(:get, "path", nil, foo: "bar").and_return(:returned)
|
69
59
|
expect(subject.get("path", foo: "bar")).to eq(:returned)
|
70
60
|
end
|
71
61
|
end
|
@@ -101,13 +91,28 @@ describe Dnsimple::Client do
|
|
101
91
|
describe "#execute" do
|
102
92
|
subject { described_class.new(username: "user", password: "pass") }
|
103
93
|
|
104
|
-
it "raises RequestError in case of error" do
|
105
|
-
stub_request(:
|
106
|
-
|
94
|
+
it "raises RequestError in case of error with a JSON response" do
|
95
|
+
stub_request(:post, %r{/foo}).to_return(read_http_fixture("transferDomain/error-indnsimple.http"))
|
96
|
+
|
97
|
+
expect {
|
98
|
+
subject.execute(:post, "foo", {})
|
99
|
+
}.to raise_error(Dnsimple::RequestError, "The domain google.com is already in DNSimple and cannot be added")
|
100
|
+
end
|
101
|
+
|
102
|
+
it "raises RequestError in case of error with an HTML response" do
|
103
|
+
stub_request(:get, %r{/foo}).to_return(read_http_fixture("badgateway.http"))
|
107
104
|
|
108
105
|
expect {
|
109
106
|
subject.execute(:get, "foo", {})
|
110
|
-
}.to raise_error(Dnsimple::RequestError, "
|
107
|
+
}.to raise_error(Dnsimple::RequestError, "502 Bad Gateway")
|
108
|
+
end
|
109
|
+
|
110
|
+
it "raises RequestError in absence of content types" do
|
111
|
+
stub_request(:put, %r{/foo}).to_return(read_http_fixture("method-not-allowed.http"))
|
112
|
+
|
113
|
+
expect {
|
114
|
+
subject.execute(:put, "foo", {})
|
115
|
+
}.to raise_error(Dnsimple::RequestError, "405 Method Not Allowed")
|
111
116
|
end
|
112
117
|
end
|
113
118
|
|
@@ -115,53 +120,56 @@ describe Dnsimple::Client do
|
|
115
120
|
subject { described_class.new(username: "user", password: "pass") }
|
116
121
|
|
117
122
|
it "performs a request" do
|
118
|
-
stub_request(:get, %r
|
123
|
+
stub_request(:get, %r{/foo})
|
119
124
|
|
120
125
|
subject.request(:get, 'foo', {})
|
121
126
|
|
122
127
|
expect(WebMock).to have_requested(:get, "https://user:pass@api.dnsimple.com/foo").
|
123
|
-
|
128
|
+
with(headers: { 'Accept' => 'application/json', 'User-Agent' => "dnsimple-ruby/#{Dnsimple::VERSION}" })
|
124
129
|
end
|
125
130
|
|
126
131
|
it "delegates to HTTParty" do
|
127
|
-
stub_request(:get, %r
|
132
|
+
stub_request(:get, %r{/foo})
|
128
133
|
|
129
134
|
expect(HTTParty).to receive(:get).
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
135
|
+
with(
|
136
|
+
"#{subject.base_url}foo",
|
137
|
+
format: :json,
|
138
|
+
basic_auth: { username: "user", password: "pass" },
|
139
|
+
headers: { 'Accept' => 'application/json', 'User-Agent' => "dnsimple-ruby/#{Dnsimple::VERSION}" }
|
140
|
+
).
|
141
|
+
and_return(double('response', code: 200))
|
136
142
|
|
137
143
|
subject.request(:get, 'foo')
|
138
144
|
end
|
139
145
|
|
140
146
|
it "properly extracts processes options and encodes data" do
|
141
147
|
expect(HTTParty).to receive(:put).
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
148
|
+
with(
|
149
|
+
"#{subject.base_url}foo",
|
150
|
+
format: :json,
|
151
|
+
body: JSON.dump(something: "else"),
|
152
|
+
query: { foo: "bar" },
|
153
|
+
basic_auth: { username: "user", password: "pass" },
|
154
|
+
headers: { 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'User-Agent' => "dnsimple-ruby/#{Dnsimple::VERSION}", "Custom" => "Header" }
|
155
|
+
).
|
156
|
+
and_return(double('response', code: 200))
|
150
157
|
|
151
158
|
subject.request(:put, 'foo', { something: "else" }, { query: { foo: "bar" }, headers: { "Custom" => "Header" } })
|
152
159
|
end
|
153
160
|
|
154
161
|
it "handles non application/json content types" do
|
155
162
|
expect(HTTParty).to receive(:post).
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
163
|
+
with(
|
164
|
+
"#{subject.base_url}foo",
|
165
|
+
format: :json,
|
166
|
+
body: { something: "else" },
|
167
|
+
basic_auth: { username: "user", password: "pass" },
|
168
|
+
headers: { 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => "dnsimple-ruby/#{Dnsimple::VERSION}" }
|
169
|
+
).
|
170
|
+
and_return(double('response', code: 200))
|
171
|
+
|
172
|
+
subject.request(:post, 'foo', { something: "else" }, { headers: { "Content-Type" => "application/x-www-form-urlencoded" } })
|
165
173
|
end
|
166
174
|
end
|
167
175
|
|
data/spec/dnsimple/extra_spec.rb
CHANGED
@@ -22,17 +22,17 @@ describe Dnsimple::Extra do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
describe ".validate_mandatory_attributes" do
|
25
|
-
let(:mandatory_attributes) { %i
|
25
|
+
let(:mandatory_attributes) { %i(name email) }
|
26
26
|
|
27
27
|
it "raises an error if a mandatory attribute is not present " do
|
28
28
|
expect {
|
29
|
-
described_class.validate_mandatory_attributes({name: "foo"}, mandatory_attributes)
|
29
|
+
described_class.validate_mandatory_attributes({ name: "foo" }, mandatory_attributes)
|
30
30
|
}.to raise_error(ArgumentError, ":email is required")
|
31
31
|
end
|
32
32
|
|
33
33
|
it "does not raise an error if all attributes are present" do
|
34
34
|
expect {
|
35
|
-
described_class.validate_mandatory_attributes({name: "foo", email: "bar"}, mandatory_attributes)
|
35
|
+
described_class.validate_mandatory_attributes({ name: "foo", email: "bar" }, mandatory_attributes)
|
36
36
|
}.not_to raise_error
|
37
37
|
end
|
38
38
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Server: nginx
|
3
|
+
Date: Thu, 24 Mar 2016 11:17:01 GMT
|
4
|
+
Content-Type: application/json; charset=utf-8
|
5
|
+
Transfer-Encoding: chunked
|
6
|
+
Connection: keep-alive
|
7
|
+
Status: 200 OK
|
8
|
+
X-RateLimit-Limit: 2400
|
9
|
+
X-RateLimit-Remaining: 2392
|
10
|
+
X-RateLimit-Reset: 1458821049
|
11
|
+
ETag: W/"cb540984f806b12ac437cc1f76092f90"
|
12
|
+
Cache-Control: max-age=0, private, must-revalidate
|
13
|
+
X-Request-Id: 0ea7bdd2-63ca-4eef-9c41-4a83d2fe0067
|
14
|
+
X-Runtime: 2.845860
|
15
|
+
Strict-Transport-Security: max-age=31536000
|
16
|
+
|
17
|
+
{"data":["ns1.dnsimple.com","ns2.dnsimple.com","ns3.dnsimple.com","ns4.dnsimple.com"]}
|