cirneco 0.9.16 → 0.9.17

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.
Files changed (94) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile.lock +70 -67
  3. data/cirneco.gemspec +3 -3
  4. data/lib/cirneco/data_center.rb +0 -2
  5. data/lib/cirneco/doi.rb +2 -90
  6. data/lib/cirneco/media.rb +1 -3
  7. data/lib/cirneco/metadata.rb +0 -2
  8. data/lib/cirneco/utils.rb +3 -3
  9. data/lib/cirneco/version.rb +1 -1
  10. data/lib/cirneco/work.rb +0 -2
  11. data/spec/api_spec.rb +8 -7
  12. data/spec/doi_spec.rb +4 -63
  13. data/spec/fixtures/vcr_cassettes/Cirneco_Work/media/includes_media.yml +42 -56
  14. data/spec/fixtures/vcr_cassettes/Cirneco_Work/schema/BlogPosting.yml +42 -56
  15. data/spec/utils_spec.rb +9 -10
  16. data/spec/work_spec.rb +2 -2
  17. metadata +10 -93
  18. data/data/authors.yml +0 -0
  19. data/data/references.yaml +0 -0
  20. data/data/site.yml +0 -0
  21. data/lib/cirneco/file_utils.rb +0 -371
  22. data/resources/jats-1.1/JATS-journalpublishing1-elements.xsd +0 -8608
  23. data/resources/jats-1.1/JATS-journalpublishing1-mathml3-elements.xsd +0 -8608
  24. data/resources/jats-1.1/JATS-journalpublishing1-mathml3.xsd +0 -48
  25. data/resources/jats-1.1/JATS-journalpublishing1.xsd +0 -59
  26. data/resources/jats-1.1/module-ali.xsd +0 -46
  27. data/resources/jats-1.1/standard-modules/mathml2/common/common-attribs.xsd +0 -44
  28. data/resources/jats-1.1/standard-modules/mathml2/common/math.xsd +0 -126
  29. data/resources/jats-1.1/standard-modules/mathml2/common/xlink-href.xsd +0 -20
  30. data/resources/jats-1.1/standard-modules/mathml2/content/arith.xsd +0 -90
  31. data/resources/jats-1.1/standard-modules/mathml2/content/calculus.xsd +0 -146
  32. data/resources/jats-1.1/standard-modules/mathml2/content/common-attrib.xsd +0 -30
  33. data/resources/jats-1.1/standard-modules/mathml2/content/constants.xsd +0 -83
  34. data/resources/jats-1.1/standard-modules/mathml2/content/constructs.xsd +0 -260
  35. data/resources/jats-1.1/standard-modules/mathml2/content/elementary-functions.xsd +0 -117
  36. data/resources/jats-1.1/standard-modules/mathml2/content/functions.xsd +0 -73
  37. data/resources/jats-1.1/standard-modules/mathml2/content/linear-algebra.xsd +0 -173
  38. data/resources/jats-1.1/standard-modules/mathml2/content/logic.xsd +0 -53
  39. data/resources/jats-1.1/standard-modules/mathml2/content/relations.xsd +0 -55
  40. data/resources/jats-1.1/standard-modules/mathml2/content/semantics.xsd +0 -85
  41. data/resources/jats-1.1/standard-modules/mathml2/content/sets.xsd +0 -236
  42. data/resources/jats-1.1/standard-modules/mathml2/content/statistics.xsd +0 -136
  43. data/resources/jats-1.1/standard-modules/mathml2/content/tokens.xsd +0 -120
  44. data/resources/jats-1.1/standard-modules/mathml2/content/vector-calculus.xsd +0 -88
  45. data/resources/jats-1.1/standard-modules/mathml2/content/zzz.tokens.xsd.from.zip +0 -120
  46. data/resources/jats-1.1/standard-modules/mathml2/mathml2.xsd +0 -59
  47. data/resources/jats-1.1/standard-modules/mathml2/presentation/action.xsd +0 -44
  48. data/resources/jats-1.1/standard-modules/mathml2/presentation/characters.xsd +0 -37
  49. data/resources/jats-1.1/standard-modules/mathml2/presentation/common-attribs.xsd +0 -113
  50. data/resources/jats-1.1/standard-modules/mathml2/presentation/common-types.xsd +0 -103
  51. data/resources/jats-1.1/standard-modules/mathml2/presentation/error.xsd +0 -40
  52. data/resources/jats-1.1/standard-modules/mathml2/presentation/layout.xsd +0 -195
  53. data/resources/jats-1.1/standard-modules/mathml2/presentation/scripts.xsd +0 -186
  54. data/resources/jats-1.1/standard-modules/mathml2/presentation/space.xsd +0 -52
  55. data/resources/jats-1.1/standard-modules/mathml2/presentation/style.xsd +0 -69
  56. data/resources/jats-1.1/standard-modules/mathml2/presentation/table.xsd +0 -216
  57. data/resources/jats-1.1/standard-modules/mathml2/presentation/tokens.xsd +0 -124
  58. data/resources/jats-1.1/standard-modules/xlink.xsd +0 -100
  59. data/resources/jats-1.1/standard-modules/xml.xsd +0 -287
  60. data/spec/file_utils_spec.rb +0 -203
  61. data/spec/fixtures/apa.csl +0 -621
  62. data/spec/fixtures/authors.yml +0 -19
  63. data/spec/fixtures/cool-dois/index.html +0 -404
  64. data/spec/fixtures/cool-dois-minted/index.html +0 -359
  65. data/spec/fixtures/cool-dois-minted.html.md +0 -99
  66. data/spec/fixtures/cool-dois-missing-metadata/index.html +0 -356
  67. data/spec/fixtures/cool-dois-no-accession-number.html.md +0 -97
  68. data/spec/fixtures/cool-dois-no-json-ld/index.html +0 -352
  69. data/spec/fixtures/cool-dois.html.md +0 -100
  70. data/spec/fixtures/cool-dois.yml +0 -10
  71. data/spec/fixtures/index-minted.html +0 -271
  72. data/spec/fixtures/index.html +0 -320
  73. data/spec/fixtures/index.html.erb +0 -42
  74. data/spec/fixtures/references.bib +0 -506
  75. data/spec/fixtures/references.yaml +0 -1060
  76. data/spec/fixtures/site.yml +0 -8
  77. data/spec/fixtures/vcr_cassettes/Cirneco_DataCenter/jats/should_generate_jats_for_all_urls.yml +0 -38
  78. data/spec/fixtures/vcr_cassettes/Cirneco_DataCenter/mint_and_hide_DOIs/should_hide_for_all_urls.yml +0 -38
  79. data/spec/fixtures/vcr_cassettes/Cirneco_DataCenter/mint_and_hide_DOIs/should_mint_and_hide_for_all_urls.yml +0 -38
  80. data/spec/fixtures/vcr_cassettes/Cirneco_DataCenter/mint_and_hide_DOIs/should_mint_for_all_urls.yml +0 -38
  81. data/spec/fixtures/vcr_cassettes/Cirneco_Doi/jats/writes_jats_for_list_of_urls.yml +0 -38
  82. data/spec/fixtures/vcr_cassettes/Cirneco_Doi/mint_and_hide_DOIs/hides_dois_for_list_of_urls.yml +0 -38
  83. data/spec/fixtures/vcr_cassettes/Cirneco_Doi/mint_and_hide_DOIs/mints_and_hides_dois_for_list_of_urls.yml +0 -38
  84. data/spec/fixtures/vcr_cassettes/Cirneco_Doi/mint_and_hide_DOIs/mints_dois_for_list_of_urls.yml +0 -38
  85. data/spec/fixtures/vcr_cassettes/Cirneco_Work/DOI_API/get/should_get_all_dois.yml +0 -121
  86. data/spec/fixtures/vcr_cassettes/Cirneco_Work/DOI_API/get/should_get_doi.yml +0 -121
  87. data/spec/fixtures/vcr_cassettes/Cirneco_Work/DOI_API/get/should_get_doi_not_found.yml +0 -121
  88. data/spec/fixtures/vcr_cassettes/Cirneco_Work/DOI_API/get/username_missing.yml +0 -121
  89. data/spec/fixtures/vcr_cassettes/Cirneco_Work/DOI_API/put/should_put_doi.yml +0 -121
  90. data/spec/fixtures/vcr_cassettes/Cirneco_Work/Media_API/get/should_get_media.yml +0 -121
  91. data/spec/fixtures/vcr_cassettes/Cirneco_Work/Media_API/post/should_post_media.yml +0 -121
  92. data/spec/fixtures/vcr_cassettes/Cirneco_Work/Metadata_API/delete/should_delete_metadata.yml +0 -121
  93. data/spec/fixtures/vcr_cassettes/Cirneco_Work/Metadata_API/get/should_get_metadata.yml +0 -121
  94. data/spec/fixtures/vcr_cassettes/Cirneco_Work/Metadata_API/post/should_post_metadata.yml +0 -121
