From f9f241d0b4bac6848f4b3dd9db192e91561a959f Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Mon, 17 Jun 2019 21:56:15 +0200 Subject: [PATCH] lookup url for crossref dois --- app/jobs/url_job.rb | 2 +- app/models/concerns/helpable.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/jobs/url_job.rb b/app/jobs/url_job.rb index bbaed531c..ea0098989 100644 --- a/app/jobs/url_job.rb +++ b/app/jobs/url_job.rb @@ -11,7 +11,7 @@ def perform(doi_id) doi = Doi.where(doi: doi_id).first if doi.present? - response = Doi.get_doi(doi: doi.doi) + response = Doi.get_doi(doi: doi.doi, agency: doi.agency) url = response.body.dig('data', 'values', 0, 'data', 'value') if url.present? if (doi.is_registered_or_findable? || %w(europ ethz crossref).include?(doi.provider_id)) && doi.minted.blank? diff --git a/app/models/concerns/helpable.rb b/app/models/concerns/helpable.rb index 1ecad142b..51ad50cd4 100644 --- a/app/models/concerns/helpable.rb +++ b/app/models/concerns/helpable.rb @@ -154,12 +154,12 @@ def get_dois(options={}) def get_doi(options={}) return OpenStruct.new(body: { "errors" => [{ "title" => "DOI missing" }] }) unless options[:doi].present? - url = Rails.env.production? ? "https://doi.org" : "https://handle.test.datacite.org" - url += "/api/handles/#{options[:doi]}" - response = Maremma.get(url, username: "300%3A#{ENV['HANDLE_USERNAME']}", password: ENV['HANDLE_PASSWORD'], ssl_self_signed: true, timeout: 10) + url = (Rails.env.production? || options[:agency] == "Crossref") ? "https://doi.org" : "https://handle.test.datacite.org" + url += "/#{options[:doi]}" + response = Maremma.get(url, ssl_self_signed: true, timeout: 10) if response.status == 200 - response + response.headers[:location] else text = "Error " + response.body["errors"].inspect