Skip to content

Commit

Permalink
fix lookup dois in handle server. datacite/datacite#685
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Apr 18, 2019
1 parent 01ceb5e commit 56d3f9a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
6 changes: 2 additions & 4 deletions app/models/concerns/helpable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ module ClassMethods
def get_dois(options={})
return OpenStruct.new(body: { "errors" => [{ "title" => "Prefix missing" }] }) unless options[:prefix].present?

count_url = Rails.env.production? ? "https://doi.org" : "https://handle.test.datacite.org"
count_url += "/api/handles?prefix=#{options[:prefix]}&pageSize=0"
count_url = ENV['HANDLE_URL'] + "/api/handles?prefix=#{options[:prefix]}&pageSize=0"
response = Maremma.get(count_url, username: "300%3A#{ENV['HANDLE_USERNAME']}", password: ENV['HANDLE_PASSWORD'], ssl_self_signed: true, timeout: 60)

total = response.body.dig("data", "totalCount").to_i
Expand All @@ -123,8 +122,7 @@ def get_dois(options={})
total_pages = (total.to_f / 1000).ceil

(0...total_pages).each do |page|
url = Rails.env.production? ? "https://doi.org" : "https://handle.test.datacite.org"
url += "/api/handles?prefix=#{options[:prefix]}&page=#{page}&pageSize=1000"
url = ENV['HANDLE_URL'] + "/api/handles?prefix=#{options[:prefix]}&page=#{page}&pageSize=1000"
response = Maremma.get(url, username: "300%3A#{ENV['HANDLE_USERNAME']}", password: ENV['HANDLE_PASSWORD'], ssl_self_signed: true, timeout: 60)
if response.status == 200
dois += (response.body.dig("data", "handles") || [])
Expand Down
Loading

0 comments on commit 56d3f9a

Please sign in to comment.