Module: Serrano
- Extended by:
- Configuration
- Defined in:
- lib/serrano.rb,
lib/serrano/cn.rb,
lib/serrano/error.rb,
lib/serrano/filters.rb,
lib/serrano/request.rb,
lib/serrano/version.rb,
lib/serrano/cnrequest.rb,
lib/serrano/filterhandler.rb,
lib/serrano/request_cursor.rb
Overview
Serrano::RequestCursor
Class to perform HTTP requests to the Crossref API
Defined Under Namespace
Modules: Filters Classes: BadGateway, BadRequest, CNRequest, ContentNegotiation, Error, GatewayTimeout, InternalServerError, NotFound, Request, RequestCursor, ServiceUnavailable
Constant Summary collapse
- VERSION =
"1.4"
Class Method Summary collapse
- .assert_valid_filters(filters) ⇒ Object
-
.citation_count(doi:, url: "https://www.crossref.org/openurl/", key: "[email protected]", options: nil) ⇒ Object
Get a citation count with a DOI.
-
.content_negotiation(ids:, format: "bibtex", style: "apa", locale: "en-US") ⇒ Hash
Get citations in various formats from CrossRef.
-
.csl_styles ⇒ Object
Get csl styles.
- .filters ⇒ Object
-
.funders(ids: nil, query: nil, filter: nil, offset: nil, limit: nil, sample: nil, sort: nil, order: nil, facet: nil, select: nil, works: false, options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args) ⇒ Array
Search the funders route.
-
.journals(ids: nil, query: nil, filter: nil, offset: nil, limit: nil, sample: nil, sort: nil, order: nil, facet: nil, select: nil, works: false, options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args) ⇒ Array
Search the journals route.
-
.licenses(query: nil, offset: nil, limit: nil, sample: nil, sort: nil, order: nil, facet: nil, options: nil, verbose: false) ⇒ Array
Search the licenses route.
-
.members(ids: nil, query: nil, filter: nil, offset: nil, limit: nil, sample: nil, sort: nil, order: nil, facet: nil, select: nil, works: false, options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args) ⇒ Array
Search the members route.
-
.prefixes(ids:, filter: nil, offset: nil, limit: nil, sample: nil, sort: nil, order: nil, facet: nil, select: nil, works: false, options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args) ⇒ Array
Search the prefixes route.
-
.random_dois(sample: 10, options: nil, verbose: false) ⇒ Array
Get a random set of DOI’s.
-
.registration_agency(ids:, options: nil, verbose: false) ⇒ Array
Determine registration agency for DOIs.
-
.types(ids: nil, offset: nil, limit: nil, select: nil, works: false, options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args) ⇒ Array
Search the types route.
-
.works(ids: nil, query: nil, filter: nil, offset: nil, limit: nil, sample: nil, sort: nil, order: nil, facet: nil, select: nil, options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args) ⇒ Array
Search the works route.
Methods included from Configuration
Class Method Details
.assert_valid_filters(filters) ⇒ Object
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 |
# File 'lib/serrano.rb', line 673 def self.assert_valid_filters(filters) unless filters.is_a? Hash raise ArgumentError, <<~ERR Filters must be provided as a hash, like: Serrano.works(query: "something", filters: { has_abstract: true }) ERR end filters.each do |name, _| filter_strings = Filters.names.map(&:to_s) next if filter_strings.include?(name.to_s) raise ArgumentError, <<~ERR The filter "#{name}" is not a valid filter. Please run `Serrano.filters.filters` to see all valid filters. ERR end end |
.citation_count(doi:, url: "https://www.crossref.org/openurl/", key: "[email protected]", options: nil) ⇒ Object
Get a citation count with a DOI
more info on this Crossref API service.
651 652 653 654 655 656 657 658 659 660 661 |
# File 'lib/serrano.rb', line 651 def self.citation_count(doi:, url: "https://www.crossref.org/openurl/", key: "[email protected]", options: nil) args = {id: "doi:" + doi, pid: key, noredirect: true} opts = args.delete_if { |_k, v| v.nil? } conn = Faraday.new(url: url, request: ) res = conn.get "", opts x = res.body oc = REXML::Document.new("<doc>#{x}</doc>") REXML::XPath.first(oc, "//query").attributes["fl_count"].to_i end |
.content_negotiation(ids:, format: "bibtex", style: "apa", locale: "en-US") ⇒ Hash
Get citations in various formats from CrossRef
630 631 632 633 |
# File 'lib/serrano.rb', line 630 def self.content_negotiation(ids:, format: "bibtex", style: "apa", locale: "en-US") ids = Array(ids).map { |x| ERB::Util.url_encode(x) } CNRequest.new(ids, format, style, locale).perform end |
.csl_styles ⇒ Object
Get csl styles
669 670 671 |
# File 'lib/serrano.rb', line 669 def self.csl_styles fetch_styles end |
.filters ⇒ Object
4 5 6 |
# File 'lib/serrano/filters.rb', line 4 def self.filters Filters end |
.funders(ids: nil, query: nil, filter: nil, offset: nil, limit: nil, sample: nil, sort: nil, order: nil, facet: nil, select: nil, works: false, options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args) ⇒ Array
Funders without IDs don’t show up on the /funders route
Search the funders route
385 386 387 388 389 390 391 392 393 394 |
# File 'lib/serrano.rb', line 385 def self.funders(ids: nil, query: nil, filter: nil, offset: nil, limit: nil, sample: nil, sort: nil, order: nil, facet: nil, select: nil, works: false, options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args) assert_valid_filters(filter) if filter RequestCursor.new("funders", ids, query, filter, offset, limit, sample, sort, order, facet, select, works, nil, , verbose, cursor, cursor_max, args).perform end |
.journals(ids: nil, query: nil, filter: nil, offset: nil, limit: nil, sample: nil, sort: nil, order: nil, facet: nil, select: nil, works: false, options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args) ⇒ Array
Search the journals route
438 439 440 441 442 443 444 445 446 447 |
# File 'lib/serrano.rb', line 438 def self.journals(ids: nil, query: nil, filter: nil, offset: nil, limit: nil, sample: nil, sort: nil, order: nil, facet: nil, select: nil, works: false, options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args) assert_valid_filters(filter) if filter RequestCursor.new("journals", ids, query, filter, offset, limit, sample, sort, order, facet, select, works, nil, , verbose, cursor, cursor_max, args).perform end |
.licenses(query: nil, offset: nil, limit: nil, sample: nil, sort: nil, order: nil, facet: nil, options: nil, verbose: false) ⇒ Array
Search the licenses route
523 524 525 526 527 528 529 |
# File 'lib/serrano.rb', line 523 def self.licenses(query: nil, offset: nil, limit: nil, sample: nil, sort: nil, order: nil, facet: nil, options: nil, verbose: false) Request.new("licenses", nil, query, nil, offset, limit, sample, sort, order, facet, nil, nil, nil, , verbose).perform end |
.members(ids: nil, query: nil, filter: nil, offset: nil, limit: nil, sample: nil, sort: nil, order: nil, facet: nil, select: nil, works: false, options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args) ⇒ Array
Search the members route
284 285 286 287 288 289 290 291 292 293 |
# File 'lib/serrano.rb', line 284 def self.members(ids: nil, query: nil, filter: nil, offset: nil, limit: nil, sample: nil, sort: nil, order: nil, facet: nil, select: nil, works: false, options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args) assert_valid_filters(filter) if filter RequestCursor.new("members", ids, query, filter, offset, limit, sample, sort, order, facet, select, works, nil, , verbose, cursor, cursor_max, args).perform end |
.prefixes(ids:, filter: nil, offset: nil, limit: nil, sample: nil, sort: nil, order: nil, facet: nil, select: nil, works: false, options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args) ⇒ Array
Search the prefixes route
332 333 334 335 336 337 338 339 340 341 |
# File 'lib/serrano.rb', line 332 def self.prefixes(ids:, filter: nil, offset: nil, limit: nil, sample: nil, sort: nil, order: nil, facet: nil, select: nil, works: false, options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args) assert_valid_filters(filter) if filter RequestCursor.new("prefixes", ids, nil, filter, offset, limit, sample, sort, order, facet, select, works, nil, , verbose, cursor, cursor_max, args).perform end |
.random_dois(sample: 10, options: nil, verbose: false) ⇒ Array
This method uses works internally, but doesn’t allow you to pass on
Get a random set of DOI’s
arguments to that method.
564 565 566 567 568 |
# File 'lib/serrano.rb', line 564 def self.random_dois(sample: 10, options: nil, verbose: false) tmp = Request.new("works", nil, nil, nil, nil, nil, sample, nil, nil, nil, nil, false, nil, , verbose).perform tmp["message"]["items"].collect { |x| x["DOI"] } end |
.registration_agency(ids:, options: nil, verbose: false) ⇒ Array
Determine registration agency for DOIs
542 543 544 545 |
# File 'lib/serrano.rb', line 542 def self.registration_agency(ids:, options: nil, verbose: false) Request.new("works", ids, nil, nil, nil, nil, nil, nil, nil, nil, nil, false, true, , verbose).perform end |
.types(ids: nil, offset: nil, limit: nil, select: nil, works: false, options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args) ⇒ Array
Search the types route
483 484 485 486 487 488 489 |
# File 'lib/serrano.rb', line 483 def self.types(ids: nil, offset: nil, limit: nil, select: nil, works: false, options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args) RequestCursor.new("types", ids, nil, nil, offset, limit, nil, nil, nil, nil, select, works, nil, , verbose, cursor, cursor_max, args).perform end |
.works(ids: nil, query: nil, filter: nil, offset: nil, limit: nil, sample: nil, sort: nil, order: nil, facet: nil, select: nil, options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args) ⇒ Array
Search the works route
227 228 229 230 231 232 233 234 235 236 |
# File 'lib/serrano.rb', line 227 def self.works(ids: nil, query: nil, filter: nil, offset: nil, limit: nil, sample: nil, sort: nil, order: nil, facet: nil, select: nil, options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args) assert_valid_filters(filter) if filter RequestCursor.new("works", ids, query, filter, offset, limit, sample, sort, order, facet, select, nil, nil, , verbose, cursor, cursor_max, args).perform end |