datacite 0.6.0 → 0.8.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cdf38cc62fc479c6a1c83719e27652830c893850b54faa42bd745c45336fbe38
4
- data.tar.gz: ca019efa9f9130d58061c9150fad4abdbeb2a2bbfb373d68a1bf0cfb8c639068
3
+ metadata.gz: 70e80d4615ecf31ae69938f5008ee396db504bd2e4ce7637816bb5df5c4038cd
4
+ data.tar.gz: ef72c4e1491a8567f087e1fa889e68c5cfba68a96070f324cbe4f670dda70967
5
5
  SHA512:
6
- metadata.gz: 2a211b25333cf2dc5bc57db4744f3253d8954e35b74bb8af4c77252f1063ea85a1077717a8330f60bd2c58577a4f1dd03777c11a12fa607074502ebca4b7db9c
7
- data.tar.gz: 5d7715a9e6c66cde554740b4ded731c7c90344969b77a2295d5567014fd2a79db25ca87b99a13750959e3e1cf81c15cba69d1a575c90618fede91f74a63bfe19
6
+ metadata.gz: 447c41b1b2d1cc567fb9f9aa854e249b56d31f9f8646f8e859af461dad8931e381b611eb5f346b129868677d1773b3d84f356fa5ed3b1cc1895df88021c8e1f7
7
+ data.tar.gz: '085d1ddcb4ed62ab36480fb1875e73f71b29245e16fd8e8d7746df321d6a89df6a01156902ed639962f79e9a8bec0ce2b10a51e3137001404118d7633eade4fc'
data/.rubocop.yml CHANGED
@@ -3,7 +3,7 @@ plugins:
3
3
  - rubocop-rspec
4
4
 
5
5
  AllCops:
6
- TargetRubyVersion: 3.0
6
+ TargetRubyVersion: 3.4
7
7
 
8
8
  Metrics/BlockLength:
9
9
  Exclude:
@@ -16,17 +16,12 @@ RSpec/MultipleExpectations:
16
16
  RSpec/MultipleMemoizedHelpers:
17
17
  Enabled: false
18
18
 
19
- Style/StringLiterals:
20
- Enabled: true
21
- EnforcedStyle: double_quotes
22
-
23
- Style/StringLiteralsInInterpolation:
24
- Enabled: true
25
- EnforcedStyle: double_quotes
26
-
27
19
  Layout/LineLength:
28
20
  Max: 120
29
21
 
22
+ RSpec/ExampleLength:
23
+ Enabled: false
24
+
30
25
  Gemspec/DeprecatedAttributeAssignment: # new in 1.30
31
26
  Enabled: true
32
27
  Gemspec/DevelopmentDependencies: # new in 1.44
@@ -335,3 +330,30 @@ Style/SendWithLiteralMethodName: # new in 1.64
335
330
  Enabled: true
336
331
  Style/SuperArguments: # new in 1.64
337
332
  Enabled: true
333
+
334
+ Gemspec/AttributeAssignment: # new in 1.77
335
+ Enabled: true
336
+ Layout/EmptyLinesAfterModuleInclusion: # new in 1.79
337
+ Enabled: true
338
+ Lint/UselessDefaultValueArgument: # new in 1.76
339
+ Enabled: true
340
+ Lint/UselessOr: # new in 1.76
341
+ Enabled: true
342
+ Naming/PredicateMethod: # new in 1.76
343
+ Enabled: true
344
+ Style/ArrayIntersectWithSingleElement: # new in 1.81
345
+ Enabled: true
346
+ Style/CollectionQuerying: # new in 1.77
347
+ Enabled: true
348
+ Style/ComparableBetween: # new in 1.74
349
+ Enabled: true
350
+ Style/EmptyStringInsideInterpolation: # new in 1.76
351
+ Enabled: true
352
+ Style/HashFetchChain: # new in 1.75
353
+ Enabled: true
354
+ Style/ItBlockParameter: # new in 1.75
355
+ Enabled: true
356
+ Style/RedundantArrayFlatten: # new in 1.76
357
+ Enabled: true
358
+ RSpec/IncludeExamples: # new in 3.6
359
+ Enabled: true
data/Gemfile CHANGED
@@ -1,17 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in datacite.gemspec
6
6
  gemspec
