Class: Uc3DmpCitation::Citer

Inherits:
Object
  • Object
show all
Defined in:
lib/uc3-dmp-citation.rb

Constant Summary collapse

DEFAULT_CITATION_STYLE =
'chicago-author-date'
DEFAULT_DOI_URL =
'http://doi.org'
DEFAULT_WORK_TYPE =
'Dataset'
DOI_REGEX =
%r{[0-9]{2}\.[0-9]{4,}/[a-zA-Z0-9/_.-]+}
MSG_BIBTEX_FAILURE =
'Unable to fetch Bibtex for the specified DOI.'
MSG_UNABLE_TO_UPDATE =
'Unable to update the citations on the DMP ID.'

Class Method Summary collapse

Class Method Details

.fetch_citation(doi:, logger: nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/uc3-dmp-citation.rb', line 24

def fetch_citation(doi:, logger: nil)
  uri = _doi_to_uri(doi: doi)
  return nil if uri.nil? || uri.blank?

  logger.debug(message: "Fetching BibTeX from: #{uri}") if logger.respond_to?(:debug)
  resp = Uc3DmpExternalApi::Client.call(url: uri, method: :get, additional_headers: headers, logger: logger)
  return nil if resp.nil? || resp.to_s.strip.empty?

  bibtex = BibTeX.parse(_cleanse_bibtex(text: resp))
  work_type = identifier['work_type'].nil? ? determine_work_type(bibtex: bibtex) :  identifier['work_type']
  _bibtex_to_citation(uri: uri, work_type: work_type, bibtex: bibtex)
end