data/spec/work_spec.rb CHANGED
@@ -13,10 +13,10 @@ describe Cirneco::Work, vcr: true do
13
13
  describe 'schema' do
14
14
  it "BlogPosting" do
15
15
  expect(subject.valid?).to be true
16
- expect(subject.id).to eq("https://doi.org/10.5438/0000-01hc")
16
+ expect(subject.id).to eq("https://doi.org/10.5438/4k3m-nyvg")
17
17
  expect(subject.url).to eq("https://blog.datacite.org/eating-your-own-dog-food")
18
18
  expect(subject.type).to eq("BlogPosting")
19
- expect(subject.author).to eq("type"=>"Person", "id"=>"http://orcid.org/0000-0003-1419-2405", "name"=>"Martin Fenner", "givenName"=>"Martin", "familyName"=>"Fenner")
19
+ expect(subject.author).to eq("type"=>"Person", "id"=>"https://orcid.org/0000-0003-1419-2405", "name"=>"Martin Fenner", "givenName"=>"Martin", "familyName"=>"Fenner")
20
20
  expect(subject.title).to eq("Eating your own Dog Food")
21
21
  expect(subject.alternate_name).to eq("MS-49-3632-5083")
22
22
  expect(subject.description["text"]).to start_with("Eating your own dog food")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cirneco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.16
