maremma 2.2.2 → 2.3
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 +8 -8
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +3 -3
- data/README.md +1 -1
- data/lib/maremma.rb +27 -18
- data/lib/maremma/version.rb +1 -1
- data/spec/fixtures/vcr_cassettes/Maremma/content_negotiation/redirects_to_URL.yml +775 -0
- data/spec/fixtures/vcr_cassettes/Maremma/content_negotiation/returns_content_as_bibtex.yml +87 -0
- data/spec/fixtures/vcr_cassettes/Maremma/get/get_json_with_params.yml +1200 -534
- data/spec/maremma_spec.rb +40 -23
- metadata +4 -2
data/spec/maremma_spec.rb
CHANGED
@@ -5,6 +5,7 @@ describe Maremma do
|
|
5
5
|
let(:url) { "http://example.org" }
|
6
6
|
let(:data) { { "name" => "Fred" } }
|
7
7
|
let(:post_data) { { "name" => "Jack" } }
|
8
|
+
let(:accept_header) { "text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5" }
|
8
9
|
|
9
10
|
context "get" do
|
10
11
|
it "get json" do
|
@@ -47,9 +48,9 @@ describe Maremma do
|
|
47
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")
|
48
49
|
response = subject.get(url)
|
49
50
|
facet_fields = response.fetch("data", {}).fetch("facet_counts", {}).fetch("facet_fields", {})
|
50
|
-
expect(facet_fields["datacentre_facet"]).to eq(["CDL.DPLANET - Data-Planet",
|
51
|
-
expect(facet_fields["resourceType_facet"]).to eq(["Dataset",
|
52
|
-
expect(facet_fields["publicationYear"]).to eq(["2015",
|
51
|
+
expect(facet_fields["datacentre_facet"]).to eq(["CDL.DPLANET - Data-Planet", 862673, "BL.CCDC - The Cambridge Crystallographic Data Centre", 617281, "ETHZ.SEALS - E-Periodica", 511747, "ESTDOI.BIO - TÜ Loodusmuuseum", 487448, "CDL.DIGSCI - Digital Science", 431015, "TIB.R-GATE - ResearchGate", 391313, "GESIS.DIE - Deutsches Institut für Erwachsenenbildung", 373193, "ETHZ.EPICS-BA - E-Pics Bildarchiv", 355076, "TIB.PANGAEA - PANGAEA - Publishing Network for Geoscientific and Environmental Data", 346849, "BL.IMPERIAL - Imperial College London", 190482])
|
52
|
+
expect(facet_fields["resourceType_facet"]).to eq(["Dataset", 2598715, "Text", 1390919, "Other", 873873, "Image", 704151, "Collection", 351593, "Software", 15895, "Audiovisual", 7098, "Event", 6711, "PhysicalObject", 6680, "Film", 920, "Model", 556, "InteractiveResource", 372, "Sound", 243, "Workflow", 221, "Service", 21])
|
53
|
+
expect(facet_fields["publicationYear"]).to eq(["2015", 2040850, "2014", 936486, "2016", 522234, "2011", 339370, "2013", 335358, "2012", 214191, "2005", 163347, "2007", 159146, "2006", 146147, "2010", 144512])
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
@@ -227,6 +228,22 @@ describe Maremma do
|
|
227
228
|
end
|
228
229
|
end
|
229
230
|
|
231
|
+
context "content negotiation" do
|
232
|
+
it "redirects to URL", vcr: true do
|
233
|
+
url = "http://doi.org/10.5281/ZENODO.21430"
|
234
|
+
response = subject.get(url)
|
235
|
+
doc = Nokogiri::HTML(response.fetch("data", ""))
|
236
|
+
title = doc.at_css("head title").text
|
237
|
+
expect(title).to eq("DataCite-ORCID: 1.0 - Zenodo")
|
238
|
+
end
|
239
|
+
|
240
|
+
it "returns content as bibtex", vcr: true do
|
241
|
+
url = "https://doi.org/10.5281/ZENODO.21430"
|
242
|
+
response = subject.get(url, content_type: "application/x-bibtex")
|
243
|
+
expect(response.fetch("data", nil)).to eq("@data{198243d2-ed8a-4126-867e-5fff1e80dcfc,\n doi = {10.5281/ZENODO.21430},\n url = {http://dx.doi.org/10.5281/ZENODO.21430},\n author = {Martin Fenner; Karl Jonathan Ward; Gudmundur A. Thorisson; Robert Peters; },\n publisher = {Zenodo},\n title = {DataCite-ORCID: 1.0},\n year = {2015}\n}")
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
230
247
|
context 'parse_error_response' do
|
231
248
|
it 'json' do
|
232
249
|
string = '{ "error": "An error occured." }'
|
@@ -266,58 +283,58 @@ describe Maremma do
|
|
266
283
|
end
|
267
284
|
end
|
268
285
|
|
269
|
-
context '
|
286
|
+
context 'accept headers' do
|
270
287
|
it 'default' do
|
271
|
-
|
272
|
-
expect(
|
273
|
-
|
288
|
+
headers = subject.set_request_headers(url)
|
289
|
+
expect(headers).to eq("Accept"=>"text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5",
|
290
|
+
"User-Agent"=>"Maremma - https://github.com/datacite/maremma")
|
274
291
|
end
|
275
292
|
|
276
293
|
it 'json' do
|
277
|
-
|
278
|
-
expect(
|
279
|
-
|
294
|
+
headers = subject.set_request_headers(url, content_type: 'json')
|
295
|
+
expect(headers).to eq("Accept"=>"application/json",
|
296
|
+
"User-Agent"=>"Maremma - https://github.com/datacite/maremma")
|
280
297
|
end
|
281
298
|
|
282
299
|
it 'xml' do
|
283
|
-
|
284
|
-
expect(
|
285
|
-
|
300
|
+
headers = subject.set_request_headers(url, content_type: 'xml')
|
301
|
+
expect(headers).to eq("Accept"=>"application/xml",
|
302
|
+
"User-Agent"=>"Maremma - https://github.com/datacite/maremma")
|
286
303
|
end
|
287
304
|
|
288
305
|
it 'html' do
|
289
|
-
|
290
|
-
expect(
|
291
|
-
|
306
|
+
headers = subject.set_request_headers(url, content_type: 'html')
|
307
|
+
expect(headers).to eq("Accept" => "text/html; charset=UTF-8",
|
308
|
+
"User-Agent" => "Maremma - https://github.com/datacite/maremma")
|
292
309
|
end
|
293
310
|
|
294
311
|
it 'other' do
|
295
|
-
|
296
|
-
expect(
|
297
|
-
|
312
|
+
headers = subject.set_request_headers(url, content_type: 'application/x-bibtex')
|
313
|
+
expect(headers).to eq("Accept" => "application/x-bibtex",
|
314
|
+
"User-Agent" => "Maremma - https://github.com/datacite/maremma")
|
298
315
|
end
|
299
316
|
end
|
300
317
|
|
301
318
|
context 'authentication' do
|
302
319
|
it 'no auth' do
|
303
320
|
options = {}
|
304
|
-
expect(subject.set_request_headers(url, options)).to eq("
|
321
|
+
expect(subject.set_request_headers(url, options)).to eq("User-Agent"=>"Maremma - https://github.com/datacite/maremma", "Accept"=>accept_header)
|
305
322
|
end
|
306
323
|
|
307
324
|
it 'bearer' do
|
308
325
|
options = { bearer: 'mF_9.B5f-4.1JqM' }
|
309
|
-
expect(subject.set_request_headers(url, options)).to eq("
|
326
|
+
expect(subject.set_request_headers(url, options)).to eq("User-Agent"=>"Maremma - https://github.com/datacite/maremma", "Accept"=>accept_header, "Authorization"=>"Bearer mF_9.B5f-4.1JqM")
|
310
327
|
end
|
311
328
|
|
312
329
|
it 'token' do
|
313
330
|
options = { token: '12345' }
|
314
|
-
expect(subject.set_request_headers(url, options)).to eq("
|
331
|
+
expect(subject.set_request_headers(url, options)).to eq("User-Agent"=>"Maremma - https://github.com/datacite/maremma", "Accept"=>accept_header, "Authorization"=>"Token token=12345")
|
315
332
|
end
|
316
333
|
|
317
334
|
it 'basic' do
|
318
335
|
options = { username: 'foo', password: '12345' }
|
319
336
|
basic = Base64.encode64("foo:12345")
|
320
|
-
expect(subject.set_request_headers(url, options)).to eq("
|
337
|
+
expect(subject.set_request_headers(url, options)).to eq("User-Agent"=>"Maremma - https://github.com/datacite/maremma", "Accept"=>accept_header, "Authorization"=>"Basic #{basic}")
|
321
338
|
end
|
322
339
|
end
|
323
340
|
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.3'
|
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-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -257,6 +257,8 @@ files:
|
|
257
257
|
- lib/maremma.rb
|
258
258
|
- lib/maremma/version.rb
|
259
259
|
- maremma.gemspec
|
260
|
+
- spec/fixtures/vcr_cassettes/Maremma/content_negotiation/redirects_to_URL.yml
|
261
|
+
- spec/fixtures/vcr_cassettes/Maremma/content_negotiation/returns_content_as_bibtex.yml
|
260
262
|
- spec/fixtures/vcr_cassettes/Maremma/get/get_json_with_params.yml
|
261
263
|
- spec/maremma_spec.rb
|
262
264
|
- spec/spec_helper.rb
|