maremma 3.1 → 3.1.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/CHANGELOG.md +7 -0
- data/Gemfile.lock +1 -1
- data/lib/maremma/version.rb +1 -1
- data/lib/maremma.rb +16 -6
- data/spec/maremma_spec.rb +34 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab2e7075facc4988175f758e582800b7479f3554
|
4
|
+
data.tar.gz: 99b3bf7a5d806867588e8e3384a003c2233ded50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b98eb05622984eab0c819f0650341127f93b1b58b83ccadaf121af8535227a54b6924a364e8e36d52bd1dce726d5d4307c2481644c8ac06f9ad2f9dcc697665a
|
7
|
+
data.tar.gz: 130bdf89a39c65dec55c9c3b48fd5ed8b8f9f10ac8ca63662b9ae44e72d152aaca3e7a6a7f54ba95afea47cc5ae03f6c8caa5a4e5ed7c0a6bd1599962cbca3a2
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## v.3.1.1 (January 2, 2017)
|
2
|
+
|
3
|
+
[maremma 3.1.1](https://github.com/datacite/maremma/releases/tag/v.3.1.1) was released on January 2, 2017:
|
4
|
+
|
5
|
+
* added option to disable redirects by setting `limit` to 0.
|
6
|
+
* return status code for errors
|
7
|
+
|
1
8
|
## v.3.1 (December 10, 2016)
|
2
9
|
|
3
10
|
[maremma 3.1](https://github.com/datacite/maremma/releases/tag/v.3.1) was released on December 10, 2016:
|
data/Gemfile.lock
CHANGED
data/lib/maremma/version.rb
CHANGED
data/lib/maremma.rb
CHANGED
@@ -34,7 +34,9 @@ module Maremma
|
|
34
34
|
headers: response.headers,
|
35
35
|
status: response.status)
|
36
36
|
rescue *NETWORKABLE_EXCEPTIONS => error
|
37
|
-
|
37
|
+
error_response = rescue_faraday_error(error)
|
38
|
+
OpenStruct.new(body: error_response,
|
39
|
+
status: error_response.fetch("errors", {}).first.fetch("status", 400))
|
38
40
|
end
|
39
41
|
|
40
42
|
def self.put(url, options={})
|
@@ -52,7 +54,9 @@ module Maremma
|
|
52
54
|
headers: response.headers,
|
53
55
|
status: response.status)
|
54
56
|
rescue *NETWORKABLE_EXCEPTIONS => error
|
55
|
-
|
57
|
+
error_response = rescue_faraday_error(error)
|
58
|
+
OpenStruct.new(body: error_response,
|
59
|
+
status: error_response.fetch("errors", {}).first.fetch("status", 400))
|
56
60
|
end
|
57
61
|
|
58
62
|
def self.delete(url, options={})
|
@@ -69,7 +73,9 @@ module Maremma
|
|
69
73
|
headers: response.headers,
|
70
74
|
status: response.status)
|
71
75
|
rescue *NETWORKABLE_EXCEPTIONS => error
|
72
|
-
|
76
|
+
error_response = rescue_faraday_error(error)
|
77
|
+
OpenStruct.new(body: error_response,
|
78
|
+
status: error_response.fetch("errors", {}).first.fetch("status", 400))
|
73
79
|
end
|
74
80
|
|
75
81
|
def self.get(url, options={})
|
@@ -91,7 +97,9 @@ module Maremma
|
|
91
97
|
headers: response.headers,
|
92
98
|
status: response.status)
|
93
99
|
rescue *NETWORKABLE_EXCEPTIONS => error
|
94
|
-
|
100
|
+
error_response = rescue_faraday_error(error)
|
101
|
+
OpenStruct.new(body: error_response,
|
102
|
+
status: error_response.fetch("errors", {}).first.fetch("status", 400))
|
95
103
|
end
|
96
104
|
|
97
105
|
def self.head(url, options={})
|
@@ -112,7 +120,9 @@ module Maremma
|
|
112
120
|
OpenStruct.new(headers: response.headers,
|
113
121
|
status: response.status)
|
114
122
|
rescue *NETWORKABLE_EXCEPTIONS => error
|
115
|
-
|
123
|
+
error_response = rescue_faraday_error(error)
|
124
|
+
OpenStruct.new(body: error_response,
|
125
|
+
status: error_response.fetch("errors", {}).first.fetch("status", 400))
|
116
126
|
end
|
117
127
|
|
118
128
|
def self.faraday_conn(options = {})
|
@@ -127,7 +137,7 @@ module Maremma
|
|
127
137
|
c.headers['Content-type'] = options[:headers]['Content-type'] if options[:headers]['Content-type'].present?
|
128
138
|
c.headers['Accept'] = options[:headers]['Accept']
|
129
139
|
c.headers['User-Agent'] = options[:headers]['User-Agent']
|
130
|
-
c.use FaradayMiddleware::FollowRedirects, limit: limit, cookie: :all
|
140
|
+
c.use FaradayMiddleware::FollowRedirects, limit: limit, cookie: :all if limit > 0
|
131
141
|
c.request :multipart
|
132
142
|
c.request :json if options[:headers]['Accept'] == 'application/json'
|
133
143
|
c.use Faraday::Response::RaiseError
|
data/spec/maremma_spec.rb
CHANGED
@@ -32,6 +32,14 @@ describe Maremma do
|
|
32
32
|
expect(stub).to have_been_requested
|
33
33
|
end
|
34
34
|
|
35
|
+
it "head html" do
|
36
|
+
stub = stub_request(:head, url).to_return(:body => data.to_s, :status => 200, :headers => { "Content-Type" => "text/html" })
|
37
|
+
response = subject.head(url, accept: 'html')
|
38
|
+
expect(response.body).to be_nil
|
39
|
+
expect(response.headers).to eq("Content-Type"=>"text/html")
|
40
|
+
expect(stub).to have_been_requested
|
41
|
+
end
|
42
|
+
|
35
43
|
it "post xml" do
|
36
44
|
stub = stub_request(:post, url).with(:body => post_data.to_xml).to_return(:body => data.to_xml, :status => 200, :headers => { "Content-Type" => "text/html" })
|
37
45
|
subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(Hash.from_xml(response.body.to_s)["hash"]).to eq(data) }
|
@@ -142,6 +150,13 @@ describe Maremma do
|
|
142
150
|
expect(stub).to have_been_requested
|
143
151
|
end
|
144
152
|
|
153
|
+
it "head html" do
|
154
|
+
stub = stub_request(:head, url).to_return(:body => error.to_s, :status => [404], :headers => { "Content-Type" => "text/html" })
|
155
|
+
response = subject.head(url, accept: 'html')
|
156
|
+
expect(response.status).to eq(404)
|
157
|
+
expect(stub).to have_been_requested
|
158
|
+
end
|
159
|
+
|
145
160
|
it "post xml" do
|
146
161
|
stub = stub_request(:post, url).with(:body => post_data.to_xml).to_return(:body => error.to_xml, :status => [404], :headers => { "Content-Type" => "application/xml" })
|
147
162
|
subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(Hash.from_xml(response.to_s)["hash"]).to eq(error) }
|
@@ -177,6 +192,13 @@ describe Maremma do
|
|
177
192
|
expect(stub).to have_been_requested
|
178
193
|
end
|
179
194
|
|
195
|
+
it "head html" do
|
196
|
+
stub = stub_request(:head, url).to_return(:status => [408])
|
197
|
+
response = subject.head(url, accept: 'html')
|
198
|
+
expect(response.status).to eq(408)
|
199
|
+
expect(stub).to have_been_requested
|
200
|
+
end
|
201
|
+
|
180
202
|
it "post xml" do
|
181
203
|
stub = stub_request(:post, url).with(:body => post_data.to_xml).to_return(:status => [408])
|
182
204
|
subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(response.body).to be_nil }
|
@@ -190,15 +212,6 @@ describe Maremma do
|
|
190
212
|
end
|
191
213
|
end
|
192
214
|
|
193
|
-
context "head" do
|
194
|
-
it "head" do
|
195
|
-
stub = stub_request(:head, url).to_return(:status => 200, :headers => { "Content-Type" => "application/json" })
|
196
|
-
response = subject.head(url)
|
197
|
-
expect(response.headers).to eq("Content-Type"=>"application/json")
|
198
|
-
expect(stub).to have_been_requested
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
215
|
context "delete" do
|
203
216
|
it "delete" do
|
204
217
|
stub = stub_request(:delete, url).to_return(:status => 204, :headers => { "Content-Type" => "text/html" })
|
@@ -344,6 +357,18 @@ describe Maremma do
|
|
344
357
|
response = subject.get(url, limit: 1)
|
345
358
|
expect(response.body).to eq("errors"=>[{"status"=>400, "title"=>"too many redirects; last one to: http://www.example.org/redirect/x"}])
|
346
359
|
end
|
360
|
+
|
361
|
+
it "redirect limit 0" do
|
362
|
+
stub_request(:get, url).to_return(status: 301, headers: { location: redirect_url })
|
363
|
+
response = subject.get(url, limit: 0)
|
364
|
+
expect(response.headers["Location"]).to eq("http://www.example.org/redirect")
|
365
|
+
end
|
366
|
+
|
367
|
+
it "redirect limit 0 head" do
|
368
|
+
stub_request(:head, url).to_return(status: 301, headers: { location: redirect_url })
|
369
|
+
response = subject.head(url, limit: 0)
|
370
|
+
expect(response.headers["Location"]).to eq("http://www.example.org/redirect")
|
371
|
+
end
|
347
372
|
end
|
348
373
|
|
349
374
|
context "content negotiation" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maremma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Fenner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|