maremma 2.4.4 → 2.5
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 +8 -1
- data/Gemfile.lock +38 -38
- data/lib/maremma.rb +23 -8
- data/lib/maremma/version.rb +1 -1
- data/maremma.gemspec +2 -2
- data/spec/fixtures/vcr_cassettes/Maremma/content_negotiation/redirects_to_URL.yml +471 -718
- data/spec/fixtures/vcr_cassettes/Maremma/content_negotiation/returns_content_as_bibtex.yml +12 -12
- data/spec/fixtures/vcr_cassettes/Maremma/get/get_json_with_params.yml +538 -1200
- data/spec/fixtures/vcr_cassettes/Maremma/link_headers/parses_link_headers.yml +539 -0
- data/spec/maremma_spec.rb +57 -50
- metadata +9 -14
data/spec/maremma_spec.rb
CHANGED
|
@@ -11,21 +11,21 @@ describe Maremma do
|
|
|
11
11
|
it "get json" do
|
|
12
12
|
stub = stub_request(:get, url).to_return(:body => data.to_json, :status => 200, :headers => { "Content-Type" => "application/json" })
|
|
13
13
|
response = subject.get(url)
|
|
14
|
-
expect(response).to eq("data" => data)
|
|
14
|
+
expect(response).to eq("data" => data, "headers"=>{"Content-Type"=>"application/json"})
|
|
15
15
|
expect(stub).to have_been_requested
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
it "get xml" do
|
|
19
19
|
stub = stub_request(:get, url).to_return(:body => data.to_xml, :status => 200, :headers => { "Content-Type" => "application/xml" })
|
|
20
20
|
response = subject.get(url, accept: 'xml')
|
|
21
|
-
expect(response).to eq("data" =>
|
|
21
|
+
expect(response).to eq("data"=>data, "headers"=>{"Content-Type"=>"application/xml"})
|
|
22
22
|
expect(stub).to have_been_requested
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
it "get html" do
|
|
26
26
|
stub = stub_request(:get, url).to_return(:body => data.to_s, :status => 200, :headers => { "Content-Type" => "text/html" })
|
|
27
27
|
response = subject.get(url, accept: 'html')
|
|
28
|
-
expect(response).to eq("data" => data.to_s)
|
|
28
|
+
expect(response).to eq("data" => data.to_s, "headers"=>{"Content-Type"=>"text/html"})
|
|
29
29
|
expect(stub).to have_been_requested
|
|
30
30
|
end
|
|
31
31
|
|
|
@@ -48,18 +48,9 @@ describe Maremma do
|
|
|
48
48
|
expect(url).to eq("https://search.datacite.org/api?q=*%3A*&fl=doi%2Ctitle%2Cdescription%2Cpublisher%2CpublicationYear%2CresourceType%2CresourceTypeGeneral%2CrightsURI%2Cdatacentre_symbol%2Cxml%2Cminted%2Cupdated&fq=has_metadata%3Atrue&fq=is_active%3Atrue&facet=true&facet.field=resourceType_facet&facet.field=publicationYear&facet.field=datacentre_facet&facet.limit=10&f.resourceType_facet.facet.limit=15&wt=json")
|
|
49
49
|
response = subject.get(url)
|
|
50
50
|
facet_fields = response.fetch("data", {}).fetch("facet_counts", {}).fetch("facet_fields", {})
|
|
51
|
-
expect(facet_fields["datacentre_facet"]).to eq(["CDL.DPLANET - Data-Planet",
|
|
52
|
-
expect(facet_fields["resourceType_facet"]).to eq(["Dataset",
|
|
53
|
-
expect(facet_fields["publicationYear"]).to eq(["2015",
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
context "head" do
|
|
58
|
-
it "head html" do
|
|
59
|
-
stub = stub_request(:head, url).to_return(:status => 200, :headers => { "Content-Type" => "text/html" })
|
|
60
|
-
response = subject.head(url, accept: 'html')
|
|
61
|
-
expect(response).to eq("Content-Type"=>"text/html")
|
|
62
|
-
expect(stub).to have_been_requested
|
|
51
|
+
expect(facet_fields["datacentre_facet"].each_slice(2).first).to eq(["CDL.DPLANET - Data-Planet", 866179])
|
|
52
|
+
expect(facet_fields["resourceType_facet"].each_slice(2).first).to eq(["Dataset", 2868231])
|
|
53
|
+
expect(facet_fields["publicationYear"].each_slice(2).first).to eq(["2015", 2048329])
|
|
63
54
|
end
|
|
64
55
|
end
|
|
65
56
|
|
|
@@ -67,21 +58,21 @@ describe Maremma do
|
|
|
67
58
|
it "get json" do
|
|
68
59
|
stub = stub_request(:get, url).to_return(:body => nil, :status => 200, :headers => { "Content-Type" => "application/json" })
|
|
69
60
|
response = subject.get(url)
|
|
70
|
-
expect(response).to eq("data" =>
|
|
61
|
+
expect(response).to eq("data"=>nil, "headers"=>{"Content-Type"=>"application/json"})
|
|
71
62
|
expect(stub).to have_been_requested
|
|
72
63
|
end
|
|
73
64
|
|
|
74
65
|
it "get xml" do
|
|
75
66
|
stub = stub_request(:get, url).to_return(:body => nil, :status => 200, :headers => { "Content-Type" => "application/xml" })
|
|
76
67
|
response = subject.get(url, accept: 'xml')
|
|
77
|
-
expect(response).to eq("data" =>
|
|
68
|
+
expect(response).to eq("data"=>nil, "headers"=>{"Content-Type"=>"application/xml"})
|
|
78
69
|
expect(stub).to have_been_requested
|
|
79
70
|
end
|
|
80
71
|
|
|
81
72
|
it "get html" do
|
|
82
73
|
stub = stub_request(:get, url).to_return(:body => nil, :status => 200, :headers => { "Content-Type" => "text/html" })
|
|
83
74
|
response = subject.get(url, accept: 'html')
|
|
84
|
-
expect(response).to eq("data" => nil)
|
|
75
|
+
expect(response).to eq("data" => nil, "headers"=>{"Content-Type"=>"text/html"})
|
|
85
76
|
expect(stub).to have_been_requested
|
|
86
77
|
end
|
|
87
78
|
|
|
@@ -149,6 +140,24 @@ describe Maremma do
|
|
|
149
140
|
end
|
|
150
141
|
end
|
|
151
142
|
|
|
143
|
+
context "head" do
|
|
144
|
+
it "head" do
|
|
145
|
+
stub = stub_request(:head, url).to_return(:status => 200, :headers => { "Content-Type" => "application/json" })
|
|
146
|
+
response = subject.head(url)
|
|
147
|
+
expect(response).to eq("headers"=>{"Content-Type"=>"application/json"})
|
|
148
|
+
expect(stub).to have_been_requested
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
context "delete" do
|
|
153
|
+
it "delete" do
|
|
154
|
+
stub = stub_request(:delete, url).to_return(:status => 204, :headers => { "Content-Type" => "text/html" })
|
|
155
|
+
response = subject.delete(url)
|
|
156
|
+
expect(response).to eq("data"=>nil, "headers"=>{"Content-Type"=>"text/html"})
|
|
157
|
+
expect(stub).to have_been_requested
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
152
161
|
context "connection failed" do
|
|
153
162
|
it "get json" do
|
|
154
163
|
stub = stub_request(:get, url).to_raise(Faraday::ConnectionFailed.new("Connection refused - connect(2)"))
|
|
@@ -244,7 +253,7 @@ describe Maremma do
|
|
|
244
253
|
stub_request(:get, url).to_return(status: 301, headers: { location: redirect_url })
|
|
245
254
|
stub_request(:get, redirect_url).to_return(status: 200, body: "Test")
|
|
246
255
|
response = subject.get(url)
|
|
247
|
-
expect(response).to eq("data"=>"Test")
|
|
256
|
+
expect(response).to eq("data"=>"Test", "headers"=>{})
|
|
248
257
|
end
|
|
249
258
|
|
|
250
259
|
it "redirect four times" do
|
|
@@ -254,7 +263,7 @@ describe Maremma do
|
|
|
254
263
|
stub_request(:get, redirect_url+ "/y").to_return(status: 301, headers: { location: redirect_url + "/z" })
|
|
255
264
|
stub_request(:get, redirect_url + "/z").to_return(status: 200, body: "Test")
|
|
256
265
|
response = subject.get(url)
|
|
257
|
-
expect(response).to eq("data"=>"Test")
|
|
266
|
+
expect(response).to eq("data"=>"Test", "headers"=>{})
|
|
258
267
|
end
|
|
259
268
|
|
|
260
269
|
it "redirect limit 1" do
|
|
@@ -264,27 +273,30 @@ describe Maremma do
|
|
|
264
273
|
response = subject.get(url, limit: 1)
|
|
265
274
|
expect(response).to eq("errors"=>[{"status"=>400, "title"=>"too many redirects; last one to: http://www.example.org/redirect/x"}])
|
|
266
275
|
end
|
|
267
|
-
|
|
268
|
-
it "redirect limit 0 head" do
|
|
269
|
-
stub_request(:head, url).to_return(status: 301, headers: { location: redirect_url })
|
|
270
|
-
response = subject.head(url, limit: 0)
|
|
271
|
-
expect(response["Location"]).to eq("http://www.example.org/redirect")
|
|
272
|
-
end
|
|
273
276
|
end
|
|
274
277
|
|
|
275
278
|
context "content negotiation" do
|
|
276
279
|
it "redirects to URL", vcr: true do
|
|
277
|
-
url = "
|
|
280
|
+
url = "https://doi.org/10.5281/ZENODO.21430"
|
|
278
281
|
response = subject.get(url)
|
|
279
282
|
doc = Nokogiri::HTML(response.fetch("data", ""))
|
|
280
283
|
title = doc.at_css("head title").text
|
|
281
|
-
expect(title).to eq("DataCite-ORCID: 1.0
|
|
284
|
+
expect(title).to eq("DataCite-ORCID: 1.0 | Zenodo")
|
|
282
285
|
end
|
|
283
286
|
|
|
284
287
|
it "returns content as bibtex", vcr: true do
|
|
285
288
|
url = "https://doi.org/10.5281/ZENODO.21430"
|
|
286
289
|
response = subject.get(url, accept: "application/x-bibtex")
|
|
287
|
-
expect(response.fetch("data", nil)).to eq("@
|
|
290
|
+
expect(response.fetch("data", nil)).to eq("@misc{https://doi.org/10.5281/ZENODO.21430,\n doi = {10.5281/ZENODO.21430},\n url = {https://doi.org/10.5281/ZENODO.21430},\n author = {Martin Fenner and Karl Jonathan Ward and Gudmundur A. Thorisson and Robert Peters},\n publisher = {Zenodo},\n title = {DataCite-ORCID: 1.0},\n year = {2015}\n}")
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
context "link headers" do
|
|
295
|
+
it "parses link headers", vcr: true do
|
|
296
|
+
url = "https://search.datacite.org/works/10.5281/ZENODO.21430"
|
|
297
|
+
response = subject.get(url)
|
|
298
|
+
headers = response.fetch("headers", {}).fetch("Link", "").split(", ")
|
|
299
|
+
expect(headers.first).to eq("<https://doi.org/10.5281/ZENODO.21430> ; rel=\"identifier\"")
|
|
288
300
|
end
|
|
289
301
|
end
|
|
290
302
|
|
|
@@ -308,94 +320,89 @@ describe Maremma do
|
|
|
308
320
|
context 'parse_success_response' do
|
|
309
321
|
it 'from_json' do
|
|
310
322
|
string = '{ "word": "abc" }'
|
|
311
|
-
expect(subject.parse_success_response(string)).to eq("
|
|
323
|
+
expect(subject.parse_success_response(string)).to eq("word"=>"abc")
|
|
312
324
|
end
|
|
313
325
|
|
|
314
326
|
it 'from_json with data' do
|
|
315
327
|
string = '{ "data": { "word": "abc" }}'
|
|
316
|
-
expect(subject.parse_success_response(string)).to eq("
|
|
328
|
+
expect(subject.parse_success_response(string)).to eq("word"=>"abc")
|
|
317
329
|
end
|
|
318
330
|
|
|
319
331
|
it 'from_xml' do
|
|
320
332
|
string = "<word>abc</word>"
|
|
321
|
-
expect(subject.parse_success_response(string)).to eq("
|
|
333
|
+
expect(subject.parse_success_response(string)).to eq("word"=>"abc")
|
|
322
334
|
end
|
|
323
335
|
|
|
324
336
|
it 'from_string' do
|
|
325
337
|
string = "abc"
|
|
326
|
-
expect(subject.parse_success_response(string)).to eq("
|
|
338
|
+
expect(subject.parse_success_response(string)).to eq("abc")
|
|
327
339
|
end
|
|
328
340
|
|
|
329
341
|
it 'from_string with utf-8' do
|
|
330
342
|
string = "fön "
|
|
331
|
-
expect(subject.parse_success_response(string)).to eq("
|
|
343
|
+
expect(subject.parse_success_response(string)).to eq("fön")
|
|
332
344
|
end
|
|
333
345
|
end
|
|
334
346
|
|
|
335
347
|
context 'accept headers' do
|
|
336
348
|
it 'default' do
|
|
337
349
|
headers = subject.set_request_headers(url)
|
|
338
|
-
expect(headers).to eq("
|
|
339
|
-
"User-Agent"=>"Maremma - https://github.com/datacite/maremma")
|
|
350
|
+
expect(headers["Accept"]).to eq("text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5")
|
|
340
351
|
end
|
|
341
352
|
|
|
342
353
|
it 'json' do
|
|
343
354
|
headers = subject.set_request_headers(url, accept: 'json')
|
|
344
|
-
expect(headers).to eq("
|
|
345
|
-
"User-Agent"=>"Maremma - https://github.com/datacite/maremma")
|
|
355
|
+
expect(headers["Accept"]).to eq("application/json")
|
|
346
356
|
end
|
|
347
357
|
|
|
348
358
|
it 'xml' do
|
|
349
359
|
headers = subject.set_request_headers(url, accept: 'xml')
|
|
350
|
-
expect(headers).to eq("
|
|
351
|
-
"User-Agent"=>"Maremma - https://github.com/datacite/maremma")
|
|
360
|
+
expect(headers["Accept"]).to eq("application/xml")
|
|
352
361
|
end
|
|
353
362
|
|
|
354
363
|
it 'html' do
|
|
355
364
|
headers = subject.set_request_headers(url, accept: 'html')
|
|
356
|
-
expect(headers).to eq("
|
|
357
|
-
"User-Agent" => "Maremma - https://github.com/datacite/maremma")
|
|
365
|
+
expect(headers["Accept"]).to eq("text/html; charset=UTF-8")
|
|
358
366
|
end
|
|
359
367
|
|
|
360
368
|
it 'other' do
|
|
361
369
|
headers = subject.set_request_headers(url, accept: 'application/x-bibtex')
|
|
362
|
-
expect(headers).to eq("
|
|
363
|
-
"User-Agent" => "Maremma - https://github.com/datacite/maremma")
|
|
370
|
+
expect(headers["Accept"]).to eq("application/x-bibtex")
|
|
364
371
|
end
|
|
365
372
|
end
|
|
366
373
|
|
|
367
374
|
context 'authentication' do
|
|
368
375
|
it 'no auth' do
|
|
369
376
|
options = {}
|
|
370
|
-
expect(subject.set_request_headers(url, options)).to
|
|
377
|
+
expect(subject.set_request_headers(url, options)["Authorization"]).to be nil
|
|
371
378
|
end
|
|
372
379
|
|
|
373
380
|
it 'bearer' do
|
|
374
381
|
options = { bearer: 'mF_9.B5f-4.1JqM' }
|
|
375
|
-
expect(subject.set_request_headers(url, options)).to eq("
|
|
382
|
+
expect(subject.set_request_headers(url, options)["Authorization"]).to eq("Bearer mF_9.B5f-4.1JqM")
|
|
376
383
|
end
|
|
377
384
|
|
|
378
385
|
it 'token' do
|
|
379
386
|
options = { token: '12345' }
|
|
380
|
-
expect(subject.set_request_headers(url, options)).to eq("
|
|
387
|
+
expect(subject.set_request_headers(url, options)["Authorization"]).to eq("Token token=12345")
|
|
381
388
|
end
|
|
382
389
|
|
|
383
390
|
it 'basic' do
|
|
384
391
|
options = { username: 'foo', password: '12345' }
|
|
385
392
|
basic = Base64.encode64("foo:12345")
|
|
386
|
-
expect(subject.set_request_headers(url, options)).to eq("
|
|
393
|
+
expect(subject.set_request_headers(url, options)["Authorization"]).to eq("Basic #{basic}")
|
|
387
394
|
end
|
|
388
395
|
end
|
|
389
396
|
|
|
390
397
|
context 'host' do
|
|
391
398
|
it 'empty' do
|
|
392
399
|
options = {}
|
|
393
|
-
expect(subject.set_request_headers(url, options)).to
|
|
400
|
+
expect(subject.set_request_headers(url, options)["Host"]).to be nil
|
|
394
401
|
end
|
|
395
402
|
|
|
396
403
|
it 'true' do
|
|
397
404
|
options = { host: true}
|
|
398
|
-
expect(subject.set_request_headers(url, options)).to eq("
|
|
405
|
+
expect(subject.set_request_headers(url, options)["Host"]).to eq("example.org")
|
|
399
406
|
end
|
|
400
407
|
end
|
|
401
408
|
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.5'
|
|
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: 2016-11-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|
|
@@ -72,20 +72,14 @@ dependencies:
|
|
|
72
72
|
requirements:
|
|
73
73
|
- - "~>"
|
|
74
74
|
- !ruby/object:Gem::Version
|
|
75
|
-
version:
|
|
76
|
-
- - ">="
|
|
77
|
-
- !ruby/object:Gem::Version
|
|
78
|
-
version: 1.6.8
|
|
75
|
+
version: 1.6.7
|
|
79
76
|
type: :runtime
|
|
80
77
|
prerelease: false
|
|
81
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
82
79
|
requirements:
|
|
83
80
|
- - "~>"
|
|
84
81
|
- !ruby/object:Gem::Version
|
|
85
|
-
version:
|
|
86
|
-
- - ">="
|
|
87
|
-
- !ruby/object:Gem::Version
|
|
88
|
-
version: 1.6.8
|
|
82
|
+
version: 1.6.7
|
|
89
83
|
- !ruby/object:Gem::Dependency
|
|
90
84
|
name: builder
|
|
91
85
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -124,16 +118,16 @@ dependencies:
|
|
|
124
118
|
name: oj
|
|
125
119
|
requirement: !ruby/object:Gem::Requirement
|
|
126
120
|
requirements:
|
|
127
|
-
- - "
|
|
121
|
+
- - "~>"
|
|
128
122
|
- !ruby/object:Gem::Version
|
|
129
|
-
version: 2.
|
|
123
|
+
version: 2.13.1
|
|
130
124
|
type: :runtime
|
|
131
125
|
prerelease: false
|
|
132
126
|
version_requirements: !ruby/object:Gem::Requirement
|
|
133
127
|
requirements:
|
|
134
|
-
- - "
|
|
128
|
+
- - "~>"
|
|
135
129
|
- !ruby/object:Gem::Version
|
|
136
|
-
version: 2.
|
|
130
|
+
version: 2.13.1
|
|
137
131
|
- !ruby/object:Gem::Dependency
|
|
138
132
|
name: activesupport
|
|
139
133
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -294,6 +288,7 @@ files:
|
|
|
294
288
|
- spec/fixtures/vcr_cassettes/Maremma/content_negotiation/redirects_to_URL.yml
|
|
295
289
|
- spec/fixtures/vcr_cassettes/Maremma/content_negotiation/returns_content_as_bibtex.yml
|
|
296
290
|
- spec/fixtures/vcr_cassettes/Maremma/get/get_json_with_params.yml
|
|
291
|
+
- spec/fixtures/vcr_cassettes/Maremma/link_headers/parses_link_headers.yml
|
|
297
292
|
- spec/maremma_spec.rb
|
|
298
293
|
- spec/spec_helper.rb
|
|
299
294
|
homepage: https://github.com/datacite/maremma
|