4
+ version: 0.9.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fenner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-10 00:00:00.000000000 Z
11
+ date: 2018-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: maremma
@@ -50,48 +50,42 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: 0.9.32
53
+ version: '0.9'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: 0.9.32
60
+ version: '0.9'
61
61
  - !ruby/object:Gem::Dependency
62
- name: base32-crockford-checksum
62
+ name: base32-url
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: 0.2.2
67
+ version: '0.3'
68
68
  type: :runtime
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: 0.2.2
74
+ version: '0.3'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: nokogiri
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '1.6'
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- version: 1.6.8
81
+ version: 1.8.1
85
82
  type: :runtime
86
83
  prerelease: false
87
84
  version_requirements: !ruby/object:Gem::Requirement
88
85
  requirements:
89
86
  - - "~>"
90
87
  - !ruby/object:Gem::Version
91
- version: '1.6'
92
- - - ">="
93
- - !ruby/object:Gem::Version
94
- version: 1.6.8
88
+ version: 1.8.1
95
89
  - !ruby/object:Gem::Dependency
96
90
  name: builder
97
91
  requirement: !ruby/object:Gem::Requirement
@@ -328,59 +322,17 @@ files:
328
322
  - Rakefile
329
323
  - bin/cirneco
330
324
  - cirneco.gemspec
331
- - data/authors.yml
332
- - data/references.yaml
333
- - data/site.yml
334
325
  - lib/cirneco.rb
335
326
  - lib/cirneco/api.rb
336
327
  - lib/cirneco/base.rb
337
328
  - lib/cirneco/cli.rb
338
329
  - lib/cirneco/data_center.rb
339
330
  - lib/cirneco/doi.rb
340
- - lib/cirneco/file_utils.rb
341
331
  - lib/cirneco/media.rb
342
332
  - lib/cirneco/metadata.rb
343
333
  - lib/cirneco/utils.rb
344
334
  - lib/cirneco/version.rb
345
335
  - lib/cirneco/work.rb
