cirneco 0.9.12 → 0.9.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +124 -49
  3. data/cirneco.gemspec +5 -4
  4. data/lib/cirneco/api.rb +8 -8
  5. data/lib/cirneco/base.rb +2 -2
  6. data/lib/cirneco/cli.rb +1 -1
  7. data/lib/cirneco/utils.rb +48 -95
  8. data/lib/cirneco/version.rb +1 -1
  9. data/lib/cirneco/work.rb +8 -203
  10. data/spec/api_spec.rb +16 -28
  11. data/spec/doi_spec.rb +9 -11
  12. data/spec/fixtures/cool-dois-minted/index.html +189 -234
  13. data/spec/fixtures/cool-dois-minted.html.md +1 -1
  14. data/spec/fixtures/cool-dois.html.md +2 -2
  15. data/spec/fixtures/index-minted.html +1 -1
  16. data/spec/fixtures/index.html +50 -1
  17. data/spec/fixtures/index.html.erb +2 -2
  18. data/spec/fixtures/vcr_cassettes/Cirneco_DataCenter/get/should_get_all_dois_by_prefix.yml +20 -18
  19. data/spec/fixtures/vcr_cassettes/Cirneco_DataCenter/jats/should_generate_jats_for_all_urls.yml +38 -0
  20. data/spec/fixtures/vcr_cassettes/Cirneco_DataCenter/mint_and_hide_DOIs/should_hide_for_all_urls.yml +20 -20
  21. data/spec/fixtures/vcr_cassettes/Cirneco_DataCenter/mint_and_hide_DOIs/should_hide_for_url.yml +19 -17
  22. data/spec/fixtures/vcr_cassettes/Cirneco_DataCenter/mint_and_hide_DOIs/should_hide_metadata_for_work.yml +19 -17
  23. data/spec/fixtures/vcr_cassettes/Cirneco_DataCenter/mint_and_hide_DOIs/should_mint_and_hide_for_all_urls.yml +204 -108
  24. data/spec/fixtures/vcr_cassettes/Cirneco_DataCenter/mint_and_hide_DOIs/should_mint_and_hide_for_url.yml +72 -64
  25. data/spec/fixtures/vcr_cassettes/Cirneco_DataCenter/mint_and_hide_DOIs/should_mint_for_all_urls.yml +17 -291
  26. data/spec/fixtures/vcr_cassettes/Cirneco_DataCenter/mint_and_hide_DOIs/should_post_metadata_for_work.yml +47 -82
  27. data/spec/fixtures/vcr_cassettes/Cirneco_Doi/MDS_DOI_API/get/should_get_all_dois.yml +22 -18
  28. data/spec/fixtures/vcr_cassettes/Cirneco_Doi/MDS_DOI_API/get/should_get_doi.yml +19 -17
  29. data/spec/fixtures/vcr_cassettes/Cirneco_Doi/MDS_DOI_API/put/should_put_doi.yml +20 -18
  30. data/spec/fixtures/vcr_cassettes/Cirneco_Doi/jats/writes_jats_for_list_of_urls.yml +38 -0
  31. data/spec/fixtures/vcr_cassettes/Cirneco_Doi/mint_and_hide_DOIs/hides_a_doi.yml +19 -17
  32. data/spec/fixtures/vcr_cassettes/Cirneco_Doi/mint_and_hide_DOIs/hides_dois_for_list_of_urls.yml +81 -0
  33. data/spec/fixtures/vcr_cassettes/Cirneco_Doi/mint_and_hide_DOIs/mints_and_hides_a_doi.yml +72 -64
  34. data/spec/fixtures/vcr_cassettes/Cirneco_Doi/mint_and_hide_DOIs/mints_and_hides_dois_for_list_of_urls.yml +204 -108
  35. data/spec/fixtures/vcr_cassettes/Cirneco_Doi/mint_and_hide_DOIs/mints_dois_for_list_of_urls.yml +17 -291
  36. data/spec/fixtures/vcr_cassettes/Cirneco_Work/DOI_API/get/should_get_all_dois.yml +140 -18
  37. data/spec/fixtures/vcr_cassettes/Cirneco_Work/DOI_API/get/should_get_doi.yml +137 -17
  38. data/spec/fixtures/vcr_cassettes/Cirneco_Work/DOI_API/get/should_get_doi_not_found.yml +134 -16
  39. data/spec/fixtures/vcr_cassettes/Cirneco_Work/DOI_API/get/username_missing.yml +121 -0
  40. data/spec/fixtures/vcr_cassettes/Cirneco_Work/DOI_API/put/should_put_doi.yml +138 -18
  41. data/spec/fixtures/vcr_cassettes/Cirneco_Work/Media_API/get/should_get_media.yml +135 -17
  42. data/spec/fixtures/vcr_cassettes/Cirneco_Work/Media_API/post/should_post_media.yml +137 -17
  43. data/spec/fixtures/vcr_cassettes/Cirneco_Work/Metadata_API/delete/should_delete_metadata.yml +137 -17
  44. data/spec/fixtures/vcr_cassettes/Cirneco_Work/Metadata_API/get/should_get_metadata.yml +170 -27
  45. data/spec/fixtures/vcr_cassettes/Cirneco_Work/Metadata_API/post/should_post_metadata.yml +173 -28
  46. data/spec/fixtures/vcr_cassettes/Cirneco_Work/media/includes_media.yml +121 -0
  47. data/spec/fixtures/vcr_cassettes/Cirneco_Work/schema/BlogPosting.yml +121 -0
  48. data/spec/spec_helper.rb +1 -1
  49. data/spec/utils_spec.rb +28 -41
  50. data/spec/work_spec.rb +33 -43
  51. metadata +43 -19
  52. data/spec/fixtures/vcr_cassettes/Cirneco_DataCenter/mint_and_hide_DOIs/should_mint_for_url.yml +0 -174
  53. data/spec/fixtures/vcr_cassettes/Cirneco_Doi/mint_and_hide_DOIs/mints_a_doi.yml +0 -174
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d4bcf5675ef3673522be79fd7106614513ecfdf
4
- data.tar.gz: 53747a0efc2257fb563711017f47d56ceae19348
3
+ metadata.gz: 26264768a88f4fa5359062dc47a64fd378baee79
4
+ data.tar.gz: f6a57d8575940385bd04000497800080be5f6216
5
5
  SHA512:
6
- metadata.gz: 914c0308b088a03ad2cb26c7106f84a3ece09a13b4fa339f135026ee7849f2026615fc736478c5d5b08e334347de25a6860a12838c2a5ec73d67af80cf4c9cd4
7
- data.tar.gz: 9e3d04ee0564f380eb3a285985ef5a2dda22af275f094c48f3dfe762610a49d1baa0ec19ef5f2937e0a9c345dc0350ac3b0da99b6b830d19704cd34889b6e3bd
6
+ metadata.gz: 7ec100120cb41af67f14bdf17c70a82e819b24ccf7897f35238336c348ae6fab1773ecb582b42375a9daecc0905d25f758677bd06c672d320c8010e3c5813ada
7
+ data.tar.gz: 120c30769c64f9f173e3d1a9d2239c17c2e288cd17f83986c85d501fa288d3c35945101b76f4d1f874d7d8ace745acc54c6f09dca76ce8ef48e0bd4bcbbf59d4
data/Gemfile.lock CHANGED
@@ -1,46 +1,71 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cirneco (0.9.12)
5
- activesupport (~> 4.2, >= 4.2.5)
4
+ cirneco (0.9.13)
5
+ activesupport (>= 4.2.5, < 6)
6
6
  base32-crockford-checksum (~> 0.2.2)
7
7
  bergamasco (~> 0.3)
8
+ bolognese (~> 0.9.32)
8
9
  builder (~> 3.2, >= 3.2.2)
9
10
  dotenv (~> 2.1, >= 2.1.1)
10
- maremma (~> 3.1.2)
11
+ maremma (~> 3.5, >= 3.5.7)
11
12
  nokogiri (~> 1.6, >= 1.6.8)
12
13
  thor (~> 0.19)
13
14
 
14
15
  GEM
15
16
  remote: https://rubygems.org/
16
17
  specs:
17
- activesupport (4.2.7.1)
18
+ activesupport (5.1.2)
19
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
20
  i18n (~> 0.7)
19
- json (~> 1.7, >= 1.7.7)
20
21
  minitest (~> 5.1)
21
- thread_safe (~> 0.3, >= 0.3.4)
22
22
  tzinfo (~> 1.1)
23
- addressable (2.5.0)
23
+ addressable (2.5.1)
24
24
  public_suffix (~> 2.0, >= 2.0.2)
25
25
  base32-crockford-checksum (0.2.3)
26
- bergamasco (0.3.12)
27
- activesupport (~> 4.2, >= 4.2.5)
26
+ benchmark_methods (0.7)
27
+ bergamasco (0.3.15)
28
+ activesupport (>= 4.2.5, < 6)
28
29
  addressable (>= 2.3.6)
29
30
  builder (~> 3.2, >= 3.2.2)
30
31
  loofah (~> 2.0, >= 2.0.3)
31
- multi_json (~> 1.11.2)
32
- nokogiri (~> 1.6.7)
33
- oj (~> 2.13.1)
32
+ multi_json (~> 1.12)
33
+ nokogiri (~> 1.6, >= 1.6.8)
34
+ oj (~> 2.18, >= 2.18.1)
34
35
  pandoc-ruby (~> 2.0, >= 2.0.0)
35
36
  safe_yaml (~> 1.0, >= 1.0.4)