7
7
 
8
8
  # Specify development dependencies here
9
- gem "base64"
10
- gem "byebug"
11
- gem "rake", "~> 13.0"
12
- gem "rspec", "~> 3.0"
13
- gem "rubocop", "~> 1.7"
14
- gem "rubocop-rake"
15
- gem "rubocop-rspec"
16
- gem "simplecov"
17
- gem "webmock", "~> 3.13"
9
+ gem 'base64'
10
+ gem 'byebug'
11
+ gem 'cocina-models' # only used in tests
12
+ gem 'rake', '~> 13.0'
13
+ gem 'rspec', '~> 3.0'
14
+ gem 'rubocop', '~> 1.7'
15
+ gem 'rubocop-rake'
16
+ gem 'rubocop-rspec'
17
+ gem 'simplecov'
18
+ gem 'webmock', '~> 3.13'
data/Gemfile.lock CHANGED
@@ -1,72 +1,161 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- datacite (0.6.0)
4
+ datacite (0.8.0)
5
+ activesupport
5
6
  dry-monads (~> 1.3)
6
7
  faraday (~> 2.0)
8
+ json_schemer
7
9
  zeitwerk (~> 2.4)
8
10
 
9
11
  GEM
10
12
  remote: https://rubygems.org/
11
13
  specs:
14
+ activesupport (8.1.1)
15
+ base64
16
+ bigdecimal
17
+ concurrent-ruby (~> 1.0, >= 1.3.1)
18
+ connection_pool (>= 2.2.5)
19
+ drb
20
+ i18n (>= 1.6, < 2)
21
+ json
22
+ logger (>= 1.4.2)
23
+ minitest (>= 5.1)
24
+ securerandom (>= 0.3)
25
+ tzinfo (~> 2.0, >= 2.0.5)
26
+ uri (>= 0.13.1)
12
27
  addressable (2.8.7)
13
28
  public_suffix (>= 2.0.2, < 7.0)
14
29
  ast (2.4.3)
30
+ attr_extras (7.1.0)
15
31
  base64 (0.3.0)
16
- bigdecimal (3.2.1)
32
+ bigdecimal (3.3.1)
17
33
  byebug (12.0.0)
34
+ cocina-models (0.108.2)
35
+ activesupport
36
+ deprecation
37
+ dry-struct (~> 1.0)
38
+ dry-types (~> 1.1)
39
+ edtf
40
+ equivalent-xml
41
+ i18n
42
+ jsonpath
43
+ nokogiri
44
+ openapi_parser (~> 1.0)
45
+ super_diff
46
+ thor
47
+ zeitwerk (~> 2.1)
18
48
  concurrent-ruby (1.3.5)
19
- crack (1.0.0)
49
+ connection_pool (2.5.4)
50
+ crack (1.0.1)
20
51
  bigdecimal
21
52
  rexml
53
+ deprecation (1.1.0)
54
+ activesupport
22
55
  diff-lcs (1.6.2)
23
56
  docile (1.4.1)
57
+ drb (2.2.3)
24
58
  dry-core (1.1.0)
25
59
  concurrent-ruby (~> 1.0)
26
60
  logger
27
61
  zeitwerk (~> 2.6)
28
- dry-monads (1.8.3)
62
+ dry-inflector (1.2.0)
63
+ dry-logic (1.6.0)
64
+ bigdecimal
29
65
  concurrent-ruby (~> 1.0)
30
66
  dry-core (~> 1.1)
31
67
  zeitwerk (~> 2.6)
32
- faraday (2.13.1)
68
+ dry-monads (1.9.0)
69
+ concurrent-ruby (~> 1.0)
70
+ dry-core (~> 1.1)
71
+ zeitwerk (~> 2.6)
72
+ dry-struct (1.8.0)
73
+ dry-core (~> 1.1)
74
+ dry-types (~> 1.8, >= 1.8.2)
75
+ ice_nine (~> 0.11)
76
+ zeitwerk (~> 2.6)
77
+ dry-types (1.8.3)
78
+ bigdecimal (~> 3.0)
79
+ concurrent-ruby (~> 1.0)
80
+ dry-core (~> 1.0)
81
+ dry-inflector (~> 1.0)
82
+ dry-logic (~> 1.4)
83
+ zeitwerk (~> 2.6)
84
+ edtf (3.2.0)
85
+ activesupport (>= 3.0, < 9.0)
86
+ equivalent-xml (0.6.0)
87
+ nokogiri (>= 1.4.3)
88
+ faraday (2.14.0)
33
89
  faraday-net_http (>= 2.0, < 3.5)