346
- - resources/jats-1.1/JATS-journalpublishing1-elements.xsd
347
- - resources/jats-1.1/JATS-journalpublishing1-mathml3-elements.xsd
348
- - resources/jats-1.1/JATS-journalpublishing1-mathml3.xsd
349
- - resources/jats-1.1/JATS-journalpublishing1.xsd
350
- - resources/jats-1.1/module-ali.xsd
351
- - resources/jats-1.1/standard-modules/mathml2/common/common-attribs.xsd
352
- - resources/jats-1.1/standard-modules/mathml2/common/math.xsd
353
- - resources/jats-1.1/standard-modules/mathml2/common/xlink-href.xsd
354
- - resources/jats-1.1/standard-modules/mathml2/content/arith.xsd
355
- - resources/jats-1.1/standard-modules/mathml2/content/calculus.xsd
356
- - resources/jats-1.1/standard-modules/mathml2/content/common-attrib.xsd
357
- - resources/jats-1.1/standard-modules/mathml2/content/constants.xsd
358
- - resources/jats-1.1/standard-modules/mathml2/content/constructs.xsd
359
- - resources/jats-1.1/standard-modules/mathml2/content/elementary-functions.xsd
360
- - resources/jats-1.1/standard-modules/mathml2/content/functions.xsd
361
- - resources/jats-1.1/standard-modules/mathml2/content/linear-algebra.xsd
362
- - resources/jats-1.1/standard-modules/mathml2/content/logic.xsd
363
- - resources/jats-1.1/standard-modules/mathml2/content/relations.xsd
364
- - resources/jats-1.1/standard-modules/mathml2/content/semantics.xsd
365
- - resources/jats-1.1/standard-modules/mathml2/content/sets.xsd
366
- - resources/jats-1.1/standard-modules/mathml2/content/statistics.xsd
367
- - resources/jats-1.1/standard-modules/mathml2/content/tokens.xsd
368
- - resources/jats-1.1/standard-modules/mathml2/content/vector-calculus.xsd
369
- - resources/jats-1.1/standard-modules/mathml2/content/zzz.tokens.xsd.from.zip
370
- - resources/jats-1.1/standard-modules/mathml2/mathml2.xsd
371
- - resources/jats-1.1/standard-modules/mathml2/presentation/action.xsd
372
- - resources/jats-1.1/standard-modules/mathml2/presentation/characters.xsd
373
- - resources/jats-1.1/standard-modules/mathml2/presentation/common-attribs.xsd
374
- - resources/jats-1.1/standard-modules/mathml2/presentation/common-types.xsd
375
- - resources/jats-1.1/standard-modules/mathml2/presentation/error.xsd
376
- - resources/jats-1.1/standard-modules/mathml2/presentation/layout.xsd
377
- - resources/jats-1.1/standard-modules/mathml2/presentation/scripts.xsd
378
- - resources/jats-1.1/standard-modules/mathml2/presentation/space.xsd
379
- - resources/jats-1.1/standard-modules/mathml2/presentation/style.xsd
380
- - resources/jats-1.1/standard-modules/mathml2/presentation/table.xsd
381
- - resources/jats-1.1/standard-modules/mathml2/presentation/tokens.xsd
382
- - resources/jats-1.1/standard-modules/xlink.xsd
383
- - resources/jats-1.1/standard-modules/xml.xsd
384
336
  - resources/kernel-4.0/include/datacite-contributorType-v4.xsd
385
337
  - resources/kernel-4.0/include/datacite-dateType-v4.xsd
386
338
  - resources/kernel-4.0/include/datacite-descriptionType-v4.xsd
@@ -404,41 +356,6 @@ files:
404
356
  - resources/kernel-4.0/samples/datacite-example-workflow-v4.0.xml
405
357
  - spec/api_spec.rb
406
358
  - spec/doi_spec.rb
407
- - spec/file_utils_spec.rb
408
- - spec/fixtures/apa.csl
409
- - spec/fixtures/authors.yml
410
- - spec/fixtures/cool-dois-minted.html.md
411
- - spec/fixtures/cool-dois-minted/index.html
412
- - spec/fixtures/cool-dois-missing-metadata/index.html
413
- - spec/fixtures/cool-dois-no-accession-number.html.md
414
- - spec/fixtures/cool-dois-no-json-ld/index.html
415
- - spec/fixtures/cool-dois.html.md
416
- - spec/fixtures/cool-dois.yml
417
- - spec/fixtures/cool-dois/index.html
418
- - spec/fixtures/index-minted.html
419
- - spec/fixtures/index.html
420
- - spec/fixtures/index.html.erb
421
- - spec/fixtures/references.bib
422
- - spec/fixtures/references.yaml
423
- - spec/fixtures/site.yml
424
- - spec/fixtures/vcr_cassettes/Cirneco_DataCenter/jats/should_generate_jats_for_all_urls.yml
425
- - spec/fixtures/vcr_cassettes/Cirneco_DataCenter/mint_and_hide_DOIs/should_hide_for_all_urls.yml
426
- - spec/fixtures/vcr_cassettes/Cirneco_DataCenter/mint_and_hide_DOIs/should_mint_and_hide_for_all_urls.yml
427
- - spec/fixtures/vcr_cassettes/Cirneco_DataCenter/mint_and_hide_DOIs/should_mint_for_all_urls.yml
428
- - spec/fixtures/vcr_cassettes/Cirneco_Doi/jats/writes_jats_for_list_of_urls.yml
429
- - spec/fixtures/vcr_cassettes/Cirneco_Doi/mint_and_hide_DOIs/hides_dois_for_list_of_urls.yml
430
- - spec/fixtures/vcr_cassettes/Cirneco_Doi/mint_and_hide_DOIs/mints_and_hides_dois_for_list_of_urls.yml
431
- - spec/fixtures/vcr_cassettes/Cirneco_Doi/mint_and_hide_DOIs/mints_dois_for_list_of_urls.yml
432
- - spec/fixtures/vcr_cassettes/Cirneco_Work/DOI_API/get/should_get_all_dois.yml
433
- - spec/fixtures/vcr_cassettes/Cirneco_Work/DOI_API/get/should_get_doi.yml
434
- - spec/fixtures/vcr_cassettes/Cirneco_Work/DOI_API/get/should_get_doi_not_found.yml
435
- - spec/fixtures/vcr_cassettes/Cirneco_Work/DOI_API/get/username_missing.yml
436
- - spec/fixtures/vcr_cassettes/Cirneco_Work/DOI_API/put/should_put_doi.yml
437
- - spec/fixtures/vcr_cassettes/Cirneco_Work/Media_API/get/should_get_media.yml
438
- - spec/fixtures/vcr_cassettes/Cirneco_Work/Media_API/post/should_post_media.yml
439
- - spec/fixtures/vcr_cassettes/Cirneco_Work/Metadata_API/delete/should_delete_metadata.yml
440
- - spec/fixtures/vcr_cassettes/Cirneco_Work/Metadata_API/get/should_get_metadata.yml
441
- - spec/fixtures/vcr_cassettes/Cirneco_Work/Metadata_API/post/should_post_metadata.yml
442
359
  - spec/fixtures/vcr_cassettes/Cirneco_Work/media/includes_media.yml
