relaton-doi 1.20.1 → 1.20.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +1 -0
- data/lib/relaton_doi/crossref.rb +14 -2
- data/lib/relaton_doi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a2ee98f5c55309ec50367b65844a73f17c56f4f9333e13f6247d49556b01c2e9
|
|
4
|
+
data.tar.gz: 75ecddeaa14322883cdb8fd3920ea8f4305db25893c8df5c52c31bda35bd4344
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2ebb92c089cc1b5c769da6ee0589e328b758467e074cb283c47f2f8d006e44b8b4c581ea311d1fb816ef36f11bd2c278824f7afb02e4755f81bad5b288b93814
|
|
7
|
+
data.tar.gz: bf79f0ef9d6969330b0edcc05dcab3877aeb6cc0654eda3e85ceedcc78ce92343a307da125ba6f57a49d46adb7dc5230e4fa049ce60cd1b9f73cceaf6e911ec3
|
data/.github/workflows/rake.yml
CHANGED
data/lib/relaton_doi/crossref.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require "faraday"
|
|
2
|
+
require "uri"
|
|
2
3
|
|
|
3
4
|
module RelatonDoi
|
|
4
5
|
module Crossref
|
|
@@ -8,6 +9,8 @@ module RelatonDoi
|
|
|
8
9
|
"User-Agent" => "Relaton/RelatonDoi (https://www.relaton.org/guides/doi/; mailto:open.source@ribose.com)"
|
|
9
10
|
}.freeze
|
|
10
11
|
|
|
12
|
+
MAX_REDIRECTS = 5
|
|
13
|
+
|
|
11
14
|
#
|
|
12
15
|
# Get a document by DOI from the CrossRef API.
|
|
13
16
|
#
|
|
@@ -37,9 +40,9 @@ module RelatonDoi
|
|
|
37
40
|
#
|
|
38
41
|
# @return [Hash] The document.
|
|
39
42
|
#
|
|
40
|
-
def get_by_id(id) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
|
41
|
-
# resp = Serrano.works ids: id
|
|
43
|
+
def get_by_id(id) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
|
42
44
|
n = 0
|
|
45
|
+
redirects = 0
|
|
43
46
|
url = "https://api.crossref.org/works/#{CGI.escape(id)}"
|
|
44
47
|
loop do
|
|
45
48
|
resp = Faraday.get url, nil, HEADER
|
|
@@ -48,6 +51,15 @@ module RelatonDoi
|
|
|
48
51
|
work = JSON.parse resp.body
|
|
49
52
|
return work["message"] if work["status"] == "ok"
|
|
50
53
|
when 404 then return nil
|
|
54
|
+
when 301, 302
|
|
55
|
+
raise RelatonBib::RequestError, "Crossref error: too many redirects" if redirects >= MAX_REDIRECTS
|
|
56
|
+
|
|
57
|
+
location = resp.headers["location"] || resp.headers["Location"]
|
|
58
|
+
raise RelatonBib::RequestError, "Crossref error: redirect without Location" if location.nil? || location.empty?
|
|
59
|
+
|
|
60
|
+
url = URI.join(url, location).to_s
|
|
61
|
+
redirects += 1
|
|
62
|
+
next
|
|
51
63
|
end
|
|
52
64
|
|
|
53
65
|
if n > 1
|
data/lib/relaton_doi/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: relaton-doi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.20.
|
|
4
|
+
version: 1.20.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-04-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: relaton-bib
|