Class: PULDatacite

Inherits:
Object
  • Object
show all
Defined in:
app/services/pul_datacite.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePULDatacite

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_connectionObject (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)

Returns:

  • (Boolean)


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_doiObject



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