Class: PULDatacite
- Inherits:
-
Object
- Object
- PULDatacite
- Defined in:
- app/services/pul_datacite.rb
Instance Attribute Summary collapse
-
#datacite_connection ⇒ Object
readonly
Returns the value of attribute datacite_connection.
Class Method Summary collapse
-
.publish_test_doi? ⇒ Boolean
Determines whether or not a test DOI should be referenced (this avoids requests to the DOI API endpoint for non-production deployments).
Instance Method Summary collapse
- #draft_doi ⇒ Object
-
#initialize ⇒ PULDatacite
constructor
A new instance of PULDatacite.
Constructor Details
#initialize ⇒ PULDatacite
Returns a new instance of PULDatacite.
14 15 16 17 18 |
# File 'app/services/pul_datacite.rb', line 14 def initialize @datacite_connection = Datacite::Client.new(username: Rails.configuration.datacite.user, password: Rails.configuration.datacite.password, host: Rails.configuration.datacite.host) end |
Instance Attribute Details
#datacite_connection ⇒ Object (readonly)
Returns the value of attribute datacite_connection.
12 13 14 |
# File 'app/services/pul_datacite.rb', line 12 def datacite_connection @datacite_connection end |
Class Method Details
.publish_test_doi? ⇒ Boolean
Determines whether or not a test DOI should be referenced (this avoids requests to the DOI API endpoint for non-production deployments)
7 8 9 |
# File 'app/services/pul_datacite.rb', line 7 def publish_test_doi? (Rails.env.development? || Rails.env.test?) && Rails.configuration.datacite.user.blank? end |
Instance Method Details
#draft_doi ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/services/pul_datacite.rb', line 20 def draft_doi if PULDatacite.publish_test_doi? Rails.logger.info "Using hard-coded test DOI during development." "10.34770/tbd" else result = datacite_connection.autogenerate_doi(prefix: Rails.configuration.datacite.prefix) if result.success? result.success.doi else raise("Error generating DOI. #{result.failure.status} / #{result.failure.reason_phrase}") end end end |