relaton-doi 1.18.0 → 1.18.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: addc79816fa3434eabc8467f9110a145f9e3b01540d0156aa2f3ff30ba257765
4
- data.tar.gz: 2ca981cedcb28ae5c6d7e99291b1657d659f6e63c5d73c03784c44632e20f7df
3
+ metadata.gz: 3b48dd4b37b780ce903cf5a8f55ac14d0af28b3d8b02fe62119bccddfe4526b3
4
+ data.tar.gz: 9ff9d9787377ac3707aaf15979215775cc2c8f09e5add367f086faac1ab45f8b
5
5
  SHA512:
6
- metadata.gz: d21faa242b40898145e610e4f26687291c47fd4064d49d400cb838a63473ab718e1d451021923bf15d4c3a40e6e828bd586a3244d316e611c6aaf35939f9d659
7
- data.tar.gz: 8522954e572b0bf6246cf1934c3a6498d72ccc9770dea6eb2280094bd06f693b1443b666b9548e477659d18dc8ae370512a5e8ecf5d6db0bbe05a6da4feb557c
6
+ metadata.gz: 130af41cc36abc26376728b40fa798e10ef907c03e3a4fc9a2c2b156436071419e2cbf58d569f867b03900e1301c2dd05431e1a036c91c8dc595c71968aed78d
7
+ data.tar.gz: 56227622d4d4d2d6644b2feabdd5454d7b039db9ca8b8c9bfe56db02fbbf8279815fa20f40c747e15d3528b67dcb696310870fff657d729a3924413405d1433c
data/README.adoc CHANGED
@@ -14,6 +14,8 @@ https://github.com/metanorma/metanorma-model-iso#iso-bibliographic-item[IsoBibli
14
14
  You can use it to retrieve metadata of Standards from https://crossref.org, and
15
15
  access such metadata through the `BibliographicItem` object.
16
16
 
17
+ To collect metadata this gem makes a few requests to the CrossRef API. It may take a few seconds to get the metadata.
18
+
17
19
  == Installation
18
20
 
19
21
  Add this line to your application's Gemfile:
@@ -1,7 +1,13 @@
1
+ require "faraday"
2
+
1
3
  module RelatonDoi
2
4
  module Crossref
3
5
  extend self
4
6
 
7
+ HEADER = {
8
+ "User-Agent" => "Relaton/RelatonDoi (https://www.relaton.org/guides/doi/; mailto:open.source@ribose.com)"
9
+ }.freeze
10
+
5
11
  #
6
12
  # Get a document by DOI from the CrossRef API.
7
13
  #
@@ -15,11 +21,13 @@ module RelatonDoi
15
21
  Util.warn "(#{doi}) Fetching from search.crossref.org ..."
16
22
  id = doi.sub(%r{^doi:}, "")
17
23
  message = get_by_id id
18
- Util.warn "(#{doi}) Found: `#{message['DOI']}`"
19
- Parser.parse message
20
- rescue Serrano::NotFound
21
- Util.warn "(#{doi}) Not found."
22
- nil
24
+ if message
25
+ Util.warn "(#{doi}) Found: `#{message['DOI']}`"
26
+ Parser.parse message
27
+ else
28
+ Util.warn("(#{doi}) Not found.")
29
+ nil
30
+ end
23
31
  end
24
32
 
25
33
  #
@@ -30,8 +38,24 @@ module RelatonDoi
30
38
  # @return [Hash] The document.
31
39
  #
32
40
  def get_by_id(id)
33
- resp = Serrano.works ids: id
34
- resp[0]["message"]
41
+ # resp = Serrano.works ids: id
42
+ n = 0
43
+ url = "https://api.crossref.org/works/#{CGI.escape(id)}"
44
+ loop do
45
+ resp = Faraday.get url, nil, HEADER
46
+ case resp.status
47
+ when 200
48
+ work = JSON.parse resp.body
49
+ return work["message"] if work["status"] == "ok"
50
+ when 404 then return nil
51
+ end
52
+
53
+ if n > 1
54
+ raise RelatonBib::RequestError, "Crossref error: #{resp.body}"
55
+ end
56
+ n += 1
57
+ sleep resp.headers["x-rate-limit-interval"].to_i * n
58
+ end
35
59
  end
36
60
  end
37
61
  end
@@ -47,5 +47,11 @@ module RelatonDoi
47
47
  def grammar_hash
48
48
  @grammar_hash ||= ::RelatonDoi.grammar_hash
49
49
  end
50
+
51
+ # Returns number of threads
52
+ # @return [Integer]
53
+ def threads
54
+ 2
55
+ end
50
56
  end
51
57
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonDoi
4
- VERSION = "1.18.0"
4
+ VERSION = "1.18.2"
5
5
  end
data/lib/relaton_doi.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "serrano"
3
+ # require "serrano"
4
4
  require "relaton_bipm"
5
5
  # require "relaton_iso_bib"
6
6
  # require "relaton_w3c"
@@ -13,9 +13,9 @@ require_relative "relaton_doi/util"
13
13
  require_relative "relaton_doi/parser"
14
14
  require_relative "relaton_doi/crossref"
15
15
 
16
- Serrano.configuration do |config|
17
- config.mailto = "open.source@ribose.com"
18
- end
16
+ # Serrano.configuration do |config|
17
+ # config.mailto = "open.source@ribose.com"
18
+ # end
19
19
 
20
20
  module RelatonDoi
21
21
  extend self
data/relaton-doi.gemspec CHANGED
@@ -40,7 +40,7 @@ Gem::Specification.new do |spec|
40
40
  spec.add_dependency "relaton-ietf", "~> 1.18.0"
41
41
  spec.add_dependency "relaton-nist", "~> 1.18.0"
42
42
  # spec.add_dependency "relaton-w3c", "~> 1.10.0"
43
- spec.add_dependency "serrano", "~> 1.4.0"
43
+ spec.add_dependency "faraday", "~> 2.7"
44
44
 
45
45
  # For more information and examples about making a new gem, checkout our
46
46
  # guide at: https://bundler.io/guides/creating_gem.html
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.18.0
4
+ version: 1.18.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: 2024-01-08 00:00:00.000000000 Z
11
+ date: 2024-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: relaton-bib
@@ -81,19 +81,19 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.18.0
83
83
  - !ruby/object:Gem::Dependency
84
- name: serrano
84
+ name: faraday
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 1.4.0
89
+ version: '2.7'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 1.4.0
96
+ version: '2.7'
97
97
  description: 'RelatonDOI: retrieve Standards for bibliographic using DOI through Crossrefand
98
98
  provide Relaton object.'
99
99
  email:
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  - !ruby/object:Gem::Version
143
143
  version: '0'
144
144
  requirements: []
145
- rubygems_version: 3.3.26
145
+ rubygems_version: 3.3.27
146
146
  signing_key:
147
147
  specification_version: 4
148
148
  summary: 'RelatonDOI: retrieve Standards for bibliographic using DOI through Crossrefand