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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99de211de38fbb778846ba247970b691e6d3f97e
4
- data.tar.gz: cd6f9eb248255ae6d761e6788d517f294095e11a
3
+ metadata.gz: d377e378aad9759ac9f218ba16377509339c029c
4
+ data.tar.gz: 1dafc2fd5db389a50dc4b7d60a7d80ef5731b4f9
5
5
  SHA512:
6
- metadata.gz: fffd72b4ef2e73ff34fab96649b7472eccef51893a0b9c54fcb9441d21ea4c447861a78d1f2114054453a5934398f3c9de077364be72885c8f69f539d681ab11
7
- data.tar.gz: ceb1d297b65b1d9847d809b35cead4cad152c1f9b76ccdfd40d44095c8979823e38bec16d76eac119e172b1f466fb4c32d86885e109f8bf53e63b86ddc0c5dd5
6
+ metadata.gz: 3d342a26a0519b9396614f3f191b19ee2644c9f31b52a56053dd4d1e548b1f42cafef377704c56b11b527096e54cd728d129af7e57e7636cd471ff0523e9e7ad
7
+ data.tar.gz: 83768b5fec5c5cd51f10bebfa94ed0bd0cb3b577fd895350e28ab784606cabb02c1468ed1dec10fcbb25c25bd2a272160745e20622d3b8e8ae9527d1ab938216
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- maremma (3.0)
4
+ maremma (3.0.1)
5
5
  activesupport (~> 4.2, >= 4.2.5)
6
6
  builder (~> 3.2, >= 3.2.2)
7
7
  excon (~> 0.45.0)
@@ -95,4 +95,4 @@ DEPENDENCIES
95
95
  webmock (~> 1.22, >= 1.22.3)
96
96
 
97
97
  BUNDLED WITH
98
- 1.12.5
98
+ 1.13.6
data/lib/maremma.rb CHANGED
@@ -38,7 +38,21 @@ module Maremma
38
38
  end
39
39
 
40
40
  def self.put(url, options={})
41
- self.post(url, options={})
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={})
@@ -1,3 +1,3 @@
1
1
  module Maremma
2
- VERSION = "3.0"
2
+ VERSION = "3.0.1"
3
3
  end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maremma
3
3
  version: !ruby/object:Gem::Version
4
- version: '3.0'
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fenner