34
90
  json
35
91
  logger
36
- faraday-net_http (3.4.0)
92
+ faraday-net_http (3.4.1)
37
93
  net-http (>= 0.5.0)
38
- hashdiff (1.2.0)
39
- json (2.12.2)
94
+ hana (1.3.7)
95
+ hashdiff (1.2.1)
96
+ i18n (1.14.7)
97
+ concurrent-ruby (~> 1.0)
98
+ ice_nine (0.11.2)
99
+ json (2.15.2)
100
+ json_schemer (2.4.0)
101
+ bigdecimal
102
+ hana (~> 1.3)
103
+ regexp_parser (~> 2.0)
104
+ simpleidn (~> 0.2)
105
+ jsonpath (1.1.5)
106
+ multi_json
40
107
  language_server-protocol (3.17.0.5)
41
108
  lint_roller (1.1.0)
42
109
  logger (1.7.0)
43
- net-http (0.6.0)
110
+ minitest (5.26.0)
111
+ multi_json (1.17.0)
112
+ net-http (0.7.0)
44
113
  uri
114
+ nokogiri (1.18.10-aarch64-linux-gnu)
115
+ racc (~> 1.4)
116
+ nokogiri (1.18.10-aarch64-linux-musl)
117
+ racc (~> 1.4)
118
+ nokogiri (1.18.10-arm-linux-gnu)
119
+ racc (~> 1.4)
120
+ nokogiri (1.18.10-arm-linux-musl)
121
+ racc (~> 1.4)
122
+ nokogiri (1.18.10-arm64-darwin)
123
+ racc (~> 1.4)
124
+ nokogiri (1.18.10-x86_64-darwin)
125
+ racc (~> 1.4)
126
+ nokogiri (1.18.10-x86_64-linux-gnu)
127
+ racc (~> 1.4)
128
+ nokogiri (1.18.10-x86_64-linux-musl)
129
+ racc (~> 1.4)
130
+ openapi_parser (1.0.0)
131
+ optimist (3.2.1)
45
132
  parallel (1.27.0)
46
- parser (3.3.8.0)
133
+ parser (3.3.10.0)
47
134
  ast (~> 2.4.1)
48
135
  racc
49
- prism (1.4.0)
136
+ patience_diff (1.2.0)
137
+ optimist (~> 3.0)
138
+ prism (1.6.0)
50
139
  public_suffix (6.0.2)
51
140
  racc (1.8.1)
52
141
  rainbow (3.1.1)
53
- rake (13.3.0)
54
- regexp_parser (2.10.0)
55
- rexml (3.4.1)
56
- rspec (3.13.1)
142
+ rake (13.3.1)
143
+ regexp_parser (2.11.3)
144
+ rexml (3.4.4)
145
+ rspec (3.13.2)
57
146
  rspec-core (~> 3.13.0)
58
147
  rspec-expectations (~> 3.13.0)
59
148
  rspec-mocks (~> 3.13.0)
60
- rspec-core (3.13.4)
149
+ rspec-core (3.13.6)
61
150
  rspec-support (~> 3.13.0)
62
151
  rspec-expectations (3.13.5)
63
152
  diff-lcs (>= 1.2.0, < 2.0)
64
153
  rspec-support (~> 3.13.0)
65
- rspec-mocks (3.13.5)
154
+ rspec-mocks (3.13.7)
66
155
  diff-lcs (>= 1.2.0, < 2.0)
67
156
  rspec-support (~> 3.13.0)
68
- rspec-support (3.13.4)
69
- rubocop (1.75.8)
157
+ rspec-support (3.13.6)
158
+ rubocop (1.81.7)
70
159
  json (~> 2.3)
