lib/bolognese/readers/datacite_reader.rb in bolognese-0.9.34 vs lib/bolognese/readers/datacite_reader.rb in bolognese-0.9.35

- old
+ new

@@ -2,13 +2,14 @@ module Readers module DataciteReader def get_datacite(id: nil, **options) return nil unless id.present? + search_url = options[:sandbox] ? "https://search.test.datacite.org/api" : "https://search.datacite.org/api" + doi = doi_from_url(id) - url = options.fetch(:search_url, nil).presence || "https://search.datacite.org/api" - url += "?q=doi:#{doi}&fl=doi,xml,allocator_symbol,datacentre_symbol,media,minted,updated&wt=json" + url = search_url + "?q=doi:#{doi}&fl=doi,xml,allocator_symbol,datacentre_symbol,media,minted,updated&wt=json" response = Maremma.get url attributes = response.body.dig("data", "response", "docs").first return nil unless attributes.present? @@ -25,13 +26,12 @@ "member_id" => attributes.fetch("allocator_symbol", nil), "data_center_id" => attributes.fetch("datacentre_symbol", nil), "url" => url } end - def read_datacite(string: nil) + def read_datacite(string: nil, **options) meta = string.present? ? Maremma.from_xml(string).fetch("resource", {}) : {} - - id = normalize_doi(meta.dig("identifier", "__content__")) + id = normalize_doi(meta.dig("identifier", "__content__"), sandbox: options[:sandbox]) doi = doi_from_url(id) 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)