lib/bolognese/readers/datacite_reader.rb in bolognese-0.9.56 vs lib/bolognese/readers/datacite_reader.rb in bolognese-0.9.58

- old
+ new

@@ -4,13 +4,13 @@ def get_datacite(id: nil, **options) return nil unless id.present? doi = doi_from_url(id) search_url = doi_search(id, options) - url = search_url + "?q=doi:#{doi}&fl=doi,xml,allocator_symbol,datacentre_symbol,media,minted,updated&wt=json" + search_url += "?q=doi:#{doi}&fl=doi,url,xml,allocator_symbol,datacentre_symbol,media,minted,updated&wt=json" - response = Maremma.get url + response = Maremma.get search_url attributes = response.body.dig("data", "response", "docs").first return nil unless attributes.present? string = attributes.fetch('xml', "PGhzaD48L2hzaD4=\n") string = Base64.decode64(string) @@ -28,10 +28,11 @@ end string = doc.to_s end { "string" => string, + "url" => attributes.fetch("url", nil), "date_registered" => attributes.fetch("minted", nil), "date_updated" => attributes.fetch("updated", nil), "provider_id" => attributes.fetch("allocator_symbol", nil), "client_id" => attributes.fetch("datacentre_symbol", nil) } end @@ -54,18 +55,10 @@ else id = normalize_doi(meta.dig("identifier", "__content__"), sandbox: options[:sandbox]) end doi = doi_from_url(id) - - if options[:url] - url = options[:url] - else - response = Maremma.head(id, limit: 0) - url = response.headers.present? ? response.headers["location"] : nil - end - resource_type_general = meta.dig("resourceType", "resourceTypeGeneral") type = Bolognese::Utils::DC_TO_SO_TRANSLATIONS[resource_type_general.to_s.dasherize] || "CreativeWork" title = Array.wrap(meta.dig("titles", "title")).map do |r| if r.is_a?(String) sanitize(r) @@ -104,10 +97,10 @@ "citeproc_type" => Bolognese::Utils::DC_TO_CP_TRANSLATIONS[resource_type_general.to_s.dasherize] || "article", "bibtex_type" => Bolognese::Utils::SO_TO_BIB_TRANSLATIONS[type] || "misc", "ris_type" => Bolognese::Utils::DC_TO_RIS_TRANSLATIONS[resource_type_general.to_s.dasherize] || "GEN", "resource_type_general" => resource_type_general, "doi" => doi, - "url" => url, + "url" => options.fetch(:url, nil), "title" => title, "alternate_name" => alternate_name, "author" => get_authors(meta.dig("creators", "creator")), "editor" => get_authors(Array.wrap(meta.dig("contributors", "contributor")).select { |r| r["contributorType"] == "Editor" }), "publisher" => meta.fetch("publisher", nil),