443
360
  - spec/fixtures/vcr_cassettes/Cirneco_Work/schema/BlogPosting.yml
444
361
  - spec/spec_helper.rb
@@ -464,7 +381,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
464
381
  version: '0'
465
382
  requirements: []
466
383
  rubyforge_project:
467
- rubygems_version: 2.6.11
384
+ rubygems_version: 2.7.4
468
385
  signing_key:
469
386
  specification_version: 4
470
387
  summary: Ruby client library for the DataCite MDS
data/data/authors.yml DELETED
File without changes
data/data/references.yaml DELETED
File without changes
data/data/site.yml DELETED
File without changes
@@ -1,371 +0,0 @@
1
- require 'bergamasco'
2
- require 'open-uri'
3
- require 'time'
4
-
5
- module Cirneco
6
- module FileUtils
7
- JATS_SCHEMA = File.expand_path("../../../resources/jats-1.1/JATS-journalpublishing1.xsd", __FILE__)
8
-
9
- LICENSES = {
10
- "https://creativecommons.org/licenses/by/4.0/" => "Creative Commons Attribution (CC-BY 4.0)",
11
- "https://creativecommons.org/publicdomain/zero/1.0/" => "Creative Commons Public Domain Dedication (CC0 1.0)"
12
- }
13
-
14
- def get_accession_number(filepath)
15
- metadata = Bergamasco::Markdown.read_yaml_for_doi_metadata(filepath)
16
- metadata.fetch("accession_number", nil).to_s.scan(/\d+/).first.to_i
17
- end
18
-
19
- def get_all_accession_numbers(folderpath)
20
- Dir.glob("#{folderpath}/*.md").sort.map do |filepath|
21
- get_accession_number(filepath)
22
- end.select { |a| a > 0 }.sort
23
- end
24
-
25
- def update_accession_number(filepath, options={})
26
- filename = File.basename(filepath)
27
- return "File #{filename} ignored: not a markdown or html file" unless %w(.md .html .erb).include?(File.extname(filepath))
28
-
29
- old_metadata = Bergamasco::Markdown.read_yaml_for_doi_metadata(filepath)
30
- return "File #{filename} ignored: no yaml front matter" unless old_metadata.present?
31
-
32
- return "File #{filename} ignored: no empty accession_number" if options[:opt_in] && !old_metadata.key?("accession_number")
33
-
34
- return "Accession number #{old_metadata["accession_number"]} not changed for #{filename}" if old_metadata["accession_number"]
35
-
36
- if old_metadata["doi"].present?
37
- number = decode_doi(old_metadata["doi"])
38
- options[:number] = number if number > 0
39
- else
40
- folderpath = File.dirname(filepath)
41
- options[:registered_numbers] = get_all_accession_numbers(folderpath)
42
- end
43
-
44
- accession_number = generate_accession_number(options)
45
-
46
- new_metadata = Bergamasco::Markdown.update_file(filepath, "accession_number" => accession_number)
47
- "Accession number #{new_metadata["accession_number"]} generated for #{filename}"
48
- end
49
-
50
- def update_all_accession_numbers(folderpath, options={})
51
- Dir.glob("#{folderpath}/*.md").sort.map do |filepath|
52
- update_accession_number(filepath, options)
53
- end
54
- end
55
-
56
- # fetch schema.org metadata in JSON-LD format to mint DOI
57
- def mint_doi_for_url(url, options={})
58
- filename, build_path, source_path = filepath_from_url(url, options)
59
-
60
- json = get_json_ld_from_work(build_path, options)
61
- metadata = JSON.parse(json)
62
- return "DOI #{metadata["doi"]} not changed for #{filename}" if metadata["doi"] && metadata["dateModified"] == metadata["datePublished"] && options[:force].blank?
63
-
64
- prefix = options[:prefix] || ENV['PREFIX']
65
- doi = encode_doi(prefix, number: metadata["alternateName"]) if metadata["doi"].blank?
66
-
67
- new_metadata = Bergamasco::Markdown.update_file(source_path, "doi" => doi, "date" => metadata["dateModified"])
68
- "DOI #{new_metadata["doi"]} minted for #{filename}"
69
- end
70
-
71
- # fetch schema.org metadata in JSON-LD format to mint DOI
72
- def mint_and_hide_doi_for_url(url, options={})
73
- filename, build_path, source_path = filepath_from_url(url, options)
74
-
75
- json = get_json_ld_from_work(build_path, options)
76
- metadata = JSON.parse(json)
77
- metadata["doi"] = doi_from_url(metadata["@id"])
78
- return "DOI #{metadata["doi"]} not changed for #{filename}" if metadata["doi"] && metadata["dateModified"] == metadata["datePublished"] && options[:force].blank?
79
-
80
- prefix = options[:prefix] || ENV['PREFIX']
81
- metadata["doi"] = encode_doi(prefix, number: metadata["alternateName"]) if metadata["doi"].blank?
82
-
83
- response = post_metadata_for_work(json, options.merge(doi: metadata["doi"]))
84
- return "Errors for DOI #{metadata["doi"]}: #{response.body['errors'].first['title']}\n" if response.body['errors'].present?
85
-
86
- response = hide_metadata_for_work(json, options.merge(doi: metadata["doi"]))
87
- return "Errors for DOI #{metadata["doi"]}: #{response.body['errors'].first['title']}\n" if response.body['errors'].present?
88
-
89
- new_metadata = Bergamasco::Markdown.update_file(source_path, "published" => false)
90
- "DOI #{metadata["doi"]} minted and hidden for #{filename}"
91
- end
92
-
93
- # fetch schema.org metadata in JSON-LD format to mint DOI
94
- # DOIs are never deleted, but we can remove the metadata from the DataCite index
95
- def hide_doi_for_url(url, options={})
96
- filename, build_path, source_path = filepath_from_url(url, options)
97
-
98
- json = get_json_ld_from_work(build_path, options)
99
- metadata = JSON.parse(json)
100
- metadata["doi"] = doi_from_url(metadata["@id"])
101
- return "No DOI for #{filename}" unless metadata["doi"]
102
- return "DOI #{metadata["doi"]} not active for #{filename}" unless metadata["datePublished"] || options[:force].present?
103
-
104
- response = hide_metadata_for_work(json, options)
105
- return "Errors for DOI #{metadata["doi"]}: #{response.body['errors'].first['title']}\n" if response.body['errors'].present?
106
-
107
- new_metadata = Bergamasco::Markdown.update_file(source_path, "published" => false)
108
- "DOI #{metadata["doi"]} hidden for #{filename}"
109
- end
110
-
111
- def mint_dois_for_all_urls(url, options={})
112
- urls = get_urls_for_works(url)
113
- urls.map do |u|
114
- mint_doi_for_url(u, options)
115
- end.join("\n")
116
- end
117
-
118
- def mint_and_hide_dois_for_all_urls(url, options={})
119
- urls = get_urls_for_works(url)
120
- urls.map do |u|
121
- mint_and_hide_doi_for_url(u, options)
122
- end.join("\n")
123
- end
124
-
125
- def hide_dois_for_all_urls(url, options={})
126
- urls = get_urls_for_works(url)
127
- urls.map do |u|
128
- hide_doi_for_url(u, options)
129
- end.join("\n")
130
- end
131
-
132
- def get_urls_for_works(url)
133
- doc = Nokogiri::HTML(open(url))
134
- json = doc.at_xpath("//script[@type='application/ld+json']")
135
- return [url] unless json.present?
136
-
137
- metadata = ActiveSupport::JSON.decode(json.text)
138
- metadata.fetch("hasPart", []).map { |p| p["@id"] } + [url]
139
- end
140
-
141
- def get_json_ld_from_work(url, options={})
142
- doc = Nokogiri::HTML(open(url))
143
- json = doc.at_xpath("//script[@type='application/ld+json']")
144
- return { "error" => "Error: no schema.org metadata found" } unless json.present?
145
-
146
- json.text
147
- end
148
-
149
- def post_metadata_for_work(input, options={})
150
- metadata = JSON.parse(input)
151
-
152
- prefix = options[:prefix] || ENV['PREFIX']
153
- doi = encode_doi(prefix, number: metadata["alternateName"]) if metadata["doi"].blank?
154
-
155
- work = Cirneco::Work.new(input: input)
156
- work.doi = doi
157
- return work.errors if work.errors.present?
158
-
159
- response = work.post_metadata(work.datacite, options)
160
- return response unless response.status == 201
161
-
162
- response = work.put_doi(work.doi, options.merge(url: metadata["url"]))
163
- return response unless response.status == 201
164
-
165
- if work.media.present?
166
- work.post_media(metadata.doi, options.merge(media: work.media))
167
- else
168
- response
169
- end
170
- end
171
-
172
- def post_and_hide_metadata_for_work(input, options={})
173
- metadata = JSON.parse(input)
174
-
175
- prefix = options[:prefix] || ENV['PREFIX']
176
- doi = encode_doi(prefix, number: metadata["alternateName"]) if metadata["doi"].blank?
177
-
178
- work = Cirneco::Work.new(input: input)
179
- work.doi = doi
180
- return work.errors if work.errors.present?
181
-
182
- response = work.post_metadata(work.datacite, options)
183
- return response unless response.status == 201
184
-
185
- response = work.put_doi(work.doi, options.merge(url: metadata["url"]))
186
- return response unless response.status == 201
187
-
188
- response = work.delete_metadata(doi, options)
189
- return response unless response.status == 201
190
-
191
- if work.media.present?
192
- work.post_media(metadata["doi"], options.merge(media: work.media))
193
- else
194
- response
195
- end
196
- end
197
-
198
- def hide_metadata_for_work(input, options={})
199
- metadata = JSON.parse(input)
200
- metadata["doi"] = doi_from_url(metadata["@id"])
201
-
202
- prefix = options[:prefix] || ENV['PREFIX']
203
- metadata["doi"] = encode_doi(prefix, number: metadata["alternateName"]) if metadata["doi"].blank?
204
-
205
- work = Cirneco::Work.new(input: input)
206
- work.doi = metadata["doi"]
207
- return work.errors if work.errors.present?
208
-
209
- work.delete_metadata(metadata["doi"], options)
210
- end
211
-
212
- def generate_metadata_for_jats(url, options={})
213
- doc = Nokogiri::HTML(open(url))
214
- json = doc.at_xpath("//script[@type='application/ld+json']")
215
- return { "error" => "Error: no schema.org metadata found" } unless json.present?
216
-
217
- metadata = ActiveSupport::JSON.decode(json.text)
218
- return { "error" => "Error: blog post not published" } if metadata["published"].to_s == "false"
219
- return { "error" => "Error: required metadata missing" } unless ["name", "author", "publisher", "datePublished", "@type"].all? { |k| metadata.key? k }
220
-
221
- # required metadata
222
- if /(http|https):\/\/(dx\.)?doi\.org\/(\w+)/.match(metadata["@id"])
223
- uri = Addressable::URI.parse(metadata["@id"])
224
- metadata["doi"] = uri.path[1..-1].upcase
225
- end
226
-
227
- metadata["title"] = metadata["name"]
228
- metadata["author"] = format_authors(metadata["author"]).map do |a|
229
- { "given_name" => a[:given_name],
230
- "family_name" => a[:family_name],
231
- "name" => a[:name],
232
- "orcid" => a[:orcid] }.compact
233
- end
234
-
235
- metadata["publisher"] = metadata.fetch("publisher", {}).fetch("name", nil)
236
- metadata["tags"] = metadata["keywords"].to_s.split(", ").select { |k| k != "featured" }
237
- metadata["date"] = metadata.fetch("datePublished", "")
238
- metadata["publication_year"] = metadata.fetch("date", "")[0..3].to_i
239
- metadata["publication_month"] = metadata.fetch("date", "")[5..6].to_i
240
- metadata["publication_day"] = metadata.fetch("date", "")[8..9].to_i
241
-
242
- # metadata["accession_number"] = metadata["alternateName"]
243
- metadata["journal_title"] = metadata.fetch("isPartOf", {}).fetch("name", nil)
244
-
245
- if metadata["description"].present?
246
- metadata["descriptions"] = [{ value: metadata["description"], description_type: "Abstract" }]
247
- end
248
-
249
- # use default version 1.0
250
- metadata["version"] ||= "1.0"
251
-
252
- # fetch reference metadata if available
253
- metadata["related_identifiers"] = get_related_identifiers(metadata)
254
-
255
- if metadata["license"].present?
256
- metadata["license_name"] = LICENSES.fetch(metadata["license"], nil)
257
- metadata["license_url"] = metadata["license"]
258
- end
259
-
260
- metadata = metadata.extract!(*%w(publisher doi tags title author date
261
- publication_year publication_month publication_day license_name
262
- license_url accession_number journal_title))
263
- end
264
-
265
- def generate_jats_for_url(url, options={})
266
- filename, build_path, source_path = filepath_from_url(url, options)
267
- metadata = generate_metadata_for_jats(build_path, options)
268
- return "No JATS XML written for #{filename}" if metadata["published"].to_s == "false"
269
-
270
- file = IO.read(source_path)
271
- content = Bergamasco::Markdown.split_yaml_frontmatter(file).last
272
- text = Bergamasco::Markdown.join_yaml_frontmatter(metadata, content)
273
-
274
- xml = Bergamasco::Pandoc.convert_to_jats(text, options)
275
- xmlname = filename.gsub(/\.html\.(erb|md)/, ".xml")
276
- xmlpath = build_path.gsub("index.html", xmlname)
277
- IO.write(xmlpath, xml)
278
-
279
- "JATS XML written for #{filename}"
280
- end
281
-
282
- def generate_jats_for_all_urls(url, options={})
283
- urls = get_urls_for_works(url)
284
- urls.map do |u|
285
- generate_jats_for_url(u, options)
286
- end.join("\n")
287
- end
288
-
289
- def validate_jats(xml)
290
- schema = Nokogiri::XML::Schema(open(JATS_SCHEMA))
291
- puts schema.validate(Nokogiri::XML(xml))
292
-
293
- OpenStruct.new(body: { "errors" => schema.validate(Nokogiri::XML(xml)).map { |error| { "title" => error.to_s } } })
294
- end
295
-
296
- def url_from_path(site_url, filepath)
297
- site_url.to_s.chomp("\\") + "/" + File.basename(filepath)[0..-9] + "/"
298
- end
299
-
300
- def format_authors(authors)
301
- Array(authors).map do |author|
302
- orcid = validate_orcid(author["@id"])
303
- name = (author["givenName"].present? || author["familyName"].present?) ? nil : author["name"]
304
-
305
- { :given_name => author["givenName"],
306
- :family_name => author["familyName"],
307
- :name => name,
308
- :orcid => orcid }.compact
309
- end
310
- end
311
-
312
- def get_related_identifiers(metadata)
313
- citations = Array(metadata["citation"])
314
- parent = [metadata["isPartOf"]].compact.map { |r| r.merge("relation_type" => "IsPartOf") }
315
- children = Array(metadata["hasPart"]).map { |r| r.merge("relation_type" => "HasPart") }
316
-
317
- (citations + parent + children).map do |r|
318
- id = r.fetch("@id", "")
319
- relation_type = r.fetch("relation_type", "References")
320
-
321
- if /(http|https):\/\/(dx\.)?doi\.org\/(\w+)/.match(id)
322
- uri = Addressable::URI.parse(id)
323
- value = uri.path[1..-1].upcase
324
- type = "DOI"
325
- elsif /(http|https):\/\//.match(id)
326
- uri = Addressable::URI.parse(id)
327
- value = uri.normalize.to_s
328
- type = "URL"
329
- else
330
- type = nil
331
- end
332
-
333
- {
334
- value: value,
335
- related_identifier_type: type,
336
- relation_type: relation_type
337
- }
338
- end.select { |t| t[:related_identifier_type].present? }
339
- end
340
-
341
- def format_media(metadata)
342
- [metadata["encoding"]].compact.map do |m|
343
- { mime_type: m["fileFormat"],
344
- url: m["@id"] }
345
- end
346
- end
347
-
348
- def filepath_from_url(url, options={})
349
- if doi_from_url(url)
350
- response = Maremma.head(url, limit: 0)
351
- url = response.headers.present? ? response.headers.fetch("Location", "") : ""
352
- end
353
-
354
- uri = Addressable::URI.parse(url.gsub(Dir.pwd + options[:build_dir].to_s, "")
355
- .gsub(/index\.html$/, "")
356
- .gsub(/\/$/, ""))
357
- basename = File.basename(uri.path, ".html").presence || "index"
358
-
359
- if basename.starts_with?("index")
360
- filename = basename + ".html.erb"
361
- source_path = Dir.pwd + options[:source_dir].to_s + filename
362
- build_path = Dir.pwd + options[:build_dir].to_s + basename + ".html"
363
- else
364
- filename = basename + ".html.md"
365
- source_path = Dir.pwd + options[:source_dir].to_s + options[:posts_dir].to_s + filename
366
- build_path = Dir.pwd + options[:build_dir].to_s + basename + "/index.html"
367
- end
368
- [filename, build_path, source_path]
369
- end
370
- end
371
- end