serrano 0.6.0 → 1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +22 -0
- data/.github/workflows/ruby.yml +30 -0
- data/.gitignore +1 -1
- data/CHANGELOG.md +14 -0
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/README.md +11 -9
- data/Rakefile +22 -20
- data/lib/serrano/cn.rb +4 -4
- data/lib/serrano/cnrequest.rb +34 -48
- data/lib/serrano/faraday.rb +55 -53
- data/lib/serrano/filterhandler.rb +22 -22
- data/lib/serrano/filters.rb +67 -67
- data/lib/serrano/request.rb +29 -32
- data/lib/serrano/request_cursor.rb +48 -52
- data/lib/serrano/styles.rb +17 -17
- data/lib/serrano/utils.rb +8 -9
- data/lib/serrano/version.rb +1 -1
- data/lib/serrano.rb +69 -73
- data/serrano.gemspec +34 -33
- metadata +76 -75
- data/.rubocop.yml +0 -30
- data/.rubocop_todo.yml +0 -105
- data/.travis.yml +0 -11
- data/Gemfile.lock +0 -82
data/lib/serrano.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
|
12
|
-
require
|
13
|
-
require
|
3
|
+
require "erb"
|
4
|
+
require "serrano/version"
|
5
|
+
require "serrano/request"
|
6
|
+
require "serrano/request_cursor"
|
7
|
+
require "serrano/filterhandler"
|
8
|
+
require "serrano/cnrequest"
|
9
|
+
require "serrano/filters"
|
10
|
+
require "serrano/styles"
|
11
|
+
|
12
|
+
require "rexml/document"
|
13
|
+
require "rexml/xpath"
|
14
14
|
|
15
15
|
# @!macro serrano_params
|
16
16
|
# @param offset [Fixnum] Number of record to start at, any non-negative integer up to 10,000
|
@@ -42,8 +42,7 @@ require 'rexml/xpath'
|
|
42
42
|
# @param cursor [String] Cursor character string to do deep paging. Default is `nil`.
|
43
43
|
# Pass in '*' to start deep paging. Any combination of query, filters and facets may be
|
44
44
|
# used with deep paging cursors. While limit may be specified along with cursor, offset
|
45
|
-
# and sample cannot be used. See
|
46
|
-
# https://github.com/CrossRef/rest-api-doc/blob/master/rest_api.md#deep-paging-with-cursors
|
45
|
+
# and sample cannot be used. See https://api.crossref.org/
|
47
46
|
# @param cursor_max [Fixnum] Max records to retrieve. Only used when cursor
|
48
47
|
# param used. Because deep paging can result in continuous requests until all
|
49
48
|
# are retrieved, use this parameter to set a maximum number of records. Of course,
|
@@ -63,8 +62,7 @@ require 'rexml/xpath'
|
|
63
62
|
# - oauth [Hash] A hash with OAuth details
|
64
63
|
|
65
64
|
# @!macro field_queries
|
66
|
-
# @param [Hash<Object>] args Field queries, as named parameters. See
|
67
|
-
# https://github.com/CrossRef/rest-api-doc/blob/master/rest_api.md#field-queries
|
65
|
+
# @param [Hash<Object>] args Field queries, as named parameters. See https://api.crossref.org/
|
68
66
|
# Field query parameters mut be named, and must start with `query_`. Any dashes or
|
69
67
|
# periods should be replaced with underscores. The options include:
|
70
68
|
# - query_container_title: Query container-title aka. publication name
|
@@ -99,18 +97,16 @@ require 'rexml/xpath'
|
|
99
97
|
# For example, if you want to inspect headers returned from the HTTP request,
|
100
98
|
# and parse the raw result in any way you wish.
|
101
99
|
#
|
102
|
-
# @see https://
|
103
|
-
# detailed description of the Crossref API
|
100
|
+
# @see https://api.crossref.org for detailed description of the Crossref API
|
104
101
|
#
|
105
102
|
# What am I actually searching when using the Crossref search API?
|
106
103
|
#
|
107
|
-
# You are using the Crossref search API described at
|
108
|
-
# https://github.com/CrossRef/rest-api-doc/blob/master/rest_api.md.
|
104
|
+
# You are using the Crossref search API described at https://api.crossref.org
|
109
105
|
# When you search with query terms, on Crossref servers they are not
|
110
106
|
# searching full text, or even abstracts of articles, but only what is
|
111
107
|
# available in the data that is returned to you. That is, they search
|
112
108
|
# article titles, authors, etc. For some discussion on this, see
|
113
|
-
# https://gitlab.com/crossref/issues
|
109
|
+
# https://gitlab.com/crossref/issues/-/issues/101
|
114
110
|
#
|
115
111
|
#
|
116
112
|
# The Polite Pool
|
@@ -152,8 +148,8 @@ module Serrano
|
|
152
148
|
|
153
149
|
define_setting :access_token
|
154
150
|
define_setting :access_secret
|
155
|
-
define_setting :mailto, ENV[
|
156
|
-
define_setting :base_url,
|
151
|
+
define_setting :mailto, ENV["CROSSREF_EMAIL"]
|
152
|
+
define_setting :base_url, "https://api.crossref.org/"
|
157
153
|
|
158
154
|
##
|
159
155
|
# Search the works route
|
@@ -229,14 +225,14 @@ module Serrano
|
|
229
225
|
# # select certain fields
|
230
226
|
# Serrano.works(select: ['DOI', 'title'], limit: 3)
|
231
227
|
def self.works(ids: nil, query: nil, filter: nil, offset: nil,
|
232
|
-
|
233
|
-
|
234
|
-
|
228
|
+
limit: nil, sample: nil, sort: nil, order: nil, facet: nil,
|
229
|
+
select: nil, options: nil, verbose: false, cursor: nil,
|
230
|
+
cursor_max: 5000, **args)
|
235
231
|
|
236
232
|
assert_valid_filters(filter) if filter
|
237
|
-
RequestCursor.new(
|
238
|
-
|
239
|
-
|
233
|
+
RequestCursor.new("works", ids, query, filter, offset,
|
234
|
+
limit, sample, sort, order, facet, select, nil, nil, options,
|
235
|
+
verbose, cursor, cursor_max, args).perform
|
240
236
|
end
|
241
237
|
|
242
238
|
##
|
@@ -286,14 +282,14 @@ module Serrano
|
|
286
282
|
# # select certain fields
|
287
283
|
# Serrano.members(ids: 340, works: true, select: ['DOI', 'title'], limit: 3)
|
288
284
|
def self.members(ids: nil, query: nil, filter: nil, offset: nil,
|
289
|
-
|
290
|
-
|
291
|
-
|
285
|
+
limit: nil, sample: nil, sort: nil, order: nil, facet: nil,
|
286
|
+
select: nil, works: false, options: nil, verbose: false,
|
287
|
+
cursor: nil, cursor_max: 5000, **args)
|
292
288
|
|
293
289
|
assert_valid_filters(filter) if filter
|
294
|
-
RequestCursor.new(
|
295
|
-
|
296
|
-
|
290
|
+
RequestCursor.new("members", ids, query, filter, offset,
|
291
|
+
limit, sample, sort, order, facet, select, works, nil,
|
292
|
+
options, verbose, cursor, cursor_max, args).perform
|
297
293
|
end
|
298
294
|
|
299
295
|
##
|
@@ -334,14 +330,14 @@ module Serrano
|
|
334
330
|
# # select certain fields
|
335
331
|
# Serrano.prefixes(ids: "10.1016", works: true, select: ['DOI', 'title'], limit: 3)
|
336
332
|
def self.prefixes(ids:, filter: nil, offset: nil,
|
337
|
-
|
338
|
-
|
339
|
-
|
333
|
+
limit: nil, sample: nil, sort: nil, order: nil, facet: nil,
|
334
|
+
select: nil, works: false, options: nil, verbose: false,
|
335
|
+
cursor: nil, cursor_max: 5000, **args)
|
340
336
|
|
341
337
|
assert_valid_filters(filter) if filter
|
342
|
-
RequestCursor.new(
|
343
|
-
|
344
|
-
|
338
|
+
RequestCursor.new("prefixes", ids, nil, filter, offset,
|
339
|
+
limit, sample, sort, order, facet, select, works, nil,
|
340
|
+
options, verbose, cursor, cursor_max, args).perform
|
345
341
|
end
|
346
342
|
|
347
343
|
##
|
@@ -387,14 +383,14 @@ module Serrano
|
|
387
383
|
# # select certain fields
|
388
384
|
# Serrano.funders(ids: "10.13039/100000001", works: true, select: ['DOI', 'title'], limit: 3)
|
389
385
|
def self.funders(ids: nil, query: nil, filter: nil, offset: nil,
|
390
|
-
|
391
|
-
|
392
|
-
|
386
|
+
limit: nil, sample: nil, sort: nil, order: nil, facet: nil,
|
387
|
+
select: nil, works: false, options: nil, verbose: false,
|
388
|
+
cursor: nil, cursor_max: 5000, **args)
|
393
389
|
|
394
390
|
assert_valid_filters(filter) if filter
|
395
|
-
RequestCursor.new(
|
396
|
-
|
397
|
-
|
391
|
+
RequestCursor.new("funders", ids, query, filter, offset,
|
392
|
+
limit, sample, sort, order, facet, select, works, nil, options,
|
393
|
+
verbose, cursor, cursor_max, args).perform
|
398
394
|
end
|
399
395
|
|
400
396
|
##
|
@@ -440,14 +436,14 @@ module Serrano
|
|
440
436
|
# # select certain fields
|
441
437
|
# Serrano.journals(ids: "2167-8359", works: true, select: ['DOI', 'title'], limit: 3)
|
442
438
|
def self.journals(ids: nil, query: nil, filter: nil, offset: nil,
|
443
|
-
|
444
|
-
|
445
|
-
|
439
|
+
limit: nil, sample: nil, sort: nil, order: nil, facet: nil,
|
440
|
+
select: nil, works: false, options: nil, verbose: false,
|
441
|
+
cursor: nil, cursor_max: 5000, **args)
|
446
442
|
|
447
443
|
assert_valid_filters(filter) if filter
|
448
|
-
RequestCursor.new(
|
449
|
-
|
450
|
-
|
444
|
+
RequestCursor.new("journals", ids, query, filter, offset,
|
445
|
+
limit, sample, sort, order, facet, select, works, nil, options,
|
446
|
+
verbose, cursor, cursor_max, args).perform
|
451
447
|
end
|
452
448
|
|
453
449
|
##
|
@@ -485,11 +481,11 @@ module Serrano
|
|
485
481
|
# # select certain fields
|
486
482
|
# Serrano.types(ids: "journal", works: true, select: ['DOI', 'title'], limit: 3)
|
487
483
|
def self.types(ids: nil, offset: nil, limit: nil, select: nil, works: false,
|
488
|
-
|
484
|
+
options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args)
|
489
485
|
|
490
|
-
RequestCursor.new(
|
491
|
-
|
492
|
-
|
486
|
+
RequestCursor.new("types", ids, nil, nil, offset,
|
487
|
+
limit, nil, nil, nil, nil, select, works, nil, options,
|
488
|
+
verbose, cursor, cursor_max, args).perform
|
493
489
|
end
|
494
490
|
|
495
491
|
##
|
@@ -525,11 +521,11 @@ module Serrano
|
|
525
521
|
# Serrano.licenses()
|
526
522
|
# Serrano.licenses(limit: 3)
|
527
523
|
def self.licenses(query: nil, offset: nil,
|
528
|
-
|
529
|
-
|
524
|
+
limit: nil, sample: nil, sort: nil, order: nil,
|
525
|
+
facet: nil, options: nil, verbose: false)
|
530
526
|
|
531
|
-
Request.new(
|
532
|
-
|
527
|
+
Request.new("licenses", nil, query, nil, offset,
|
528
|
+
limit, sample, sort, order, facet, nil, nil, nil, options, verbose).perform
|
533
529
|
end
|
534
530
|
|
535
531
|
##
|
@@ -544,8 +540,8 @@ module Serrano
|
|
544
540
|
# Serrano.registration_agency(ids: '10.1371/journal.pone.0033693')
|
545
541
|
# Serrano.registration_agency(ids: ['10.1007/12080.1874-1746','10.1007/10452.1573-5125', '10.1111/(issn)1442-9993'])
|
546
542
|
def self.registration_agency(ids:, options: nil, verbose: false)
|
547
|
-
Request.new(
|
548
|
-
|
543
|
+
Request.new("works", ids, nil, nil, nil,
|
544
|
+
nil, nil, nil, nil, nil, nil, false, true, options, verbose).perform
|
549
545
|
end
|
550
546
|
|
551
547
|
##
|
@@ -566,9 +562,9 @@ module Serrano
|
|
566
562
|
# Serrano.random_dois(sample: 10)
|
567
563
|
# Serrano.random_dois(sample: 100)
|
568
564
|
def self.random_dois(sample: 10, options: nil, verbose: false)
|
569
|
-
tmp = Request.new(
|
570
|
-
|
571
|
-
tmp[
|
565
|
+
tmp = Request.new("works", nil, nil, nil, nil,
|
566
|
+
nil, sample, nil, nil, nil, nil, false, nil, options, verbose).perform
|
567
|
+
tmp["message"]["items"].collect { |x| x["DOI"] }
|
572
568
|
end
|
573
569
|
|
574
570
|
##
|
@@ -631,7 +627,7 @@ module Serrano
|
|
631
627
|
# '10.5167/UZH-38402','10.5167/UZH-41217']
|
632
628
|
# x = Serrano.content_negotiation(ids: dois)
|
633
629
|
# puts x
|
634
|
-
def self.content_negotiation(ids:, format:
|
630
|
+
def self.content_negotiation(ids:, format: "bibtex", style: "apa", locale: "en-US")
|
635
631
|
ids = Array(ids).map { |x| ERB::Util.url_encode(x) }
|
636
632
|
CNRequest.new(ids, format, style, locale).perform
|
637
633
|
end
|
@@ -643,7 +639,8 @@ module Serrano
|
|
643
639
|
# @param url [String] the API url for the function (should be left to default)
|
644
640
|
# @param key [String] your API key
|
645
641
|
#
|
646
|
-
# @see
|
642
|
+
# @see https://www.crossref.org/documentation/retrieve-metadata/openurl/ for
|
643
|
+
# more info on this Crossref API service.
|
647
644
|
#
|
648
645
|
# @example
|
649
646
|
# require 'serrano'
|
@@ -651,17 +648,16 @@ module Serrano
|
|
651
648
|
# Serrano.citation_count(doi: "10.1016/j.fbr.2012.01.001")
|
652
649
|
# # DOI not found
|
653
650
|
# Serrano.citation_count(doi: "10.1016/j.fbr.2012")
|
654
|
-
def self.citation_count(doi:, url:
|
655
|
-
|
651
|
+
def self.citation_count(doi:, url: "https://www.crossref.org/openurl/",
|
652
|
+
key: "cboettig@ropensci.org", options: nil)
|
656
653
|
|
657
|
-
args = {
|
654
|
+
args = {id: "doi:" + doi, pid: key, noredirect: true}
|
658
655
|
opts = args.delete_if { |_k, v| v.nil? }
|
659
656
|
conn = Faraday.new(url: url, request: options)
|
660
|
-
res = conn.get
|
657
|
+
res = conn.get "", opts
|
661
658
|
x = res.body
|
662
659
|
oc = REXML::Document.new("<doc>#{x}</doc>")
|
663
|
-
|
664
|
-
value
|
660
|
+
REXML::XPath.first(oc, "//query").attributes["fl_count"].to_i
|
665
661
|
end
|
666
662
|
|
667
663
|
# Get csl styles
|
data/serrano.gemspec
CHANGED
@@ -1,50 +1,51 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
lib = File.expand_path(
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require
|
5
|
+
require "serrano/version"
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
|
-
s.name
|
9
|
-
s.version
|
10
|
-
s.platform
|
11
|
-
s.required_ruby_version =
|
12
|
-
s.
|
13
|
-
s.
|
14
|
-
s.
|
15
|
-
s.
|
16
|
-
s.
|
17
|
-
s.
|
18
|
-
s.licenses = 'MIT'
|
8
|
+
s.name = "serrano"
|
9
|
+
s.version = Serrano::VERSION
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
s.required_ruby_version = ">= 2.1"
|
12
|
+
s.summary = "Crossref Client"
|
13
|
+
s.description = "Low Level Ruby Client for the Crossref Search API"
|
14
|
+
s.authors = "Scott Chamberlain"
|
15
|
+
s.email = "myrmecocystus@gmail.com"
|
16
|
+
s.homepage = "https://github.com/sckott/serrano"
|
17
|
+
s.licenses = "MIT"
|
19
18
|
|
20
19
|
s.files = `git ls-files -z`.split("\x0").reject do |f|
|
21
20
|
f.match(%r{^(test|spec|features)/})
|
22
21
|
end
|
23
|
-
s.require_paths = [
|
22
|
+
s.require_paths = ["lib"]
|
24
23
|
|
25
|
-
s.bindir
|
26
|
-
s.executables = [
|
24
|
+
s.bindir = "bin"
|
25
|
+
s.executables = ["serrano"]
|
27
26
|
|
28
|
-
s.add_development_dependency
|
29
|
-
s.add_development_dependency
|
30
|
-
s.add_development_dependency
|
31
|
-
s.add_development_dependency
|
32
|
-
s.add_development_dependency
|
33
|
-
s.add_development_dependency
|
34
|
-
s.add_development_dependency
|
35
|
-
s.add_development_dependency
|
36
|
-
s.add_development_dependency
|
27
|
+
s.add_development_dependency "bundler", "~> 2.1", ">= 2.1.4"
|
28
|
+
s.add_development_dependency "codecov", "~> 0.5.0"
|
29
|
+
s.add_development_dependency "json", "~> 2.3", ">= 2.3.1"
|
30
|
+
s.add_development_dependency "rake", "~> 13.0", ">= 13.0.1"
|
31
|
+
s.add_development_dependency "standard", "~> 1.0"
|
32
|
+
s.add_development_dependency "simplecov", "~> 0.21.2"
|
33
|
+
s.add_development_dependency "test-unit", "~> 3.3", ">= 3.3.6"
|
34
|
+
s.add_development_dependency "vcr", "~> 6.1"
|
35
|
+
s.add_development_dependency "webmock", "~> 3.14"
|
37
36
|
|
38
|
-
s.add_runtime_dependency
|
39
|
-
s.add_runtime_dependency
|
40
|
-
s.add_runtime_dependency
|
41
|
-
s.add_runtime_dependency
|
37
|
+
s.add_runtime_dependency "faraday", "~> 2.2"
|
38
|
+
s.add_runtime_dependency "faraday-follow_redirects", "~> 0.1.0"
|
39
|
+
s.add_runtime_dependency "multi_json", "~> 1.15"
|
40
|
+
s.add_runtime_dependency "rexml", "~> 3.2", ">= 3.2.5"
|
41
|
+
s.add_runtime_dependency "thor", "~> 1.2", ">= 1.2.1"
|
42
42
|
|
43
43
|
s.metadata = {
|
44
|
-
|
45
|
-
|
44
|
+
"homepage_uri" => "https://github.com/sckott/serrano",
|
45
|
+
"documentation_uri" => "https://www.rubydoc.info/gems/serrano",
|
46
|
+
"changelog_uri" =>
|
46
47
|
"https://github.com/sckott/serrano/releases/tag/v#{s.version}",
|
47
|
-
|
48
|
-
|
48
|
+
"source_code_uri" => "https://github.com/sckott/serrano",
|
49
|
+
"bug_tracker_uri" => "https://github.com/sckott/serrano/issues"
|
49
50
|
}
|
50
51
|
end
|