71
160
  language_server-protocol (~> 3.17.0.2)
72
161
  lint_roller (~> 1.1.0)
@@ -74,46 +163,58 @@ GEM
74
163
  parser (>= 3.3.0.2)
75
164
  rainbow (>= 2.2.2, < 4.0)
76
165
  regexp_parser (>= 2.9.3, < 3.0)
77
- rubocop-ast (>= 1.44.0, < 2.0)
166
+ rubocop-ast (>= 1.47.1, < 2.0)
78
167
  ruby-progressbar (~> 1.7)
79
168
  unicode-display_width (>= 2.4.0, < 4.0)
80
- rubocop-ast (1.44.1)
169
+ rubocop-ast (1.47.1)
81
170
  parser (>= 3.3.7.2)
82
171
  prism (~> 1.4)
83
172
  rubocop-rake (0.7.1)
84
173
  lint_roller (~> 1.1)
85
174
  rubocop (>= 1.72.1)
86
- rubocop-rspec (3.6.0)
175
+ rubocop-rspec (3.7.0)
87
176
  lint_roller (~> 1.1)
88
177
  rubocop (~> 1.72, >= 1.72.1)
89
178
  ruby-progressbar (1.13.0)
179
+ securerandom (0.4.1)
90
180
  simplecov (0.22.0)
91
181
  docile (~> 1.1)
92
182
  simplecov-html (~> 0.11)
93
183
  simplecov_json_formatter (~> 0.1)
94
- simplecov-html (0.13.1)
184
+ simplecov-html (0.13.2)
95
185
  simplecov_json_formatter (0.1.4)
96
- unicode-display_width (3.1.4)
97
- unicode-emoji (~> 4.0, >= 4.0.4)
98
- unicode-emoji (4.0.4)
99
- uri (1.0.3)
100
- webmock (3.25.1)
186
+ simpleidn (0.2.3)
187
+ super_diff (0.17.0)
188
+ attr_extras (>= 6.2.4)
189
+ diff-lcs
190
+ patience_diff
191
+ thor (1.4.0)
192
+ tzinfo (2.0.6)
193
+ concurrent-ruby (~> 1.0)
194
+ unicode-display_width (3.2.0)
195
+ unicode-emoji (~> 4.1)
196
+ unicode-emoji (4.1.0)
197
+ uri (1.1.1)
198
+ webmock (3.26.1)
101
199
  addressable (>= 2.8.0)
102
200
  crack (>= 0.3.2)
103
201
  hashdiff (>= 0.4.0, < 2.0.0)
104
202
  zeitwerk (2.7.3)
105
203
 
106
204
  PLATFORMS
107
- arm64-darwin-23
108
- arm64-darwin-24
109
- x86_64-darwin-19
110
- x86_64-darwin-21
111
- x86_64-darwin-22
112
- x86_64-linux
205
+ aarch64-linux-gnu
206
+ aarch64-linux-musl
207
+ arm-linux-gnu
208
+ arm-linux-musl
209
+ arm64-darwin
210
+ x86_64-darwin
211
+ x86_64-linux-gnu
212
+ x86_64-linux-musl
113
213
 
114
214
  DEPENDENCIES
115
215
  base64
116
216
  byebug
217
+ cocina-models
117
218
  datacite!
118
219
  rake (~> 13.0)
119
220
  rspec (~> 3.0)
@@ -124,4 +225,4 @@ DEPENDENCIES
124
225
  webmock (~> 3.13)
125
226
 
126
227
  BUNDLED WITH
127
- 2.6.9
228
+ 2.7.2
data/README.md CHANGED
@@ -97,6 +97,26 @@ result.either(
97
97
  )