37
+ bibtex-ruby (4.4.4)
38
+ latex-decode (~> 0.0)
39
+ bolognese (0.9.32)
40
+ activesupport (>= 4.2.5, < 6)
41
+ benchmark_methods (~> 0.7)
42
+ bibtex-ruby (~> 4.1)
43
+ builder (~> 3.2, >= 3.2.2)
44
+ colorize (~> 0.8.1)
45
+ gender_detector (~> 0.1.2)
46
+ json-ld (~> 2.1, >= 2.1.2)
47
+ jsonlint (~> 0.2.0)
48
+ loofah (~> 2.0, >= 2.0.3)
49
+ maremma (~> 3.5, >= 3.5.7)
50
+ namae (~> 0.11.3)
51
+ nokogiri (~> 1.6, >= 1.6.8)
52
+ postrank-uri (~> 1.0, >= 1.0.18)
53
+ rdf-rdfxml (~> 2.0)
54
+ rdf-turtle (~> 2.2)
55
+ thor (~> 0.19)
36
56
  builder (3.2.3)
37
- codeclimate-test-reporter (1.0.5)
57
+ codeclimate-test-reporter (1.0.7)
38
58
  simplecov
59
+ colorize (0.8.1)
60
+ concurrent-ruby (1.0.5)
39
61
  crack (0.4.3)
40
62
  safe_yaml (~> 1.0.0)
41
63
  diff-lcs (1.3)
42
64
  docile (1.1.5)
43
- dotenv (2.2.0)
65
+ dotenv (2.2.1)
66
+ ebnf (1.1.1)
67
+ rdf (~> 2.2)
68
+ sxp (~> 1.0)
44
69
  excon (0.45.4)
45
70
  faraday (0.9.2)
46
71
  multipart-post (>= 1.2, < 3)
@@ -48,63 +73,113 @@ GEM
48
73
  faraday
49
74
  faraday_middleware (0.10.1)
50
75
  faraday (>= 0.7.4, < 1.0)
51
- hashdiff (0.3.2)
52
- i18n (0.8.0)
53
- json (1.8.6)
76
+ gender_detector (0.1.2)
77
+ unicode_utils (>= 1.3.0)
78
+ haml (5.0.1)
79
+ temple (>= 0.8.0)
80
+ tilt
81
+ hamster (3.0.0)
82
+ concurrent-ruby (~> 1.0)
83
+ hashdiff (0.3.4)
84
+ htmlentities (4.3.4)
85
+ i18n (0.8.6)
86
+ json (2.1.0)
87
+ json-ld (2.1.5)
88
+ multi_json (~> 1.12)
89
+ rdf (~> 2.2)
90
+ jsonlint (0.2.0)
91
+ oj (~> 2)
92
+ trollop (~> 2)
93
+ latex-decode (0.2.2)
94
+ unicode (~> 0.4)
95
+ link_header (0.0.8)
54
96
  loofah (2.0.3)
55
97
  nokogiri (>= 1.5.9)
56
- maremma (3.1.2)
57
- activesupport (~> 4.2, >= 4.2.5)
58
- addressable (~> 2.5)
98
+ maremma (3.5.8)
99
+ activesupport (>= 4.2.5)
100
+ addressable (>= 2.3.6)
59
101
  builder (~> 3.2, >= 3.2.2)
60
102
  excon (~> 0.45.0)
61
103
  faraday (~> 0.9.2)
62
104
  faraday-encoding (~> 0.0.1)
63
105
  faraday_middleware (~> 0.10.0)
64
- multi_json (~> 1.11.2)
65
- nokogiri (~> 1.6.7)
66
- oj (~> 2.13.1)
106
+ multi_json (~> 1.12)
107
+ nokogiri (~> 1.6, >= 1.6.8)
108
+ oj (~> 2.18, >= 2.18.1)
67
109
  mini_portile2 (2.1.0)
68
- minitest (5.10.1)
69
- multi_json (1.11.3)
110
+ minitest (5.10.3)
111
+ multi_json (1.12.1)
70
112
  multipart-post (2.0.0)
71
- nokogiri (1.6.8.1)
113
+ namae (0.11.3)
114
+ nokogiri (1.7.2)
72
115
  mini_portile2 (~> 2.1.0)
73
- oj (2.13.1)
116
+ oj (2.18.5)
74
117
  pandoc-ruby (2.0.1)
118
+ postrank-uri (1.0.22)
119
+ addressable (>= 2.3.0, < 2.6)
120
+ nokogiri (>= 1.6.1, < 1.8)
121
+ public_suffix (>= 2.0.0, < 2.1)
75
122
  public_suffix (2.0.5)
76
- rack (2.0.1)
77
- rack-test (0.6.3)
78
- rack (>= 1.0)
123
+ rack (2.0.3)
124
+ rack-test (0.7.0)
125
+ rack (>= 1.0, < 3)
79
126
  rake (12.0.0)
