serrano 0.6.0 → 1.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/serrano.rb CHANGED
@@ -1,16 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
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'
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://github.com/CrossRef/rest-api-doc/blob/master/rest_api.md for
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/issues/101
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['CROSSREF_EMAIL']
156
- define_setting :base_url, 'https://api.crossref.org/'
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
- limit: nil, sample: nil, sort: nil, order: nil, facet: nil,
233
- select: nil, options: nil, verbose: false, cursor: nil,
234
- cursor_max: 5000, **args)
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('works', ids, query, filter, offset,
238
- limit, sample, sort, order, facet, select, nil, nil, options,
239
- verbose, cursor, cursor_max, args).perform
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
- limit: nil, sample: nil, sort: nil, order: nil, facet: nil,
290
- select: nil, works: false, options: nil, verbose: false,
291
- cursor: nil, cursor_max: 5000, **args)
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('members', ids, query, filter, offset,
295
- limit, sample, sort, order, facet, select, works, nil,
296
- options, verbose, cursor, cursor_max, args).perform
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
- limit: nil, sample: nil, sort: nil, order: nil, facet: nil,
338
- select: nil, works: false, options: nil, verbose: false,
339
- cursor: nil, cursor_max: 5000, **args)
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('prefixes', ids, nil, filter, offset,
343
- limit, sample, sort, order, facet, select, works, nil,
344
- options, verbose, cursor, cursor_max, args).perform
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
- limit: nil, sample: nil, sort: nil, order: nil, facet: nil,
391
- select: nil, works: false, options: nil, verbose: false,
392
- cursor: nil, cursor_max: 5000, **args)
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('funders', ids, query, filter, offset,
396
- limit, sample, sort, order, facet, select, works, nil, options,
397
- verbose, cursor, cursor_max, args).perform
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
- limit: nil, sample: nil, sort: nil, order: nil, facet: nil,
444
- select: nil, works: false, options: nil, verbose: false,
445
- cursor: nil, cursor_max: 5000, **args)
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('journals', ids, query, filter, offset,
449
- limit, sample, sort, order, facet, select, works, nil, options,
450
- verbose, cursor, cursor_max, args).perform
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
- options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args)
484
+ options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args)
489
485
 
490
- RequestCursor.new('types', ids, nil, nil, offset,
491
- limit, nil, nil, nil, nil, select, works, nil, options,
492
- verbose, cursor, cursor_max, args).perform
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
- limit: nil, sample: nil, sort: nil, order: nil,
529
- facet: nil, options: nil, verbose: false)
524
+ limit: nil, sample: nil, sort: nil, order: nil,
525
+ facet: nil, options: nil, verbose: false)
530
526
 
531
- Request.new('licenses', nil, query, nil, offset,
532
- limit, sample, sort, order, facet, nil, nil, nil, options, verbose).perform
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('works', ids, nil, nil, nil,
548
- nil, nil, nil, nil, nil, nil, false, true, options, verbose).perform
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('works', nil, nil, nil, nil,
570
- nil, sample, nil, nil, nil, nil, false, nil, options, verbose).perform
571
- tmp['message']['items'].collect { |x| x['DOI'] }
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: 'bibtex', style: 'apa', locale: 'en-US')
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 http://labs.crossref.org/openurl/ for more info on this Crossref API service.
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: 'http://www.crossref.org/openurl/',
655
- key: 'cboettig@ropensci.org', options: nil)
651
+ def self.citation_count(doi:, url: "https://www.crossref.org/openurl/",
652
+ key: "cboettig@ropensci.org", options: nil)
656
653
 
657
- args = { id: 'doi:' + doi, pid: key, noredirect: true }
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 '', opts
657
+ res = conn.get "", opts
661
658
  x = res.body
662
659
  oc = REXML::Document.new("<doc>#{x}</doc>")
663
- value = REXML::XPath.first(oc, '//query').attributes['fl_count'].to_i
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('lib', __dir__)
3
+ lib = File.expand_path("lib", __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'serrano/version'
5
+ require "serrano/version"
6
6
 
7
7
  Gem::Specification.new do |s|
8
- s.name = 'serrano'
9
- s.version = Serrano::VERSION
10
- s.platform = Gem::Platform::RUBY
11
- s.required_ruby_version = '>= 2.1'
12
- s.date = '2020-02-18'
13
- s.summary = 'Crossref Client'
14
- s.description = 'Low Level Ruby Client for the Crossref Search API'
15
- s.authors = 'Scott Chamberlain'
16
- s.email = 'myrmecocystus@gmail.com'
17
- s.homepage = 'https://github.com/sckott/serrano'
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 = ['lib']
22
+ s.require_paths = ["lib"]
24
23
 
25
- s.bindir = 'bin'
26
- s.executables = ['serrano']
24
+ s.bindir = "bin"
25
+ s.executables = ["serrano"]
27
26
 
28
- s.add_development_dependency 'bundler', '~> 2.0', '>= 2.0.2'
29
- s.add_development_dependency 'codecov', '~> 0.1.10'
30
- s.add_development_dependency 'json', '~> 2.1'
31
- s.add_development_dependency 'rake', '~> 12.3', '>= 12.3.1'
32
- s.add_development_dependency 'rubocop', '~> 0.80.0'
33
- s.add_development_dependency 'simplecov', '~> 0.17.0'
34
- s.add_development_dependency 'test-unit', '~> 3.2', '>= 3.2.7'
35
- s.add_development_dependency 'vcr', '~> 5.0'
36
- s.add_development_dependency 'webmock', '~> 3.4', '>= 3.4.1'
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 'faraday', '>= 0.15', '< 1.0'
39
- s.add_runtime_dependency 'faraday_middleware', '>= 0.12.2', '< 0.15.0'
40
- s.add_runtime_dependency 'multi_json', '~> 1.13', '>= 1.13.1'
41
- s.add_runtime_dependency 'thor', '>= 0.20', '< 1.1'
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
- 'homepage_uri' => 'https://github.com/sckott/serrano',
45
- 'changelog_uri' =>
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
- 'source_code_uri' => 'https://github.com/sckott/serrano',
48
- 'bug_tracker_uri' => 'https://github.com/sckott/serrano/issues'
48
+ "source_code_uri" => "https://github.com/sckott/serrano",
49
+ "bug_tracker_uri" => "https://github.com/sckott/serrano/issues"
49
50
  }
50
51
  end