maremma 2.0.1 → 2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +8 -2
- data/Gemfile.lock +3 -3
- data/lib/maremma.rb +18 -15
- data/lib/maremma/version.rb +1 -1
- data/spec/maremma_spec.rb +63 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDViZDYzNTdhY2FjNzhkZmFmMGE3OTY3OTMzYzg5NjI3YjEzYzVhZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjI0MjhjNTY2YWY4NWM4N2UyMzZjMzBmODBiZGJmNTdhZjcyYzhjZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Y2ZjZWNhN2JhYzUzMzQ4MzRjNGFiYWQzYTE2ZmJmZWIyN2I3MDUxNDE4ODlh
|
10
|
+
YTVjODZkOTczYjllOGRiZGI3MTAyM2Q4YmFiZWI5ZjA1NzVjYTFmMGMzYWNh
|
11
|
+
MWQ2ZTg0ZWQwZjdlODRlYWM2MGE1OWY0ODdjNDUxYTExNzY4ZDI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MWRjNmVkMmUxNTdjMzVhMTNmYTgzM2VmMDY3ZDA0ZTEwMDRkOWYyMmZlZTU1
|
14
|
+
NjNmNWY4Yjc3MTc3ZTYzZTU1Yzk2OTU0ZWFlNzU4ZDM5ZWI0MDRlMmE3MDE3
|
15
|
+
OTQ3NTExMmUxZjMwODU4NmQwYmE1YjlhMzViNjc5ZmFjZTdjMjM=
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,18 @@
|
|
1
|
+
## v.2.1 (March 5, 2016)
|
2
|
+
|
3
|
+
[maremma 2.1](https://github.com/datacite/maremma/releases/tag/v.2.1) was released on March 5, 2016:
|
4
|
+
|
5
|
+
* fixed format for token authentication: `Token token=123` instead of `Token token="123"`
|
6
|
+
|
1
7
|
## v.2.0 (January 24, 2016)
|
2
8
|
|
3
|
-
[maremma 2.0](https://github.com/datacite/maremma/releases/tag/v.2.0) was released on January 24,
|
9
|
+
[maremma 2.0](https://github.com/datacite/maremma/releases/tag/v.2.0) was released on January 24, 2016:
|
4
10
|
|
5
11
|
* return JSONAPI-friendly `errors` hash on errors, and `data` hash otherwise
|
6
12
|
|
7
13
|
## v.1.1.0 (January 5, 2016)
|
8
14
|
|
9
|
-
[maremma 1.1](https://github.com/datacite/maremma/releases/tag/v.1.1.0) was released on January 5,
|
15
|
+
[maremma 1.1](https://github.com/datacite/maremma/releases/tag/v.1.1.0) was released on January 5, 2016:
|
10
16
|
|
11
17
|
* added support for rate-limiting headers (Twitter, Github)
|
12
18
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
maremma (2.
|
4
|
+
maremma (2.1)
|
5
5
|
activesupport (~> 4.2, >= 4.2.5)
|
6
6
|
builder (~> 3.2, >= 3.2.2)
|
7
7
|
excon (~> 0.45.0)
|
@@ -15,7 +15,7 @@ PATH
|
|
15
15
|
GEM
|
16
16
|
remote: https://rubygems.org/
|
17
17
|
specs:
|
18
|
-
activesupport (4.2.5.
|
18
|
+
activesupport (4.2.5.2)
|
19
19
|
i18n (~> 0.7)
|
20
20
|
json (~> 1.7, >= 1.7.7)
|
21
21
|
minitest (~> 5.1)
|
@@ -29,7 +29,7 @@ GEM
|
|
29
29
|
excon (0.45.4)
|
30
30
|
faraday (0.9.2)
|
31
31
|
multipart-post (>= 1.2, < 3)
|
32
|
-
faraday-encoding (0.0.
|
32
|
+
faraday-encoding (0.0.2)
|
33
33
|
faraday
|
34
34
|
faraday_middleware (0.10.0)
|
35
35
|
faraday (>= 0.7.4, < 0.10)
|
data/lib/maremma.rb
CHANGED
@@ -22,11 +22,9 @@ module Maremma
|
|
22
22
|
def self.post(url, options={})
|
23
23
|
options[:content_type] ||= 'json'
|
24
24
|
options[:data] ||= {}
|
25
|
-
options[:headers]
|
26
|
-
options[:headers]['Host'] = URI.parse(url).host
|
25
|
+
options[:headers] = set_headers(url, options)
|
27
26
|
|
28
27
|
conn = faraday_conn(options[:content_type], options)
|
29
|
-
conn = auth_conn(conn, options)
|
30
28
|
|
31
29
|
conn.options[:timeout] = options[:timeout] || DEFAULT_TIMEOUT
|
32
30
|
|
@@ -40,11 +38,9 @@ module Maremma
|
|
40
38
|
|
41
39
|
def self.get(url, options={})
|
42
40
|
options[:content_type] ||= 'json'
|
43
|
-
options[:headers]
|
44
|
-
options[:headers]['Host'] = URI.parse(url).host
|
41
|
+
options[:headers] = set_headers(url, options)
|
45
42
|
|
46
43
|
conn = faraday_conn(options[:content_type], options)
|
47
|
-
conn = auth_conn(conn, options)
|
48
44
|
|
49
45
|
conn.options[:timeout] = options[:timeout] || DEFAULT_TIMEOUT
|
50
46
|
|
@@ -67,12 +63,14 @@ module Maremma
|
|
67
63
|
"json" => 'application/json' }
|
68
64
|
accept_header = content_types.fetch(content_type, content_type)
|
69
65
|
|
66
|
+
user_agent = ENV['HOSTNAME'].present? ? "Maremma - http://#{ENV['HOSTNAME']}" : "Maremma - https://github.com/datacite/maremma"
|
67
|
+
|
70
68
|
# redirect limit
|
71
69
|
limit = options[:limit] || 10
|
72
70
|
|
73
71
|
Faraday.new do |c|
|
74
72
|
c.headers['Accept'] = accept_header
|
75
|
-
c.headers['User-Agent'] =
|
73
|
+
c.headers['User-Agent'] = user_agent
|
76
74
|
c.use FaradayMiddleware::FollowRedirects, limit: limit, cookie: :all
|
77
75
|
c.request :multipart
|
78
76
|
c.request :json if accept_header == 'application/json'
|
@@ -82,15 +80,20 @@ module Maremma
|
|
82
80
|
end
|
83
81
|
end
|
84
82
|
|
85
|
-
def self.
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
83
|
+
def self.set_headers(url, options)
|
84
|
+
options[:headers] ||= {}
|
85
|
+
options[:headers]['Host'] = URI.parse(url).host
|
86
|
+
|
87
|
+
if options[:bearer].present?
|
88
|
+
options[:headers]['Authorization'] = "Bearer #{options[:bearer]}"
|
89
|
+
elsif options[:token].present?
|
90
|
+
options[:headers]["Authorization"] = "Token token=#{options[:token]}"
|
91
|
+
elsif options[:username].present?
|
92
|
+
basic = Base64.encode64("#{options[:username]}:#{options[:password].to_s}")
|
93
|
+
options[:headers]["Authorization"] = "Basic #{basic}"
|
92
94
|
end
|
93
|
-
|
95
|
+
|
96
|
+
options[:headers]
|
94
97
|
end
|
95
98
|
|
96
99
|
def self.rescue_faraday_error(error)
|
data/lib/maremma/version.rb
CHANGED
data/spec/maremma_spec.rb
CHANGED
@@ -199,6 +199,14 @@ describe Maremma do
|
|
199
199
|
response = subject.get(url)
|
200
200
|
expect(response).to eq("data"=>"Test")
|
201
201
|
end
|
202
|
+
|
203
|
+
it "redirect limit 1" do
|
204
|
+
stub_request(:get, url).to_return(status: 301, headers: { location: redirect_url })
|
205
|
+
stub_request(:get, redirect_url).to_return(status: 301, headers: { location: redirect_url + "/x" })
|
206
|
+
stub_request(:get, redirect_url+ "/x").to_return(status: 301, headers: { location: redirect_url + "/y" })
|
207
|
+
response = subject.get(url, limit: 1)
|
208
|
+
expect(response).to eq("errors"=>[{"status"=>400, "title"=>"too many redirects; last one to: http://www.example.org/redirect/x"}])
|
209
|
+
end
|
202
210
|
end
|
203
211
|
|
204
212
|
context 'parse_error_response' do
|
@@ -239,4 +247,59 @@ describe Maremma do
|
|
239
247
|
expect(subject.parse_success_response(string)).to eq("data"=>"fön")
|
240
248
|
end
|
241
249
|
end
|
250
|
+
|
251
|
+
context 'connection' do
|
252
|
+
it 'default' do
|
253
|
+
conn = subject.faraday_conn
|
254
|
+
expect(conn.headers).to eq("Accept"=>"application/json",
|
255
|
+
"User-Agent"=>"Maremma - https://github.com/datacite/maremma")
|
256
|
+
end
|
257
|
+
|
258
|
+
it 'json' do
|
259
|
+
conn = subject.faraday_conn('json')
|
260
|
+
expect(conn.headers).to eq("Accept"=>"application/json",
|
261
|
+
"User-Agent"=>"Maremma - https://github.com/datacite/maremma")
|
262
|
+
end
|
263
|
+
|
264
|
+
it 'xml' do
|
265
|
+
conn = subject.faraday_conn('xml')
|
266
|
+
expect(conn.headers).to eq("Accept"=>"application/xml",
|
267
|
+
"User-Agent"=>"Maremma - https://github.com/datacite/maremma")
|
268
|
+
end
|
269
|
+
|
270
|
+
it 'html' do
|
271
|
+
conn = subject.faraday_conn('html')
|
272
|
+
expect(conn.headers).to eq("Accept" => "text/html; charset=UTF-8",
|
273
|
+
"User-Agent" => "Maremma - https://github.com/datacite/maremma")
|
274
|
+
end
|
275
|
+
|
276
|
+
it 'other' do
|
277
|
+
conn = subject.faraday_conn('application/x-bibtex')
|
278
|
+
expect(conn.headers).to eq("Accept" => "application/x-bibtex",
|
279
|
+
"User-Agent" => "Maremma - https://github.com/datacite/maremma")
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
context 'authentication' do
|
284
|
+
it 'no auth' do
|
285
|
+
options = {}
|
286
|
+
expect(subject.set_headers(url, options)).to eq("Host"=>"example.org")
|
287
|
+
end
|
288
|
+
|
289
|
+
it 'bearer' do
|
290
|
+
options = { bearer: 'mF_9.B5f-4.1JqM' }
|
291
|
+
expect(subject.set_headers(url, options)).to eq("Host"=>"example.org", "Authorization"=>"Bearer mF_9.B5f-4.1JqM")
|
292
|
+
end
|
293
|
+
|
294
|
+
it 'token' do
|
295
|
+
options = { token: '12345' }
|
296
|
+
expect(subject.set_headers(url, options)).to eq("Host"=>"example.org", "Authorization"=>"Token token=12345")
|
297
|
+
end
|
298
|
+
|
299
|
+
it 'basic' do
|
300
|
+
options = { username: 'foo', password: '12345' }
|
301
|
+
basic = Base64.encode64("foo:12345")
|
302
|
+
expect(subject.set_headers(url, options)).to eq("Host"=>"example.org", "Authorization"=>"Basic #{basic}")
|
303
|
+
end
|
304
|
+
end
|
242
305
|
end
|
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: 2.
|
4
|
+
version: '2.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: 2016-
|
11
|
+
date: 2016-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|