80
- rspec (3.5.0)
81
- rspec-core (~> 3.5.0)
82
- rspec-expectations (~> 3.5.0)
83
- rspec-mocks (~> 3.5.0)
84
- rspec-core (3.5.4)
85
- rspec-support (~> 3.5.0)
86
- rspec-expectations (3.5.0)
127
+ rdf (2.2.6)
128
+ hamster (~> 3.0)
129
+ link_header (~> 0.0, >= 0.0.8)
130
+ rdf-aggregate-repo (2.2.0)
131
+ rdf (~> 2.0)
132
+ rdf-rdfa (2.2.2)
133
+ haml (~> 5.0)
134
+ htmlentities (~> 4.3)
135
+ rdf (~> 2.2)
136
+ rdf-aggregate-repo (~> 2.2)
137
+ rdf-xsd (~> 2.1)
138
+ rdf-rdfxml (2.0.0)
139
+ htmlentities (~> 4.3)
140
+ rdf (~> 2.0)
141
+ rdf-rdfa (~> 2.0)
142
+ rdf-xsd (~> 2.0)
143
+ rdf-turtle (2.2.0)
144
+ ebnf (~> 1.1)
145
+ rdf (~> 2.2)
146
+ rdf-xsd (2.2.0)
147
+ rdf (~> 2.1)
148
+ rspec (3.6.0)
149
+ rspec-core (~> 3.6.0)
150
+ rspec-expectations (~> 3.6.0)
151
+ rspec-mocks (~> 3.6.0)
152
+ rspec-core (3.6.0)
153
+ rspec-support (~> 3.6.0)
154
+ rspec-expectations (3.6.0)
87
155
  diff-lcs (>= 1.2.0, < 2.0)
88
- rspec-support (~> 3.5.0)
89
- rspec-mocks (3.5.0)
156
+ rspec-support (~> 3.6.0)
157
+ rspec-mocks (3.6.0)
90
158
  diff-lcs (>= 1.2.0, < 2.0)
91
- rspec-support (~> 3.5.0)
92
- rspec-support (3.5.0)
159
+ rspec-support (~> 3.6.0)
160
+ rspec-support (3.6.0)
93
161
  rspec-xsd (0.1.0)
94
162
  nokogiri (~> 1.6)
95
163
  rspec (~> 3)
96
164
  safe_yaml (1.0.4)
97
- simplecov (0.12.0)
165
+ simplecov (0.14.1)
98
166
  docile (~> 1.1.0)
99
167
  json (>= 1.8, < 3)
100
168
  simplecov-html (~> 0.10.0)
101
- simplecov-html (0.10.0)
169
+ simplecov-html (0.10.1)
170
+ sxp (1.0.0)
171
+ rdf (~> 2.0)
172
+ temple (0.8.0)
102
173
  thor (0.19.4)
103
- thread_safe (0.3.5)
104
- tzinfo (1.2.2)
174
+ thread_safe (0.3.6)
175
+ tilt (2.0.7)
176
+ trollop (2.1.2)
177
+ tzinfo (1.2.3)
105
178
  thread_safe (~> 0.1)
179
+ unicode (0.4.4.4)
180
+ unicode_utils (1.4.0)
106
181
  vcr (3.0.3)
107
- webmock (1.24.6)
182
+ webmock (3.0.1)
108
183
  addressable (>= 2.3.6)
109
184
  crack (>= 0.3.2)
110
185
  hashdiff
@@ -120,9 +195,9 @@ DEPENDENCIES
120
195
  rake (~> 12.0)
121
196
  rspec (~> 3.4)
122
197
  rspec-xsd (~> 0.1.0)
123
- simplecov (~> 0.12.0)
198
+ simplecov (~> 0.14.1)
124
199
  vcr (~> 3.0, >= 3.0.3)
125
- webmock (~> 1.22, >= 1.22.3)
200
+ webmock (~> 3.0, >= 3.0.1)
126
201
 
127
202
  BUNDLED WITH
128
- 1.12.5
203
+ 1.15.3
data/cirneco.gemspec CHANGED
@@ -15,12 +15,13 @@ Gem::Specification.new do |s|
15
15
  s.license = 'MIT'
16
16
 
17
17
  # Declary dependencies here, rather than in the Gemfile
18
- s.add_dependency 'maremma', '~> 3.1.2'
18
+ s.add_dependency 'maremma', '~> 3.5', '>= 3.5.7'
19
19
  s.add_dependency 'bergamasco', '~> 0.3'
20
+ s.add_dependency 'bolognese', '~> 0.9.32'
20
21
  s.add_dependency 'base32-crockford-checksum', '~> 0.2.2'
21
22
  s.add_dependency 'nokogiri', '~> 1.6', '>= 1.6.8'
22
23
  s.add_dependency 'builder', '~> 3.2', '>= 3.2.2'
