hydra-remote_identifier 0.4.4 → 0.5.0

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: 06bf8800b2023776c3dcaf064c25de6a3e01778b
4
- data.tar.gz: 4619ca2b0114d02524d7045f5ecc07cf33791255
3
+ metadata.gz: 87813006e82d12d459d9ac9f003a9872092492cf
4
+ data.tar.gz: 16fe3b7b203515ef37e87fa1a11a21d6610600ab
5
5
  SHA512:
6
- metadata.gz: f7d15a5ddb6d06010753e69b532676790b699f2609ad202c054ba9736f3addf204e8cd7d4494d390b88251739e80467e467581ec56a0feec8ecd88a6599ecc85
7
- data.tar.gz: 094898fa1278674a3257aae36458879ae97fa1a22a0bb1bfa1440daf6370179675236b97d1962ae6ca72df1b8c00168ad056b0142798c1955d568319bd7c135a
6
+ metadata.gz: 6edb49259d5997f2e0b16939fb8c1424a544c1ed80e5b521681163a30a3295c442b9d00b12cfd20ecd52fd499dde059c6ec14dc18382300ff9051853e3aaaa95
7
+ data.tar.gz: 36a347aae24e33b6c93e9fb0355624e580cffe81dc8f16f6850746f64eee253055548016da9f067ccf215a4ea3cbeaea0fb530ccf7230c85116f15625ea330a2
@@ -0,0 +1,113 @@
1
+ # How to Contribute
2
+
3
+ We want your help to make Project Hydra great.
4
+ There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things.
5
+
6
+ ## Hydra Project Intellectual Property Licensing and Ownership
7
+
8
+ All code contributors must have an Individual Contributor License Agreement (iCLA) on file with the Hydra Project Steering Group.
9
+ If the contributor works for an institution, the institution must have a Corporate Contributor License Agreement (cCLA) on file.
10
+
11
+ https://wiki.duraspace.org/display/hydra/Hydra+Project+Intellectual+Property+Licensing+and+Ownership
12
+
13
+ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the project.
14
+
15
+ ## Contribution Tasks
16
+
17
+ * Reporting Issues
18
+ * Making Changes
19
+ * Submitting Changes
20
+ * Merging Changes
21
+
22
+ ### Reporting Issues
23
+
24
+ * Make sure you have a [GitHub account](https://github.com/signup/free)
25
+ * Submit a [Github issue](./issues) by:
26
+ * Clearly describing the issue
27
+ * Provide a descriptive summary
28
+ * Explain the expected behavior
29
+ * Explain the actual behavior
30
+ * Provide steps to reproduce the actual behavior
31
+
32
+ ### Making Changes
33
+
34
+ * Fork the repository on GitHub
35
+ * Create a topic branch from where you want to base your work.
36
+ * This is usually the master branch.
37
+ * To quickly create a topic branch based on master; `git branch fix/master/my_contribution master`
38
+ * Then checkout the new branch with `git checkout fix/master/my_contribution`.
39
+ * Please avoid working directly on the `master` branch.
40
+ * You may find the [hub suite of commands](https://github.com/defunkt/hub) helpful
41
+ * Make commits of logical units.
42
+ * Your commit should include a high level description of your work in HISTORY.textile
43
+ * Check for unnecessary whitespace with `git diff --check` before committing.
44
+ * Make sure your commit messages are [well formed](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
45
+ * If you created an issue, you can close it by including "Closes #issue" in your commit message. See [Github's blog post for more details](https://github.com/blog/1386-closing-issues-via-commit-messages)
46
+
47
+ ```
48
+ Present tense short summary (50 characters or less)
49
+
50
+ More detailed description, if necessary. It should be wrapped to 72
51
+ characters. Try to be as descriptive as you can, even if you think that
52
+ the commit content is obvious, it may not be obvious to others. You
53
+ should add such description also if it's already present in bug tracker,
54
+ it should not be necessary to visit a webpage to check the history.
55
+
56
+ Include Closes #<issue-number> when relavent.
57
+
58
+ Description can have multiple paragraphs and you can use code examples
59
+ inside, just indent it with 4 spaces:
60
+
61
+ class PostsController
62
+ def index
63
+ respond_with Post.limit(10)
64
+ end
65
+ end
66
+
67
+ You can also add bullet points:
68
+
69
+ - you can use dashes or asterisks
70
+
71
+ - also, try to indent next line of a point for readability, if it's too
72
+ long to fit in 72 characters
73
+ ```
74
+
75
+ * Make sure you have added the necessary tests for your changes.
76
+ * Run _all_ the tests to assure nothing else was accidentally broken.
77
+ * When you are ready to submit a pull request
78
+
79
+ ### Submitting Changes
80
+
81
+ [Detailed Walkthrough of One Pull Request per Commit](http://ndlib.github.io/practices/one-commit-per-pull-request/)
82
+
83
+ * Read the article ["Using Pull Requests"](https://help.github.com/articles/using-pull-requests) on GitHub.
84
+ * Make sure your branch is up to date with its parent branch (i.e. master)
85
+ * `git checkout master`
86
+ * `git pull --rebase`
87
+ * `git checkout <your-branch>`
88
+ * `git rebase master`
89
+ * It is likely a good idea to run your tests again.
90
+ * Squash the commits for your branch into one commit
91
+ * `git rebase --interactive HEAD~<number-of-commits>` ([See Github help](https://help.github.com/articles/interactive-rebase))
92
+ * To determine the number of commits on your branch: `git log master..<your-branch> --oneline | wc -l`
93
+ * Squashing your branch's changes into one commit is "good form" and helps the person merging your request to see everything that is going on.
94
+ * Push your changes to a topic branch in your fork of the repository.
95
+ * Submit a pull request from your fork to the project.
96
+
97
+ ### Merging Changes
98
+
99
+ * It is considered "poor from" to merge your own request.
100
+ * Please take the time to review the changes and get a sense of what is being changed. Things to consider:
101
+ * Does the commit message explain what is going on?
102
+ * Does the code changes have tests? _Not all changes need new tests, some changes are refactorings_
103
+ * Does the commit contain more than it should? Are two separate concerns being addressed in one commit?
104
+ * Did the Travis tests complete successfully?
105
+ * If you are uncertain, bring other contributors into the conversation by creating a comment that includes their @username.
106
+ * If you like the pull request, but want others to chime in, create a +1 comment and tag a user.
107
+
108
+ # Additional Resources
109
+
110
+ * [General GitHub documentation](http://help.github.com/)
111
+ * [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
112
+ * [Pro Git](http://git-scm.com/book) is both a free and excellent book about Git.
113
+ * [A Git Config for Contributing](http://ndlib.github.io/practices/my-typical-per-project-git-config/)
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Hydra::RemoteIdentifier
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/hydra-remote_identifier.png)](http://badge.fury.io/rb/hydra-remote_identifier)
4
+ [![Build Status](https://travis-ci.org/jeremyf/hydra-remote_identifier.png)](https://travis-ci.org/jeremyf/hydra-remote_identifier)
5
+
4
6
 
5
7
  Coordinate the registration and minting of remote identifiers for persisted
6
8
  objects.
@@ -54,11 +56,16 @@ Where you enqueue an asynchronous worker iterate over the requested identifiers:
54
56
  MintRemoteIdentifierWorker.enqueue(book.to_param, remote_service.name)
55
57
  end
56
58
 
57
- Where your asynchronouse worker does its work request the minting:
59
+ Where your asynchronous worker does its work request the minting:
58
60
 
59
61
  # Instantiate target from input
60
62
  Hydra::RemoteIdentifier.mint(remote_service_name, target)
61
63
 
64
+ In your show views you can provide a link to the remote identifier via
65
+ Hydra::RemoteIdentifier.remote_uri_for:
66
+
67
+ <%= link_to(object.doi, Hydra::RemoteIdentifier.remote_uri_for(:doi, object.doi)) %>
68
+
62
69
  ## Extending Hydra::RemoteIdentifier with alternate remote identifiers
63
70
 
64
71
  If you are interested in creating a new Hydra::RemoteIdentifier::RemoteService,
@@ -26,8 +26,13 @@ module Hydra::RemoteIdentifier
26
26
  # end
27
27
  #
28
28
  # @yieldparam config [Configuration]
29
+ # @see Hydra::RemoteIdentifier::Railtie
29
30
  def configure(&block)
30
31
  @configuration_block = block
32
+
33
+ # The Rails load sequence means that some of the configured Targets may
34
+ # not be loaded; As such I am not calling configure! instead relying on
35
+ # Hydra::RemoteIdentifier::Railtie to handle the configure! call
31
36
  configure! unless defined?(Rails)
32
37
  end
33
38
  attr_accessor :configuration
@@ -49,7 +54,7 @@ module Hydra::RemoteIdentifier
49
54
  # <% end %>
50
55
  #
51
56
  # @param remote_service_name [#to_s]
52
- # @param target [#registered_remote_identifier_minters] (see Hydra::RemoteIdentifier.configure)
57
+ # @param target [#registered_remote_identifier_minters]
53
58
  def with_registered_remote_service(remote_service_name, target)
54
59
  return false unless target.respond_to?(:registered_remote_identifier_minters)
55
60
  # @TODO - the registered remote identifier is more than a bit off;
@@ -61,6 +66,17 @@ module Hydra::RemoteIdentifier
61
66
  }
62
67
  end
63
68
 
69
+ # @example
70
+ # <%= link_to(object.doi, Hydra::RemoteIdentifier.remote_uri_for(:doi, object.doi)) %>
71
+ #
72
+ # @param remote_service_name [#to_s]
73
+ # @param identifier[#to_s] - An identifier that was created by the
74
+ # RemoteService derived from the given remote_service_name
75
+ # @returns [URI] - The URI for that identifier
76
+ def remote_uri_for(remote_service_name, identifier)
77
+ remote_service = configuration.find_remote_service(remote_service_name)
78
+ remote_service.remote_uri_for(identifier)
79
+ end
64
80
 
65
81
  # Yields each RemoteService#name that _is_ requested for the Target.
66
82
  #
@@ -69,7 +85,7 @@ module Hydra::RemoteIdentifier
69
85
  # Hydra::RemoteIdentifier.mint(remote_service_name, book)
70
86
  # end
71
87
  #
72
- # @param target [#registered_remote_identifier_minters] (see Hydra::RemoteIdentifier.configure)
88
+ # @param target [#registered_remote_identifier_minters]
73
89
  # @yield_param remote_service_name [#to_s]
74
90
  def requested_remote_identifiers_for(target)
75
91
  return false unless target.respond_to?(:registered_remote_identifier_minters)
@@ -89,7 +105,7 @@ module Hydra::RemoteIdentifier
89
105
  # Hydra::RemoteIdentifier.mint(:doi, book)
90
106
  #
91
107
  # @param remote_service_name [#to_s]
92
- # @param target [#registered_remote_identifier_minters] (see Hydra::RemoteIdentifier.configure)
108
+ # @param target [#registered_remote_identifier_minters]
93
109
  def mint(remote_service_name, target)
94
110
  return false unless target.respond_to?(:registered_remote_identifier_minters)
95
111
 
@@ -20,6 +20,10 @@ module Hydra::RemoteIdentifier
20
20
  remote_services.fetch(service_name)
21
21
  end
22
22
 
23
+ # @param service_name [#to_s]
24
+ # @param args - passed through to RemoteService initializer
25
+ #
26
+ # @yieldparam [Registration]
23
27
  def remote_service(service_name, *args)
24
28
  remote_service = remote_service_class_lookup(service_name).new(*args)
25
29
  remote_services[service_name] = remote_service
@@ -12,6 +12,8 @@ module Hydra::RemoteIdentifier
12
12
  @minting_coordinator = minting_coordinator
13
13
  end
14
14
 
15
+ # @param target_classes [Array]
16
+ # @yieldparam map [Map]
15
17
  def register(*target_classes, &map)
16
18
  if map.nil?
17
19
  raise RuntimeError, "You attempted to register the remote service #{remote_service} for #{target_classes} without a map"
@@ -16,15 +16,38 @@ module Hydra::RemoteIdentifier
16
16
  name.to_s
17
17
  end
18
18
 
19
+ # @param identifier[#to_s] - An identifier that was created by this remote
20
+ # service
21
+ # @returns [URI] - The URI for that identifier
22
+ def remote_uri_for(identifier)
23
+ raise NotImplementedError,
24
+ "You must implement #{self.class}#remote_uri_for(identifier)"
25
+ end
26
+
27
+ # When mapping a Target to a RemoteService, this is the name of the
28
+ # :attr_accessor that will be created on the Target; Helpful for form
29
+ # construction.
30
+ #
31
+ # @returns [Symbol]
19
32
  def accessor_name
20
33
  "mint_#{name}".to_sym
21
34
  end
22
35
 
36
+ # @param identifier[#to_s] - The name of an attribute that is
37
+ #
38
+ # @returns [boolean] - Is this a valid attribute to send as part of the
39
+ # payload for RemoteService#call
23
40
  def valid_attribute?(attribute_name)
24
41
  raise NotImplementedError,
25
42
  "You must implement #{self.class}#valid_attribute?"
26
43
  end
27
44
 
45
+ # @param payload[Hash] - A map with key/value pairs of valid attribute names
46
+ # and corresponding values that will be used to create the remote
47
+ # identifier
48
+ # @return - The remote identifier that was created
49
+ #
50
+ # @see RemoteService#valid_attribute?
28
51
  def call(payload)
29
52
  raise NotImplementedError,
30
53
  "You must implement #{self.class}#call"
@@ -14,17 +14,16 @@ module Hydra::RemoteIdentifier
14
14
  url: "https://n2t.net/ezid/"
15
15
  }
16
16
 
17
- attr_reader :uri
17
+ attr_reader :username, :password, :shoulder, :url
18
18
  def initialize(configuration = {})
19
- username = configuration.fetch(:username)
20
- password = configuration.fetch(:password)
21
- shoulder = configuration.fetch(:shoulder)
22
- url = configuration.fetch(:url)
23
-
24
- # This is specific for the creation of DOIs
25
- @uri = URI.parse(File.join(url, 'shoulder', shoulder))
26
- @uri.user = username
27
- @uri.password = password
19
+ @username = configuration.fetch(:username)
20
+ @password = configuration.fetch(:password)
21
+ @shoulder = configuration.fetch(:shoulder)
22
+ @url = configuration.fetch(:url)
23
+ end
24
+
25
+ def remote_uri_for(identifier)
26
+ URI.parse(File.join(url, identifier))
28
27
  end
29
28
 
30
29
  REQUIRED_ATTRIBUTES = ['target', 'creator', 'title', 'publisher', 'publicationyear' ].freeze
@@ -38,8 +37,15 @@ module Hydra::RemoteIdentifier
38
37
 
39
38
  private
40
39
 
40
+ def uri_for_create
41
+ uri_for_create = URI.parse(File.join(url, 'shoulder', shoulder))
42
+ uri_for_create.user = username
43
+ uri_for_create.password = password
44
+ uri_for_create
45
+ end
46
+
41
47
  def request(data)
42
- response = RestClient.post(uri.to_s, data, content_type: 'text/plain')
48
+ response = RestClient.post(uri_for_create.to_s, data, content_type: 'text/plain')
43
49
  matched_data = /\Asuccess:(.*)(?<doi>doi:[^\|]*)(.*)\Z/.match(response.body)
44
50
  matched_data[:doi].strip
45
51
  end
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module RemoteIdentifier
3
- VERSION = "0.4.4"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
@@ -15,6 +15,10 @@ module Hydra::RemoteIdentifier
15
15
  it { expect { subject.call(payload) }.to raise_error NotImplementedError }
16
16
  end
17
17
 
18
+ context '#remote_uri_for' do
19
+ it { expect { subject.remote_uri_for(double) }.to raise_error NotImplementedError }
20
+ end
21
+
18
22
  context '#valid_attribute?' do
19
23
  it { expect { subject.valid_attribute?(:attribute_name) }.to raise_error NotImplementedError }
20
24
  end
@@ -26,6 +26,13 @@ module Hydra::RemoteIdentifier
26
26
  expect(subject.call(payload)).to eq(expected_doi)
27
27
  end
28
28
  end
29
+
30
+ context '.remote_uri_for' do
31
+ let(:expected_uri) { URI.parse(File.join(subject.url, expected_doi))}
32
+ it 'should be based on configuration' do
33
+ expect(subject.remote_uri_for(expected_doi)).to eq(expected_uri)
34
+ end
35
+ end
29
36
  end
30
37
  end
31
38
  end
@@ -3,21 +3,6 @@ require File.expand_path('../../../../lib/hydra/remote_identifier', __FILE__)
3
3
  module Hydra::RemoteIdentifier
4
4
 
5
5
  describe 'public API' do
6
- before(:each) do
7
- Hydra::RemoteIdentifier.configure do |config|
8
- config.remote_service(:doi, doi_options) do |doi|
9
- doi.register(target_class) do |map|
10
- map.target :url
11
- map.creator :creator
12
- map.title :title
13
- map.publisher :publisher
14
- map.publicationyear :publicationyear
15
- map.set_identifier(:set_identifier=)
16
- end
17
- end
18
- end
19
- end
20
-
21
6
  let(:target_class) {
22
7
  Class.new {
23
8
  def url; 'http://google.com'; end
@@ -30,23 +15,27 @@ module Hydra::RemoteIdentifier
30
15
  }
31
16
 
32
17
  let(:target) { target_class.new }
33
-
34
18
  let(:expected_doi) {
35
- # From the doi-create cassette
36
- 'doi:10.5072/FK2FT8XZZ'
37
- }
38
-
39
- let(:doi_options) {
40
- {
41
- username: 'apitest',
42
- password: 'apitest',
43
- shoulder: 'doi:10.5072/FK2',
44
- url: "https://n2t.net/ezid/"
45
- }
19
+ 'doi:10.5072/FK2FT8XZZ' # From the doi-create cassette
46
20
  }
21
+ let(:doi_options) { RemoteServices::Doi::TEST_CONFIGURATION }
47
22
 
48
- describe '.with_remote_service' do
23
+ before(:each) do
24
+ Hydra::RemoteIdentifier.configure do |config|
25
+ config.remote_service(:doi, doi_options) do |doi|
26
+ doi.register(target_class) do |map|
27
+ map.target :url
28
+ map.creator :creator
29
+ map.title :title
30
+ map.publisher :publisher
31
+ map.publicationyear :publicationyear
32
+ map.set_identifier(:set_identifier=)
33
+ end
34
+ end
35
+ end
36
+ end
49
37
 
38
+ context '.with_registered_remote_service' do
50
39
  it 'should yield the service if one is registered' do
51
40
  expect {|block|
52
41
  Hydra::RemoteIdentifier.with_registered_remote_service(:doi, target, &block)
@@ -65,25 +54,16 @@ module Hydra::RemoteIdentifier
65
54
  Hydra::RemoteIdentifier.with_registered_remote_service(:doi, target, &block)
66
55
  }.to_not yield_control
67
56
  end
68
-
69
57
  end
70
58
 
71
- describe '.mint' do
72
-
73
- it 'works!', VCR::SpecSupport(record: :new_episodes, cassette_name: 'doi-integration') do
74
- expect {
75
- Hydra::RemoteIdentifier.mint(:doi, target)
76
- }.to change(target, :set_identifier).from(nil).to(expected_doi)
77
- end
78
-
79
- it 'returns false if the target is not configured for identifiers' do
80
- expect(Hydra::RemoteIdentifier.mint(:doi, double)).to eq(false)
81
- end
82
-
59
+ context '.remote_uri_for' do
60
+ it {
61
+ expect(Hydra::RemoteIdentifier.remote_uri_for(:doi, expected_doi)).
62
+ to eq(URI.parse(File.join(doi_options.fetch(:url), expected_doi)))
63
+ }
83
64
  end
84
65
 
85
- describe '.requested_remote_identifiers_for' do
86
-
66
+ context '.requested_remote_identifiers_for' do
87
67
  it 'should yield when the remote identifier was requested' do
88
68
  target.mint_doi = '1'
89
69
  expect { |block|
@@ -104,9 +84,20 @@ module Hydra::RemoteIdentifier
104
84
  Hydra::RemoteIdentifier.requested_remote_identifiers_for(target, &block)
105
85
  }.to_not yield_control
106
86
  end
87
+ end
88
+
89
+ context '.mint' do
90
+ it 'works!', VCR::SpecSupport(record: :new_episodes, cassette_name: 'doi-integration') do
91
+ expect {
92
+ Hydra::RemoteIdentifier.mint(:doi, target)
93
+ }.to change(target, :set_identifier).from(nil).to(expected_doi)
94
+ end
107
95
 
96
+ it 'returns false if the target is not configured for identifiers' do
97
+ expect(Hydra::RemoteIdentifier.mint(:doi, double)).to eq(false)
98
+ end
108
99
  end
109
100
 
110
101
  end
111
102
 
112
- end
103
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-remote_identifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-08 00:00:00.000000000 Z
11
+ date: 2013-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -97,6 +97,7 @@ files:
97
97
  - .gitignore
98
98
  - .rspec
99
99
  - .travis.yml
100
+ - CONTRIBUTING.md
100
101
  - Gemfile
101
102
  - Guardfile
102
103
  - LICENSE