98
98
  ```
99
99
 
100
+ ## Working with Cocina
101
+
102
+ ### Validating
103
+
104
+ This gem provides a method for mapping and validating a `Cocina::Models::DRO` object to a DataCite request based on the DataCite JSON Schema (v4.6), without sending any data to the DataCite API:
105
+
106
+ ```ruby
107
+ cocina_object = Cocina::Models::DRO.new(...)
108
+ validator = Datacite::Validators::CocinaValidator.new(cocina_object:)
109
+ puts validator.errors.join(', ') unless validator.valid?
110
+ ```
111
+
112
+ NOTE: A Datacite request payload can be validated without first translating from Cocina if you build the request manually or use your own metadata mapping library, e.g.:
113
+
114
+ ```ruby
115
+ datacite_attributes = { ... }
116
+ validator = Datacite::Validators::AttributesValidator.new(attributes: datacite_attributes)
117
+ puts validator.errors.join(', ') unless validator.valid?
118
+ ```
119
+
100
120
  ## Development
101
121
 
102
122
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
- require "rubocop/rake_task"
8
+ require 'rubocop/rake_task'
9
9
 
10
10
  RuboCop::RakeTask.new
11
11
 
data/bin/console CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "bundler/setup"
5
- require "datacite"
4
+ require 'bundler/setup'
5
+ require 'datacite'
6
6
 
7
7
  # You can add fixtures and/or initialization code here to make experimenting
8
8
  # with your gem easier. You can also use a different console, if you like.
@@ -11,5 +11,5 @@ require "datacite"
11
11
  # require "pry"
12
12
  # Pry.start
13
13
 
14
- require "irb"
14
+ require 'irb'
15
15
  IRB.start(__FILE__)
data/datacite.gemspec CHANGED
@@ -1,22 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/datacite/version"
3
+ require_relative 'lib/datacite/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "datacite"
6
+ spec.name = 'datacite'
7
7
  spec.version = Datacite::VERSION
8
- spec.authors = ["Justin Coyne"]
9
- spec.email = ["jcoyne@justincoyne.com"]
8
+ spec.authors = ['Justin Coyne']
9
+ spec.email = ['jcoyne@justincoyne.com']
10
10
 
11
- spec.summary = "A Ruby client library for the DataCite REST API "
12
- spec.description = "See https://support.datacite.org/docs/api"
13
- spec.homepage = "https://github.com/sul-dlss/datacite-ruby"
14
- spec.required_ruby_version = ">= 3.0"
11
+ spec.summary = 'A Ruby client library for the DataCite REST API '
12
+ spec.description = 'See https://support.datacite.org/docs/api'
13
+ spec.homepage = 'https://github.com/sul-dlss/datacite-ruby'
14
+ spec.required_ruby_version = '>= 3.4'
15
15
 
16
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
17
17
 
18
- spec.metadata["homepage_uri"] = spec.homepage
19
- spec.metadata["source_code_uri"] = spec.homepage
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = spec.homepage
20
20
  # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
21
21
 
22
22
  # Specify which files should be added to the gem when it is released.
@@ -24,12 +24,14 @@ Gem::Specification.new do |spec|
24
24
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
25
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
26
26
  end
27
- spec.bindir = "exe"
27
+ spec.bindir = 'exe'
28
28
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
- spec.require_paths = ["lib"]
29
+ spec.require_paths = ['lib']
30
30
 
31
- spec.add_dependency "dry-monads", "~> 1.3"
32
- spec.add_dependency "faraday", "~> 2.0"
33
- spec.add_dependency "zeitwerk", "~> 2.4"
34
- spec.metadata["rubygems_mfa_required"] = "true"
31
+ spec.add_dependency 'activesupport'
32
+ spec.add_dependency 'dry-monads', '~> 1.3'
33
+ spec.add_dependency 'faraday', '~> 2.0'
34
+ spec.add_dependency 'json_schemer'
35
+ spec.add_dependency 'zeitwerk', '~> 2.4'
36
+ spec.metadata['rubygems_mfa_required'] = 'true'
35
37
  end
@@ -12,7 +12,7 @@ module Datacite
12
12
  def to_json(*_args)
13
13
  {
14
14
  data: {
15
- type: "dois",
15
+ type: 'dois',
16
16
  attributes: {
17
17
  prefix: prefix
18
18
  }
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "faraday"
4
- require "dry/monads"
3
+ require 'faraday'
4
+ require 'dry/monads'
5
5
 
6
6
  module Datacite
7
7
  # The connection to DataCite API
@@ -11,7 +11,7 @@ module Datacite
11
11
  # @param [String] username
12
12
  # @param [String] password
13
13
  # @param [String] host
14
- def initialize(username: nil, password: nil, host: "api.test.datacite.org")
14
+ def initialize(username: nil, password: nil, host: 'api.test.datacite.org')
15
15
  @conn = Faraday.new(
16
16
  url: "https://#{host}",
17
17
  headers: headers
@@ -85,14 +85,14 @@ module Datacite
85
85
 
86
86
  # @returns [Dry::Monads::Result]
87
87
  def register(request_body)
88
- response = conn.post("/dois", request_body)
88
+ response = conn.post('/dois', request_body)
89
89
  response.success? ? Success(Response.new(response)) : Failure(response)
90
90
  end
91
91
 
92
92
  def headers
93
93
  {
94
- "Content-Type" => "application/vnd.api+json",
95
- "User-Agent" => "Datacite Ruby client version #{Datacite::VERSION}"
94
+ 'Content-Type' => 'application/vnd.api+json',
95
+ 'User-Agent' => "Datacite Ruby client version #{Datacite::VERSION}"
96
96
  }
97
97
  end
98
98
 
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datacite
4
+ module Mapping
5
+ module FromCocina
6
+ # Maps alternative identifiers from cocina description to DataCite JSON
7
+ class AlternateIdentifiers
8
+ # @param [Cocina::Models::Description] description
9
+ def self.build(...)
10
+ new(...).call
11
+ end
12
+
13
+ def initialize(description:)
14
+ @description = description
15
+ end
16
+
17
+ attr_reader :description
18
+
19
+ delegate :purl, to: :description
20
+
21
+ def call
22
+ [{
23
+ alternateIdentifier: purl,
24
+ alternateIdentifierType: 'PURL'
25
+ }]
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/all'
4
+ require 'cocina/models'
5
+
6
+ module Datacite
7
+ module Mapping
8
+ module FromCocina
9
+ # Transform the Cocina::Models::DRO to a DataCite request attributes payload
10
+ class Attributes
11
+ # @param [Cocina::Models::DRO] cocina_object
12
+ # @return [Hash] Hash of DataCite attributes, conforming to the DataCite API Schema
13
+ def self.build(...)
14
+ new(...).call
15
+ end
16
+
17
+ def initialize(cocina_object:)
18
+ @cocina_object = cocina_object
19
+
20
+ # Set the time zone
21
+ Time.zone = 'Pacific Time (US & Canada)'
22
+ end
23
+
24
+ attr_reader :cocina_object
25
+
26
+ delegate :access, :description, :identification, to: :cocina_object
27
+
28
+ def call # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
29
+ {
30
+ event: 'publish',
31
+ url: description.purl,
32
+ identifiers: Identifiers.build(identification:),
33
+ titles: Titles.build(description:),
34
+ publisher: { name: 'Stanford Digital Repository' }, # per DataCite schema
35
+ publicationYear: publication_year,
36
+ subjects: Subject.build(description:),
37
+ dates: Date.build(cocina_object:),
38
+ language: 'en',
39
+ types: Types.build(description:),
40
+ alternateIdentifiers: AlternateIdentifiers.build(description:),
41
+ relatedIdentifiers: related_identifiers,
42
+ rightsList: RightsList.build(access:),
43
+ descriptions: Descriptions.build(description:),
44
+ relatedItems: related_items,
45
+ schemaVersion: 'http://datacite.org/schema/kernel-4'
46
+ }.merge(ContributorAttributes.build(description:)).compact
47
+ end
48
+
49
+ private
50
+
51
+ def publication_year
52
+ date = if access.embargo
53
+ access.embargo.releaseDate.to_datetime
54
+ else
55
+ Time.zone.today
56
+ end
57
+ date.year.to_s
58
+ end
59
+
60
+ def related_identifiers
61
+ Array(description&.relatedResource).filter_map do |related_resource|
62
+ RelatedResource.related_identifier_attributes(related_resource:)
63
+ end
64
+ end
65
+
66
+ def related_items
67
+ Array(description&.relatedResource).filter_map do |related_resource|
68
+ RelatedResource.related_item_attributes(related_resource:)
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end