hydra-remote_identifier 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6dd65def0770c56f479dbc71aaa0dc462603f1ad
4
- data.tar.gz: d79fbb1d6ce12a804369a4ef441598c1effa2fbb
3
+ metadata.gz: b96ecf3dd7c10241d67f8e45794d8d392f2dc5a8
4
+ data.tar.gz: d50f078a9a4dbabfd9ab4e70fbe12f7535da198a
5
5
  SHA512:
6
- metadata.gz: 29daa6481feda3dd6225bc112b38d6117c717ca50eac693bbe7a5f665c5958a8659fa400cb49f0e2e1bc0fff3da210d05b2358715bd932af99584e031142af7b
7
- data.tar.gz: 72ccf7cd67fa4cca2dc617858a760530f2c06537a0e79efc9d2ef9ce62f798d91e84b5a2b378730c05ce4af1fcb0b547ecdb544f90824023aa846151992a14ae
6
+ metadata.gz: 4427c065e94c4386c1f5b63a8f216c5d3b6a35107f9ae8eb59eedf56dbb284fad6587577956eeaf1aa407673581bbdc4ca4dbafe8fa5f35513058f5c0e429984
7
+ data.tar.gz: 4c5081a38b8ccecee029f6b5bfb1239b2292b5d1b0fe298770527c939d1ef959d38c35f0f4131f1639ebba60c66dfd4a67d5b8d43def8b1e8d3a700a58abd7df
@@ -0,0 +1,59 @@
1
+ require 'rails/generators'
2
+
3
+ class Hydra::RemoteIdentifier::DoiGenerator < Rails::Generators::Base
4
+ DEFAULT_CREDENTIALS_PATH = 'config/doi.yml'
5
+
6
+ desc 'Register the target class names as acceptable for DOI'
7
+ class_option :credentials_path, type: :string, default: DEFAULT_CREDENTIALS_PATH, desc: 'Where can we find your DOI credentials'
8
+ class_option :target, type: :string, default: ":permanent_uri", desc: "What is the object's permanent_uri"
9
+ class_option :creator, type: :string, default: ":creator", desc: "Name of the object's creator"
10
+ class_option :title, type: :string, default: ":title", desc: "Title of the created object"
11
+ class_option :publisher, type: :string, default: ":publisher", desc: "Publisher of the created object"
12
+ class_option :publication_year, type: :string, default: ":publication_year", desc: "Year the created object was published"
13
+ class_option :set_identifier, type: :string, default: ":set_doi_identifier", desc: "Method on object to call when DOI is set"
14
+ argument :targets, :type => :array, :default => [], :banner => "class_name class_name"
15
+
16
+ def insert_doi
17
+ inject_into_file(
18
+ "config/initializers/hydra-remote_identifier_config.rb",
19
+ after: /Hydra::RemoteIdentifier.*/
20
+ ) do
21
+
22
+ data = []
23
+ data << ""
24
+ data << %( doi_credentials = Psych.load_file("#{credentials_path}"))
25
+ data << %( config.remote_service(:doi, doi_credentials) do |doi|)
26
+ data << %( doi.register(#{normalized_targets}) do |map|)
27
+ data << %( map.target #{options.fetch('target')})
28
+ data << %( map.creator #{options.fetch('creator')})
29
+ data << %( map.title #{options.fetch('title')})
30
+ data << %( map.publisher #{options.fetch('publisher')})
31
+ data << %( map.publicationyear #{options.fetch('publication_year')})
32
+ data << %( map.set_identifier #{options.fetch('set_identifier')})
33
+ data << %( end)
34
+ data << %( end)
35
+ data << ""
36
+ data.join("\n")
37
+
38
+ end
39
+ end
40
+
41
+ def optionally_create_credentials_path
42
+ if credentials_path == DEFAULT_CREDENTIALS_PATH
43
+ require 'hydra/remote_identifier/remote_services/doi'
44
+ create_file(
45
+ credentials_path,
46
+ Hydra::RemoteIdentifier::RemoteServices::Doi::TEST_CONFIGURATION.to_yaml
47
+ )
48
+ end
49
+ end
50
+
51
+ private
52
+ def credentials_path
53
+ options.fetch('credentials_path')
54
+ end
55
+
56
+ def normalized_targets
57
+ targets.collect(&:classify).join(", ")
58
+ end
59
+ end
@@ -7,20 +7,19 @@ class Hydra::RemoteIdentifier::InstallGenerator < Rails::Generators::Base
7
7
 
8
8
  data << '# Register and configure remote identifiers for persisted objects'
9
9
  data << 'Hydra::RemoteIdentifier.configure do |config|'
10
- data << ''
11
- data << '# doi_credentials = Psych.load("/path/to/doi_credentials.yml")'
12
- data << '# config.remote_service(:doi, doi_credentials) do |doi|'
13
- data << '# doi.register(PersistedObject) do |map|'
14
- data << '# map.target :url'
15
- data << '# map.creator {|obj| obj.person_name }'
16
- data << '# map.title :title'
17
- data << '# map.publisher :publisher'
18
- data << '# map.publicationyear :publicationyear'
19
- data << '# map.set_identifier :set_doi_identifier='
20
- data << '# end'
21
- data << '# end'
22
- data << ''
10
+ data << ' # doi_credentials = Psych.load("/path/to/doi_credentials.yml")'
11
+ data << ' # config.remote_service(:doi, doi_credentials) do |doi|'
12
+ data << ' # doi.register(PersistedObject) do |map|'
13
+ data << ' # map.target :url'
14
+ data << ' # map.creator {|obj| obj.person_name }'
15
+ data << ' # map.title :title'
16
+ data << ' # map.publisher :publisher'
17
+ data << ' # map.publicationyear :publicationyear'
18
+ data << ' # map.set_identifier :set_doi_identifier='
19
+ data << ' # end'
20
+ data << ' # end'
23
21
  data << 'end'
22
+ data << ''
24
23
 
25
24
  data.join("\n")
26
25
  end
@@ -26,11 +26,17 @@ module Hydra::RemoteIdentifier
26
26
  # end
27
27
  #
28
28
  # @yieldparam config [Configuration]
29
+ def configure(&block)
30
+ @configuration_block = block
31
+ configure! unless defined?(Rails)
32
+ end
29
33
  attr_accessor :configuration
30
- def configure
34
+
35
+ def configure!
31
36
  self.configuration ||= Configuration.new
32
- yield(configuration)
37
+ @configuration_block.call(configuration)
33
38
  end
39
+ private :configure!
34
40
 
35
41
  # Yields the specified RemoteService if it _could_ be requested for the
36
42
  # Target.
@@ -2,6 +2,11 @@ module Hydra::RemoteIdentifier
2
2
  class Railtie < Rails::Railtie
3
3
  generators do
4
4
  require 'generators/hydra/remote_identifier/install_generator'
5
+ require 'generators/hydra/remote_identifier/doi_generator'
6
+ end
7
+
8
+ config.to_prepare do
9
+ Hydra::RemoteIdentifier.send(:configure!)
5
10
  end
6
11
  end
7
12
  end
@@ -6,6 +6,13 @@ require 'active_support/core_ext/hash/indifferent_access'
6
6
  module Hydra::RemoteIdentifier
7
7
  module RemoteServices
8
8
  class Doi < Hydra::RemoteIdentifier::RemoteService
9
+ TEST_CONFIGURATION =
10
+ {
11
+ username: 'apitest',
12
+ password: 'apitest',
13
+ shoulder: 'doi:10.5072/FK2',
14
+ url: "https://n2t.net/ezid/"
15
+ }
9
16
 
10
17
  attr_reader :uri
11
18
  def initialize(configuration = {})
@@ -38,13 +45,13 @@ module Hydra::RemoteIdentifier
38
45
  end
39
46
 
40
47
  def data_for_create(payload)
41
- [
42
- "_target: #{payload.fetch(:target)}",
43
- "datacite.creator: #{payload.fetch(:creator)}",
44
- "datacite.title: #{payload.fetch(:title)}",
45
- "datacite.publisher: #{payload.fetch(:publisher)}",
46
- "datacite.publicationyear: #{payload.fetch(:publicationyear)}"
47
- ].join("\n")
48
+ data = []
49
+ data << "_target: #{payload.fetch(:target)}"
50
+ data << "datacite.creator: #{payload.fetch(:creator)}"
51
+ data << "datacite.title: #{payload.fetch(:title)}"
52
+ data << "datacite.publisher: #{payload.fetch(:publisher)}"
53
+ data << "datacite.publicationyear: #{payload.fetch(:publicationyear)}"
54
+ data.join("\n")
48
55
  end
49
56
  end
50
57
  end
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module RemoteIdentifier
3
- VERSION = "0.4.2"
3
+ VERSION = "0.4.3"
4
4
  end
5
5
  end
@@ -5,14 +5,7 @@ module Hydra::RemoteIdentifier
5
5
  module RemoteServices
6
6
 
7
7
  describe Doi do
8
- let(:configuration) {
9
- {
10
- username: 'apitest',
11
- password: 'apitest',
12
- shoulder: 'doi:10.5072/FK2',
13
- url: "https://n2t.net/ezid/"
14
- }
15
- }
8
+ let(:configuration) { RemoteServices::Doi::TEST_CONFIGURATION }
16
9
  let(:payload) {
17
10
  {
18
11
  target: 'http://google.com',
@@ -29,7 +22,7 @@ module Hydra::RemoteIdentifier
29
22
  subject { RemoteServices::Doi.new(configuration) }
30
23
 
31
24
  context '.call' do
32
- it 'should post to remote service', VCR::SpecSupport.merge(cassette_name: 'doi-create') do
25
+ it 'should post to remote service', VCR::SpecSupport(cassette_name: 'doi-create') do
33
26
  expect(subject.call(payload)).to eq(expected_doi)
34
27
  end
35
28
  end
@@ -70,7 +70,7 @@ module Hydra::RemoteIdentifier
70
70
 
71
71
  describe '.mint' do
72
72
 
73
- it 'works!', VCR::SpecSupport.merge(record: :new_episodes, cassette_name: 'doi-integration') do
73
+ it 'works!', VCR::SpecSupport(record: :new_episodes, cassette_name: 'doi-integration') do
74
74
  expect {
75
75
  Hydra::RemoteIdentifier.mint(:doi, target)
76
76
  }.to change(target, :set_identifier).from(nil).to(expected_doi)
data/spec/spec_helper.rb CHANGED
@@ -3,11 +3,8 @@ $:.unshift File.join(GEM_ROOT, "lib")
3
3
 
4
4
  require 'vcr'
5
5
 
6
- module VCR::SpecSupport
7
- module_function
8
- def merge(options = {})
9
- {vcr: {record: :new_episodes}.merge(options)}
10
- end
6
+ def VCR::SpecSupport(options={})
7
+ {vcr: {record: :new_episodes}.merge(options)}
11
8
  end
12
9
 
13
10
  VCR.configure do |config|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-remote_identifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen
@@ -103,6 +103,7 @@ files:
103
103
  - README.md
104
104
  - Rakefile
105
105
  - hydra-remote_identifier.gemspec
106
+ - lib/generators/hydra/remote_identifier/doi_generator.rb
106
107
  - lib/generators/hydra/remote_identifier/install_generator.rb
107
108
  - lib/hydra/remote_identifier.rb
108
109
  - lib/hydra/remote_identifier/configuration.rb