Class: Hydra::RemoteIdentifier::RemoteServices::Doi
- Inherits:
-
Hydra::RemoteIdentifier::RemoteService
- Object
- Hydra::RemoteIdentifier::RemoteService
- Hydra::RemoteIdentifier::RemoteServices::Doi
- Defined in:
- lib/hydra/remote_identifier/remote_services/doi.rb
Constant Summary collapse
- TEST_CONFIGURATION =
{ username: 'apitest', password: 'apitest', shoulder: 'doi:10.5072/FK2', url: "https://ezid.lib.purdue.edu/", resolver_url: 'http://dx.doi.org/' }
- REQUIRED_ATTRIBUTES =
['target', 'creator', 'title', 'publisher', 'publicationyear' ].freeze
Instance Attribute Summary collapse
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#resolver_url ⇒ Object
readonly
Returns the value of attribute resolver_url.
-
#shoulder ⇒ Object
readonly
Returns the value of attribute shoulder.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #call(payload) ⇒ Object
-
#initialize(options = {}) ⇒ Doi
constructor
A new instance of Doi.
- #normalize_identifier(value) ⇒ Object
- #remote_uri_for(identifier) ⇒ Object
- #valid_attribute?(attribute_name) ⇒ Boolean
Methods inherited from Hydra::RemoteIdentifier::RemoteService
#accessor_name, #mint, #name, #registered?, #to_s
Constructor Details
#initialize(options = {}) ⇒ Doi
Returns a new instance of Doi.
20 21 22 23 24 25 26 27 |
# File 'lib/hydra/remote_identifier/remote_services/doi.rb', line 20 def initialize( = {}) configuration = .with_indifferent_access @username = configuration.fetch(:username) @password = configuration.fetch(:password) @shoulder = configuration.fetch(:shoulder) @url = configuration.fetch(:url) @resolver_url = configuration.fetch(:resolver_url) { default_resolver_url } end |
Instance Attribute Details
#password ⇒ Object (readonly)
Returns the value of attribute password.
19 20 21 |
# File 'lib/hydra/remote_identifier/remote_services/doi.rb', line 19 def password @password end |
#resolver_url ⇒ Object (readonly)
Returns the value of attribute resolver_url.
19 20 21 |
# File 'lib/hydra/remote_identifier/remote_services/doi.rb', line 19 def resolver_url @resolver_url end |
#shoulder ⇒ Object (readonly)
Returns the value of attribute shoulder.
19 20 21 |
# File 'lib/hydra/remote_identifier/remote_services/doi.rb', line 19 def shoulder @shoulder end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
19 20 21 |
# File 'lib/hydra/remote_identifier/remote_services/doi.rb', line 19 def url @url end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
19 20 21 |
# File 'lib/hydra/remote_identifier/remote_services/doi.rb', line 19 def username @username end |
Instance Method Details
#call(payload) ⇒ Object
45 46 47 |
# File 'lib/hydra/remote_identifier/remote_services/doi.rb', line 45 def call(payload) request(data_for_create(payload.with_indifferent_access)) end |
#normalize_identifier(value) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/hydra/remote_identifier/remote_services/doi.rb', line 29 def normalize_identifier(value) value.to_s.strip. sub(/\A#{resolver_url}/, ''). sub(/\A\s*doi:\s+/, 'doi:'). sub(/\A(\d)/, 'doi:\1') end |
#remote_uri_for(identifier) ⇒ Object
36 37 38 |
# File 'lib/hydra/remote_identifier/remote_services/doi.rb', line 36 def remote_uri_for(identifier) URI.parse(File.join(resolver_url, normalize_identifier(identifier))) end |
#valid_attribute?(attribute_name) ⇒ Boolean
41 42 43 |
# File 'lib/hydra/remote_identifier/remote_services/doi.rb', line 41 def valid_attribute?(attribute_name) REQUIRED_ATTRIBUTES.include?(attribute_name.to_s) end |