23
- s.add_dependency 'activesupport', '~> 4.2', '>= 4.2.5'
24
+ s.add_dependency 'activesupport', '>= 4.2.5', '< 6'
24
25
  s.add_dependency 'dotenv', '~> 2.1', '>= 2.1.1'
25
26
  s.add_dependency 'thor', '~> 0.19'
26
27
  s.add_development_dependency 'bundler', '~> 1.0'
@@ -29,9 +30,9 @@ Gem::Specification.new do |s|
29
30
  s.add_development_dependency 'rake', '~> 12.0'
30
31
  s.add_development_dependency 'rack-test', '~> 0'
31
32
  s.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.3'
32
- s.add_development_dependency 'webmock', '~> 1.22', '>= 1.22.3'
33
+ s.add_development_dependency 'webmock', '~> 3.0', '>= 3.0.1'
33
34
  s.add_development_dependency 'codeclimate-test-reporter', '~> 1.0', '>= 1.0.0'
34
- s.add_development_dependency 'simplecov', '~> 0.12.0'
35
+ s.add_development_dependency 'simplecov', '~> 0.14.1'
35
36
 
36
37
  s.require_paths = ["lib"]
37
38
  s.files = `git ls-files`.split($/)
data/lib/cirneco/api.rb CHANGED
@@ -6,7 +6,7 @@ module Cirneco
6
6
  def post_metadata(data, options={})
7
7
  return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless options[:username].present? && options[:password].present?
8
8
 
