maremma 3.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/maremma.rb +15 -1
- data/lib/maremma/version.rb +1 -1
- data/spec/maremma_spec.rb +44 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d377e378aad9759ac9f218ba16377509339c029c
|
4
|
+
data.tar.gz: 1dafc2fd5db389a50dc4b7d60a7d80ef5731b4f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d342a26a0519b9396614f3f191b19ee2644c9f31b52a56053dd4d1e548b1f42cafef377704c56b11b527096e54cd728d129af7e57e7636cd471ff0523e9e7ad
|
7
|
+
data.tar.gz: 83768b5fec5c5cd51f10bebfa94ed0bd0cb3b577fd895350e28ab784606cabb02c1468ed1dec10fcbb25c25bd2a272160745e20622d3b8e8ae9527d1ab938216
|
data/Gemfile.lock
CHANGED
data/lib/maremma.rb
CHANGED
@@ -38,7 +38,21 @@ module Maremma
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def self.put(url, options={})
|
41
|
-
|
41
|
+
options[:data] ||= {}
|
42
|
+
options[:headers] = set_request_headers(url, options)
|
43
|
+
|
44
|
+
conn = faraday_conn(options)
|
45
|
+
|
46
|
+
conn.options[:timeout] = options[:timeout] || DEFAULT_TIMEOUT
|
47
|
+
|
48
|
+
response = conn.put url, {}, options[:headers] do |request|
|
49
|
+
request.body = options[:data]
|
50
|
+
end
|
51
|
+
OpenStruct.new(body: parse_success_response(response.body),
|
52
|
+
headers: response.headers,
|
53
|
+
status: response.status)
|
54
|
+
rescue *NETWORKABLE_EXCEPTIONS => error
|
55
|
+
OpenStruct.new(body: rescue_faraday_error(error))
|
42
56
|
end
|
43
57
|
|
44
58
|
def self.delete(url, options={})
|
data/lib/maremma/version.rb
CHANGED
data/spec/maremma_spec.rb
CHANGED
@@ -38,6 +38,12 @@ describe Maremma do
|
|
38
38
|
expect(stub).to have_been_requested
|
39
39
|
end
|
40
40
|
|
41
|
+
it "put xml" do
|
42
|
+
stub = stub_request(:put, url).with(:body => post_data.to_xml).to_return(:body => data.to_xml, :status => 200, :headers => { "Content-Type" => "text/html" })
|
43
|
+
subject.put(url, accept: 'xml', data: post_data.to_xml) { |response| expect(Hash.from_xml(response.body.to_s)["hash"]).to eq(data) }
|
44
|
+
expect(stub).to have_been_requested
|
45
|
+
end
|
46
|
+
|
41
47
|
it "get json with params", vcr: true do
|
42
48
|
params = { q: "*:*",
|
43
49
|
fl: "doi,title,description,publisher,publicationYear,resourceType,resourceTypeGeneral,rightsURI,datacentre_symbol,xml,minted,updated",
|
@@ -96,6 +102,12 @@ describe Maremma do
|
|
96
102
|
subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(response.body).to eq("data" => nil) }
|
97
103
|
expect(stub).to have_been_requested
|
98
104
|
end
|
105
|
+
|
106
|
+
it "put xml" do
|
107
|
+
stub = stub_request(:put, url).with(:body => post_data.to_xml).to_return(:body => nil, :status => 200, :headers => { "Content-Type" => "application/xml" })
|
108
|
+
subject.put(url, accept: 'xml', data: post_data.to_xml) { |response| expect(response.body).to eq("data" => nil) }
|
109
|
+
expect(stub).to have_been_requested
|
110
|
+
end
|
99
111
|
end
|
100
112
|
|
101
113
|
context "not found" do
|
@@ -127,6 +139,12 @@ describe Maremma do
|
|
127
139
|
subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(Hash.from_xml(response.to_s)["hash"]).to eq(error) }
|
128
140
|
expect(stub).to have_been_requested
|
129
141
|
end
|
142
|
+
|
143
|
+
it "put xml" do
|
144
|
+
stub = stub_request(:put, url).with(:body => post_data.to_xml).to_return(:body => error.to_xml, :status => [404], :headers => { "Content-Type" => "application/xml" })
|
145
|
+
subject.put(url, accept: 'xml', data: post_data.to_xml) { |response| expect(Hash.from_xml(response.to_s)["hash"]).to eq(error) }
|
146
|
+
expect(stub).to have_been_requested
|
147
|
+
end
|
130
148
|
end
|
131
149
|
|
132
150
|
context "request timeout" do
|
@@ -156,6 +174,12 @@ describe Maremma do
|
|
156
174
|
subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(response.body).to be_nil }
|
157
175
|
expect(stub).to have_been_requested
|
158
176
|
end
|
177
|
+
|
178
|
+
it "put xml" do
|
179
|
+
stub = stub_request(:put, url).with(:body => post_data.to_xml).to_return(:status => [408])
|
180
|
+
subject.put(url, accept: 'xml', data: post_data.to_xml) { |response| expect(response.body).to be_nil }
|
181
|
+
expect(stub).to have_been_requested
|
182
|
+
end
|
159
183
|
end
|
160
184
|
|
161
185
|
context "head" do
|
@@ -173,6 +197,7 @@ describe Maremma do
|
|
173
197
|
response = subject.delete(url)
|
174
198
|
expect(response.body).to eq("data"=>nil)
|
175
199
|
expect(response.headers).to eq("Content-Type"=>"text/html")
|
200
|
+
expect(response.status).to eq(204)
|
176
201
|
expect(stub).to have_been_requested
|
177
202
|
end
|
178
203
|
end
|
@@ -204,6 +229,12 @@ describe Maremma do
|
|
204
229
|
subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(response.body).to be_nil }
|
205
230
|
expect(stub).to have_been_requested
|
206
231
|
end
|
232
|
+
|
233
|
+
it "put xml" do
|
234
|
+
stub = stub_request(:put, url).with(:body => post_data.to_xml).to_raise(Faraday::ConnectionFailed.new("Connection refused - connect(2)"))
|
235
|
+
subject.put(url, accept: 'xml', data: post_data.to_xml) { |response| expect(response.body).to be_nil }
|
236
|
+
expect(stub).to have_been_requested
|
237
|
+
end
|
207
238
|
end
|
208
239
|
|
209
240
|
context "request timeout internal" do
|
@@ -233,6 +264,12 @@ describe Maremma do
|
|
233
264
|
subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(response.body).to be_nil }
|
234
265
|
expect(stub).to have_been_requested
|
235
266
|
end
|
267
|
+
|
268
|
+
it "put xml" do
|
269
|
+
stub = stub_request(:put, url).with(:body => post_data.to_xml).to_timeout
|
270
|
+
subject.put(url, accept: 'xml', data: post_data.to_xml) { |response| expect(response.body).to be_nil }
|
271
|
+
expect(stub).to have_been_requested
|
272
|
+
end
|
236
273
|
end
|
237
274
|
|
238
275
|
context "rate limit exceeded" do
|
@@ -263,6 +300,13 @@ describe Maremma do
|
|
263
300
|
subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(response.body).to be_nil }
|
264
301
|
expect(stub).to have_been_requested
|
265
302
|
end
|
303
|
+
|
304
|
+
it "put xml" do
|
305
|
+
stub = stub_request(:put, url).with(:body => post_data.to_xml)
|
306
|
+
.to_return(status: 200, headers: { 'X-Rate-Limit-Remaining' => 3 })
|
307
|
+
subject.put(url, accept: 'xml', data: post_data.to_xml) { |response| expect(response.body).to be_nil }
|
308
|
+
expect(stub).to have_been_requested
|
309
|
+
end
|
266
310
|
end
|
267
311
|
|
268
312
|
context "redirect requests" do
|