9
- mds_url = options[:sandbox] ? 'https://mds-sandbox.datacite.org' : 'https://mds.datacite.org'
9
+ mds_url = options[:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org'
10
10
 
11
11
  url = "#{mds_url}/metadata"
12
12
  Maremma.post(url, content_type: 'application/xml;charset=UTF-8', data: data, username: options[:username], password: options[:password])
@@ -15,7 +15,7 @@ module Cirneco
15
15
  def get_metadata(doi, options={})
16
16
  return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless options[:username].present? && options[:password].present?
17
17
 
18
- mds_url = options[:sandbox] ? 'https://mds-sandbox.datacite.org' : 'https://mds.datacite.org'
18
+ mds_url = options[:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org'
19
19
 
20
20
  url = "#{mds_url}/metadata/#{doi}"
21
21
  Maremma.get(url, accept: 'application/xml', username: options[:username], password: options[:password], raw: true)
@@ -24,7 +24,7 @@ module Cirneco
24
24
  def delete_metadata(doi, options={})
25
25
  return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless options[:username].present? && options[:password].present?
26
26
 
27
- mds_url = options[:sandbox] ? 'https://mds-sandbox.datacite.org' : 'https://mds.datacite.org'
27
+ mds_url = options[:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org'
28
28
 
29
29
  url = "#{mds_url}/metadata/#{doi}"
30
30
  Maremma.delete(url, username: options[:username], password: options[:password])
@@ -35,7 +35,7 @@ module Cirneco
35
35
 
36
36
  payload = "doi=#{doi}\nurl=#{options[:url]}"
37
37
 
38
- mds_url = options[:sandbox] ? 'https://mds-sandbox.datacite.org' : 'https://mds.datacite.org'
38
+ mds_url = options[:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org'
39
39
 
40
40
  url = "#{mds_url}/doi/#{doi}"
41
41
  Maremma.put(url, content_type: 'text/plain;charset=UTF-8', data: payload, username: options[:username], password: options[:password])
@@ -44,7 +44,7 @@ module Cirneco
44
44
  def get_doi(doi, options={})
45
45
  return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless options[:username].present? && options[:password].present?
46
46
 
47
- mds_url = options[:sandbox] ? 'https://mds-sandbox.datacite.org' : 'https://mds.datacite.org'
47
+ mds_url = options[:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org'
48
48
 
49
49
  url = "#{mds_url}/doi/#{doi}"
50
50
  Maremma.get(url, username: options[:username], password: options[:password])
@@ -53,7 +53,7 @@ module Cirneco
53
53
  def get_dois(options={})
54
54
  return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless options[:username].present? && options[:password].present?
55
55
 
56
- mds_url = options[:sandbox] ? 'https://mds-sandbox.datacite.org' : 'https://mds.datacite.org'
56
+ mds_url = options[:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org'
57
57
 
58
58
  url = "#{mds_url}/doi"
59
59
  response = Maremma.get(url, username: options[:username], password: options[:password])
@@ -66,7 +66,7 @@ module Cirneco
66
66
 
67
67
  payload = options[:raw] ? options[:media] : options[:media].map { |m| "#{m[:mime_type]}=#{m[:url]}" }.join("\n")
68
68
 
69
- mds_url = options[:sandbox] ? 'https://mds-sandbox.datacite.org' : 'https://mds.datacite.org'
69
+ mds_url = options[:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org'
70
70
 
71
71
  url = "#{mds_url}/media/#{doi}"
72
72
  Maremma.post(url, content_type: 'text/plain;charset=UTF-8', data: payload, username: options[:username], password: options[:password])
@@ -75,7 +75,7 @@ module Cirneco
75
75
  def get_media(doi, options={})
76
76
  return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless options[:username].present? && options[:password].present?
77
77
 
78
- mds_url = options[:sandbox] ? 'https://mds-sandbox.datacite.org' : 'https://mds.datacite.org'
78
+ mds_url = options[:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org'
79
79
 
80
80
  url = "#{mds_url}/media/#{doi}"
81
81
  response = Maremma.get(url, accept: 'application/xml', username: options[:username], password: options[:password])
data/lib/cirneco/base.rb CHANGED
@@ -4,7 +4,7 @@ module Cirneco
4
4
  env_file = File.expand_path("../../../.env", __FILE__)
5
5
  if File.exist?(env_file)
6
6
  require 'dotenv'
7
- Dotenv.load! env_file
7
+ Dotenv.overload env_file
8
8
  end
9
9
 
10
10
  # load ENV variables from container environment if json file exists
@@ -16,6 +16,6 @@ module Cirneco
16
16
  end
17
17
 
18
18
  # default values for some ENV variables
19
- ENV['MDS_URL'] ||= "https://mds-sandbox.datacite.org"
19
+ ENV['MDS_URL'] ||= "https://mds.test.datacite.org"
20
20
  end
21
21
  end
data/lib/cirneco/cli.rb CHANGED
@@ -16,7 +16,7 @@ module Cirneco
16
16
  env_file = File.expand_path("../../.env", __FILE__)
17
17
  if File.exist?(env_file)
18
18
  require 'dotenv'
19
- Dotenv.load! env_file
19
+ Dotenv.overload env_file
20
20
  end
21
21
 
22
22
  def self.exit_on_failure?
data/lib/cirneco/utils.rb CHANGED
@@ -107,13 +107,14 @@ module Cirneco
107
107
  def mint_doi_for_url(url, options={})
108
108
  filename, build_path, source_path = filepath_from_url(url, options)
109
109
 
110
- metadata = generate_metadata_for_work(build_path, options)
111
- return "DOI #{metadata["doi"]} not changed for #{filename}" if metadata["doi"] && metadata["date_updated"] == metadata["date_issued"] && options[:force].blank?
110
+ json = get_json_ld_from_work(build_path, options)
111
+ metadata = JSON.parse(json)
112
+ return "DOI #{metadata["doi"]} not changed for #{filename}" if metadata["doi"] && metadata["dateModified"] == metadata["datePublished"] && options[:force].blank?
112
113
 
113
- response = post_metadata_for_work(metadata, options)
114
- return "Errors for DOI #{metadata["doi"]}: #{response.body['errors'].first['title']}\n" if response.body['errors'].present?
114
+ prefix = options[:prefix] || ENV['PREFIX']
115
+ doi = encode_doi(prefix, number: metadata["alternateName"]) if metadata["doi"].blank?
115
116
 
116
- new_metadata = Bergamasco::Markdown.update_file(source_path, "doi" => metadata["doi"], "date" => metadata["date_updated"])
117
+ new_metadata = Bergamasco::Markdown.update_file(source_path, "doi" => doi, "date" => metadata["dateModified"])
117
118
  "DOI #{new_metadata["doi"]} minted for #{filename}"
118
119
  end
119
120
 
@@ -121,14 +122,22 @@ module Cirneco
121
122
  def mint_and_hide_doi_for_url(url, options={})
122
123
  filename, build_path, source_path = filepath_from_url(url, options)
123
124
 
124
- metadata = generate_metadata_for_work(build_path, options)
125
- return "DOI #{metadata["doi"]} not changed for #{filename}" if metadata["doi"] && metadata["date_updated"] == metadata["date_issued"] && options[:force].blank?
125
+ json = get_json_ld_from_work(build_path, options)
126
+ metadata = JSON.parse(json)
127
+ metadata["doi"] = doi_from_url(metadata["@id"])
128
+ return "DOI #{metadata["doi"]} not changed for #{filename}" if metadata["doi"] && metadata["dateModified"] == metadata["datePublished"] && options[:force].blank?
129
+
130
+ prefix = options[:prefix] || ENV['PREFIX']
131
+ metadata["doi"] = encode_doi(prefix, number: metadata["alternateName"]) if metadata["doi"].blank?
132
+
133
+ response = post_metadata_for_work(json, options.merge(doi: metadata["doi"]))
134
+ return "Errors for DOI #{metadata["doi"]}: #{response.body['errors'].first['title']}\n" if response.body['errors'].present?
126
135
 
127
- response = post_metadata_for_work(metadata, options)
136
+ response = hide_metadata_for_work(json, options.merge(doi: metadata["doi"]))
128
137
  return "Errors for DOI #{metadata["doi"]}: #{response.body['errors'].first['title']}\n" if response.body['errors'].present?
129
138
 
130
- new_metadata = Bergamasco::Markdown.update_file(source_path, "doi" => metadata["doi"], "date" => metadata["date_updated"])
131
- "DOI #{new_metadata["doi"]} minted and hidden for #{filename}"
139
+ new_metadata = Bergamasco::Markdown.update_file(source_path, "published" => false)
140
+ "DOI #{metadata["doi"]} minted and hidden for #{filename}"
132
141
  end
133
142
 
134
143
  # fetch schema.org metadata in JSON-LD format to mint DOI
@@ -136,11 +145,13 @@ module Cirneco
136
145
  def hide_doi_for_url(url, options={})
137
146
  filename, build_path, source_path = filepath_from_url(url, options)
138
147
 
139
- metadata = generate_metadata_for_work(build_path, options)
148
+ json = get_json_ld_from_work(build_path, options)
149
+ metadata = JSON.parse(json)
150
+ metadata["doi"] = doi_from_url(metadata["@id"])
140
151
  return "No DOI for #{filename}" unless metadata["doi"]
141
- return "DOI #{metadata["doi"]} not active for #{filename}" unless metadata["date_issued"] || options[:force].present?
152
+ return "DOI #{metadata["doi"]} not active for #{filename}" unless metadata["datePublished"] || options[:force].present?
142
153
 
143
- response = hide_metadata_for_work(metadata, options)
154
+ response = hide_metadata_for_work(json, options)
144
155
  return "Errors for DOI #{metadata["doi"]}: #{response.body['errors'].first['title']}\n" if response.body['errors'].present?
145
156
 
146
157
  new_metadata = Bergamasco::Markdown.update_file(source_path, "published" => false)
@@ -177,111 +188,52 @@ module Cirneco
177
188
  metadata.fetch("hasPart", []).map { |p| p["@id"] } + [url]
178
189
  end
179
190
 
180
- def generate_metadata_for_work(url, options={})
191
+ def get_json_ld_from_work(url, options={})
181
192
  doc = Nokogiri::HTML(open(url))
182
193
  json = doc.at_xpath("//script[@type='application/ld+json']")
183
194
  return { "error" => "Error: no schema.org metadata found" } unless json.present?
184
195
 
185
- metadata = ActiveSupport::JSON.decode(json.text)
186
- return { "error" => "Error: blog post not published" } if metadata["published"].to_s == "false"
187
- return { "error" => "Error: required metadata missing" } unless ["name", "author", "publisher", "datePublished", "@type"].all? { |k| metadata.key? k }
188
-
189
- # required metadata
190
- if /(http|https):\/\/(dx\.)?doi\.org\/(\w+)/.match(metadata["@id"])
191
- uri = Addressable::URI.parse(metadata["@id"])
192
- metadata["doi"] = uri.path[1..-1].upcase
193
- end
194
-
195
- metadata["title"] = metadata["name"]
196
-
197
- metadata["creators"] = format_authors(metadata["author"])
198
-
199
- metadata["publisher"] = metadata.fetch("publisher", {}).fetch("name", nil)
200
- metadata["publication_year"] = metadata["datePublished"][0..3].to_i
201
-
202
- resource_type_general = case metadata["@type"]
203
- when "Dataset" then "Dataset"
204
- when "Blog" then "Collection"
205
- when "Code" then "Software"
206
- else "Text"
207
- end
208
-
209
- metadata["resource_type"] = { value: metadata["@type"],
210
- resource_type_general: resource_type_general }
211
-
212
- # recommended metadata
213
-
214
- # use alternate_identifier to generate DOI
215
- metadata["alternate_identifier"] = metadata["alternateName"]
216
-
217
- if metadata["description"].present?
218
- metadata["descriptions"] = [{ value: metadata["description"], description_type: "Abstract" }]
219
- end
220
-
221
- # use default version 1.0
222
- metadata["version"] ||= "1.0"
223
-
224
- # fetch reference metadata if available
225
- metadata["related_identifiers"] = get_related_identifiers(metadata)
226
-
227
- if metadata["license"].present?
228
- value = LICENSES.fetch(metadata["license_url"], nil)
229
- metadata["rights_list"] = [{ value: value, rights_uri: metadata["license"] }] if value.present?
230
- end
231
-
232
- if metadata["keywords"].present?
233
- metadata["subjects"] = Array(metadata["keywords"].split(", ")).select { |k| k != "featured" }
234
- end
235
-
236
- metadata["media"] = format_media(metadata)
237
-
238
- metadata["date_created"] = metadata["dateCreated"]
239
- metadata["date_issued"] = metadata["datePublished"]
240
- metadata["date_updated"] = metadata["dateModified"]
241
-
242
- metadata = metadata.extract!(*%w(doi alternate_identifier url creators title
243
- publisher publication_year resource_type descriptions version rights_list
244
- subjects date_issued date_created date_updated related_identifiers media))
196
+ json.text
245
197
  end
246
198
 
247
- def post_metadata_for_work(metadata, options={})
248
- return OpenStruct.new(body: { "errors" => [{"title" => "Error: required metadata missing" }] }) unless ["title", "creators", "publisher", "publication_year", "resource_type"].all? { |k| metadata.key? k }
199
+ def post_metadata_for_work(input, options={})
200
+ metadata = JSON.parse(input)
249
201
 
250
202
  prefix = options[:prefix] || ENV['PREFIX']
251
- metadata["doi"] = encode_doi(prefix, number: metadata["alternate_identifier"]) if metadata["doi"].blank?
203
+ doi = encode_doi(prefix, number: metadata["alternateName"]) if metadata["doi"].blank?
252
204
 
253
- work = Cirneco::Work.new(metadata)
254
- return work.validation_errors if work.validation_errors.body["errors"].present?
205
+ work = Cirneco::Work.new(input: input, doi: doi)
206
+ return work.errors if work.errors.present?
255
207
 
256
- response = work.post_metadata(work.data, options)
208
+ response = work.post_metadata(work.datacite, options)
257
209
  return response unless response.status == 201
258
210
 
259
- response = work.put_doi(metadata["doi"], options.merge(url: metadata["url"]))
211
+ response = work.put_doi(work.doi, options.merge(url: metadata["url"]))
260
212
  return response unless response.status == 201
261
213
 
262
214
  if work.media.present?
263
- work.post_media(metadata["doi"], options.merge(media: work.media))
215
+ work.post_media(metadata.doi, options.merge(media: work.media))
264
216
  else
265
217
  response
266
218
  end
267
219
  end
268
220
 
269
- def post_and_hide_metadata_for_work(metadata, options={})
270
- return OpenStruct.new(body: { "errors" => [{"title" => "Error: required metadata missing" }] }) unless ["title", "creators", "publisher", "publication_year", "resource_type"].all? { |k| metadata.key? k }
221
+ def post_and_hide_metadata_for_work(input, options={})
222
+ metadata = JSON.parse(input)
271
223
 
272
224
  prefix = options[:prefix] || ENV['PREFIX']
273
- metadata["doi"] = encode_doi(prefix, number: metadata["alternate_identifier"]) if metadata["doi"].blank?
225
+ doi = encode_doi(prefix, number: metadata["alternateName"]) if metadata["doi"].blank?
274
226
 
275
- work = Cirneco::Work.new(metadata)
276
- return work.validation_errors if work.validation_errors.body["errors"].present?
227
+ work = Cirneco::Work.new(input: input, doi: doi)
228
+ return work.errors if work.errors.present?
277
229
 
278
- response = work.post_metadata(work.data, options)
230
+ response = work.post_metadata(work.datacite, options)
279
231
  return response unless response.status == 201
280
232
 
281
- response = work.put_doi(metadata["doi"], options.merge(url: metadata["url"]))
233
+ response = work.put_doi(work.doi, options.merge(url: metadata["url"]))
282
234
  return response unless response.status == 201
283
235
 
284
- response = work.delete_metadata(metadata["doi"], options)
236
+ response = work.delete_metadata(doi, options)
285
237
  return response unless response.status == 201
286
238
 
287
239
  if work.media.present?
@@ -291,14 +243,15 @@ module Cirneco
291
243
  end
292
244
  end
293
245
 
294
- def hide_metadata_for_work(metadata, options={})
295
- return OpenStruct.new(body: { "errors" => [{"title" => "Error: required metadata missing" }] }) unless ["title", "creators", "publisher", "publication_year", "resource_type"].all? { |k| metadata.key? k }
246
+ def hide_metadata_for_work(input, options={})
247
+ metadata = JSON.parse(input)
248
+ metadata["doi"] = doi_from_url(metadata["@id"])
296
249
 
297
250
  prefix = options[:prefix] || ENV['PREFIX']
298
- metadata["doi"] = encode_doi(prefix, number: metadata["alternate_identifier"]) if metadata["doi"].blank?
251
+ metadata["doi"] = encode_doi(prefix, number: metadata["alternateName"]) if metadata["doi"].blank?
299
252
 
300
- work = Cirneco::Work.new(metadata)
301
- return work.validation_errors if work.validation_errors.body["errors"].present?
253
+ work = Cirneco::Work.new(input: input, doi: metadata["doi"])
254
+ return work.errors if work.errors.present?
302
255
 
303
256
  work.delete_metadata(metadata["doi"], options)
304
257
  end
@@ -1,3 +1,3 @@
1
1
  module Cirneco
2
- VERSION = "0.9.12"
2
+ VERSION = "0.9.13"
3
3
  end