serrano
Advanced tools
| # This configuration was generated by | ||
| # `rubocop --auto-gen-config` | ||
| # on 2018-12-18 19:46:09 -0800 using RuboCop version 0.61.1. | ||
| # The point is for the user to remove these configuration records | ||
| # one by one as the offenses are removed from the code base. | ||
| # Note that changes in the inspected code, or installation of new | ||
| # versions of RuboCop, may require this file to be generated again. | ||
| # Offense count: 1 | ||
| # Configuration parameters: Include. | ||
| # Include: **/*.gemspec | ||
| Gemspec/RequiredRubyVersion: | ||
| Exclude: | ||
| - 'serrano.gemspec' | ||
| # Offense count: 32 | ||
| Metrics/AbcSize: | ||
| Max: 91 | ||
| # Offense count: 1 | ||
| # Configuration parameters: CountComments, ExcludedMethods. | ||
| # ExcludedMethods: refine | ||
| Metrics/BlockLength: | ||
| Max: 28 | ||
| # Offense count: 1 | ||
| # Configuration parameters: CountBlocks. | ||
| Metrics/BlockNesting: | ||
| Max: 4 | ||
| # Offense count: 2 | ||
| # Configuration parameters: CountComments. | ||
| Metrics/ClassLength: | ||
| Max: 367 | ||
| # Offense count: 5 | ||
| Metrics/CyclomaticComplexity: | ||
| Max: 11 | ||
| # Offense count: 20 | ||
| # Configuration parameters: CountComments, ExcludedMethods. | ||
| Metrics/MethodLength: | ||
| Max: 54 | ||
| # Offense count: 8 | ||
| Metrics/PerceivedComplexity: | ||
| Max: 15 | ||
| # Offense count: 7 | ||
| # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. | ||
| # AllowedNames: io, id, to, by, on, in, at, ip, db | ||
| Naming/UncommunicativeMethodParamName: | ||
| Exclude: | ||
| - 'lib/serrano/filterhandler.rb' | ||
| - 'lib/serrano/request_cursor.rb' | ||
| - 'lib/serrano/utils.rb' | ||
| # Offense count: 3 | ||
| # Cop supports --auto-correct. | ||
| # Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions. | ||
| # SupportedStyles: assign_to_condition, assign_inside_condition | ||
| Style/ConditionalAssignment: | ||
| Exclude: | ||
| - 'bin/serrano' | ||
| # Offense count: 6 | ||
| Style/Documentation: | ||
| Exclude: | ||
| - 'spec/**/*' | ||
| - 'test/**/*' | ||
| - 'bin/serrano' | ||
| - 'lib/serrano.rb' | ||
| - 'lib/serrano/cn.rb' | ||
| - 'lib/serrano/filters.rb' | ||
| - 'lib/serrano/utils.rb' | ||
| # Offense count: 1 | ||
| # Cop supports --auto-correct. | ||
| # Configuration parameters: EnforcedStyle. | ||
| # SupportedStyles: format, sprintf, percent | ||
| Style/FormatString: | ||
| Exclude: | ||
| - 'lib/serrano/utils.rb' | ||
| # Offense count: 1 | ||
| # Configuration parameters: . | ||
| # SupportedStyles: annotated, template, unannotated | ||
| Style/FormatStringToken: | ||
| EnforcedStyle: unannotated | ||
| # Offense count: 1 | ||
| # Configuration parameters: MinBodyLength. | ||
| Style/GuardClause: | ||
| Exclude: | ||
| - 'lib/serrano/response.rb' | ||
| # Offense count: 3 | ||
| # Cop supports --auto-correct. | ||
| Style/IfUnlessModifier: | ||
| Exclude: | ||
| - 'lib/serrano/cnrequest.rb' | ||
| - 'lib/serrano/utils.rb' | ||
| # Offense count: 1 | ||
| # Cop supports --auto-correct. | ||
| Style/SelfAssignment: | ||
| Exclude: | ||
| - 'lib/serrano/utils.rb' | ||
| # Offense count: 1 | ||
| # Cop supports --auto-correct. | ||
| # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. | ||
| # SupportedStyles: single_quotes, double_quotes | ||
| Style/StringLiterals: | ||
| Exclude: | ||
| - 'lib/serrano/utils.rb' | ||
| # Offense count: 198 | ||
| # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. | ||
| # URISchemes: http, https | ||
| Metrics/LineLength: | ||
| Max: 525 |
+14
| inherit_from: .rubocop_todo.yml | ||
| Naming/FileName: | ||
| Exclude: | ||
| - 'test/test-helper.rb' | ||
| Metrics/ParameterLists: | ||
| Max: 18 | ||
| # Offense count: 22 | ||
| # Configuration parameters: AllowedVariables. | ||
| Lint/UselessAssignment: | ||
| Exclude: | ||
| - 'lib/serrano/filters.rb' |
+2
-0
@@ -39,1 +39,3 @@ *.gem | ||
| lib/serrano/response.rb | ||
| cursor_testing.rb |
+7
-3
| language: ruby | ||
| cache: bundler | ||
| rvm: | ||
| - 2.1.8 | ||
| - 2.2.4 | ||
| - 2.5.0 | ||
| - 2.6.0 | ||
| before_install: | ||
| - gem update --system | ||
| - gem install bundler | ||
| - gem --version | ||
| script: | ||
| bundle exec rake test TESTOPTS="-v" | ||
| - bundle exec rake test TESTOPTS="-v" | ||
| - bundle exec rubocop |
+5
-0
@@ -0,1 +1,6 @@ | ||
| ## 0.5.2 (2019-08-07) | ||
| * fix url encoding (#51) | ||
| * started using Rubocop; many styling changes (#52) | ||
| ## 0.5.0 (2018-04-08) | ||
@@ -2,0 +7,0 @@ |
+2
-0
@@ -0,3 +1,5 @@ | ||
| # frozen_string_literal: true | ||
| source 'https://rubygems.org' | ||
| gemspec |
+42
-26
| PATH | ||
| remote: . | ||
| specs: | ||
| serrano (0.5.0) | ||
| faraday (~> 0.14.0) | ||
| faraday_middleware (~> 0.12.2) | ||
| serrano (0.5.2) | ||
| faraday (~> 0.15.0) | ||
| faraday_middleware (>= 0.12.2, < 0.14.0) | ||
| multi_json (~> 1.13, >= 1.13.1) | ||
@@ -13,5 +13,6 @@ thor (~> 0.20.0) | ||
| specs: | ||
| addressable (2.5.2) | ||
| addressable (2.6.0) | ||
| public_suffix (>= 2.0.2, < 4.0) | ||
| codecov (0.1.10) | ||
| ast (2.4.0) | ||
| codecov (0.1.14) | ||
| json | ||
@@ -22,16 +23,29 @@ simplecov | ||
| safe_yaml (~> 1.0.0) | ||
| docile (1.3.0) | ||
| faraday (0.14.0) | ||
| docile (1.3.2) | ||
| faraday (0.15.4) | ||
| multipart-post (>= 1.2, < 3) | ||
| faraday_middleware (0.12.2) | ||
| faraday_middleware (0.13.1) | ||
| faraday (>= 0.7.4, < 1.0) | ||
| hashdiff (0.3.7) | ||
| json (2.1.0) | ||
| hashdiff (1.0.0) | ||
| jaro_winkler (1.5.3) | ||
| json (2.2.0) | ||
| multi_json (1.13.1) | ||
| multipart-post (2.0.0) | ||
| power_assert (1.1.1) | ||
| public_suffix (3.0.2) | ||
| rake (12.3.1) | ||
| safe_yaml (1.0.4) | ||
| simplecov (0.16.1) | ||
| multipart-post (2.1.1) | ||
| parallel (1.17.0) | ||
| parser (2.6.3.0) | ||
| ast (~> 2.4.0) | ||
| power_assert (1.1.4) | ||
| public_suffix (3.1.1) | ||
| rainbow (3.0.0) | ||
| rake (12.3.3) | ||
| rubocop (0.74.0) | ||
| jaro_winkler (~> 1.5.1) | ||
| parallel (~> 1.10) | ||
| parser (>= 2.6) | ||
| rainbow (>= 2.2.2, < 4.0) | ||
| ruby-progressbar (~> 1.7) | ||
| unicode-display_width (>= 1.4.0, < 1.7) | ||
| ruby-progressbar (1.10.1) | ||
| safe_yaml (1.0.5) | ||
| simplecov (0.17.0) | ||
| docile (~> 1.1) | ||
@@ -41,11 +55,12 @@ json (>= 1.8, < 3) | ||
| simplecov-html (0.10.2) | ||
| test-unit (3.2.7) | ||
| test-unit (3.3.3) | ||
| power_assert | ||
| thor (0.20.0) | ||
| thor (0.20.3) | ||
| unicode-display_width (1.6.0) | ||
| url (0.3.2) | ||
| vcr (4.0.0) | ||
| webmock (3.3.0) | ||
| vcr (5.0.0) | ||
| webmock (3.6.2) | ||
| addressable (>= 2.3.6) | ||
| crack (>= 0.3.2) | ||
| hashdiff | ||
| hashdiff (>= 0.4.0, < 2.0.0) | ||
@@ -56,13 +71,14 @@ PLATFORMS | ||
| DEPENDENCIES | ||
| bundler (~> 1.16, >= 1.16.1) | ||
| bundler (~> 2.0, >= 2.0.2) | ||
| codecov (~> 0.1.10) | ||
| json (~> 2.1) | ||
| rake (~> 12.3, >= 12.3.1) | ||
| rubocop (~> 0.74.0) | ||
| serrano! | ||
| simplecov (~> 0.16.1) | ||
| simplecov (~> 0.17.0) | ||
| test-unit (~> 3.2, >= 3.2.7) | ||
| vcr (~> 4.0) | ||
| webmock (~> 3.3) | ||
| vcr (~> 5.0) | ||
| webmock (~> 3.4, >= 3.4.1) | ||
| BUNDLED WITH | ||
| 1.16.1 | ||
| 2.0.2 |
+112
-85
@@ -1,9 +0,12 @@ | ||
| require "serrano/version" | ||
| require "serrano/request" | ||
| require "serrano/request_cursor" | ||
| require "serrano/filterhandler" | ||
| require "serrano/cnrequest" | ||
| require "serrano/filters" | ||
| require "serrano/styles" | ||
| # frozen_string_literal: true | ||
| require 'erb' | ||
| require 'serrano/version' | ||
| require 'serrano/request' | ||
| require 'serrano/request_cursor' | ||
| require 'serrano/filterhandler' | ||
| require 'serrano/cnrequest' | ||
| require 'serrano/filters' | ||
| require 'serrano/styles' | ||
| require 'rexml/document' | ||
@@ -22,6 +25,6 @@ require 'rexml/xpath' | ||
| # deposited (time of most recent deposit), indexed (time of most recent index), | ||
| # published (publication date), published-print (print publication date), | ||
| # published-online (online publication date), issued (issued date (earliest known publication date)), | ||
| # is-referenced-by-count (number of times this DOI is referenced by other Crossref DOIs), or | ||
| # references-count (number of references included in the references section of the document | ||
| # published (publication date), published-print (print publication date), | ||
| # published-online (online publication date), issued (issued date (earliest known publication date)), | ||
| # is-referenced-by-count (number of times this DOI is referenced by other Crossref DOIs), or | ||
| # references-count (number of references included in the references section of the document | ||
| # identified by this DOI). Note: If the API call includes a query, then the sort | ||
@@ -36,3 +39,3 @@ # order will be by the relevance score. If no query is included, then the sort order | ||
| # a subset of elements to return. This can make your API calls much more efficient. Not | ||
| # clear yet which fields are allowed here. | ||
| # clear yet which fields are allowed here. | ||
| # @param verbose [Boolean] Print request headers to stdout. Default: false | ||
@@ -65,3 +68,3 @@ | ||
| # @!macro field_queries | ||
| # @param [Hash<Object>] args Field queries, as named parameters. See | ||
| # @param [Hash<Object>] args Field queries, as named parameters. See | ||
| # https://github.com/CrossRef/rest-api-doc/blob/master/rest_api.md#field-queries | ||
@@ -125,3 +128,3 @@ # Field query parameters mut be named, and must start with `query_`. Any dashes or | ||
| # block abusive users. | ||
| # | ||
| # | ||
| # We have been using `https` in `serrano` for a while now, so that's good | ||
@@ -131,4 +134,4 @@ # to go. To get into the Polite Pool, also set your `mailto` email address | ||
| # variable with the name `CROSSREF_EMAIL` and your mailto will be set | ||
| # for each request automatically. | ||
| # | ||
| # for each request automatically. | ||
| # | ||
| # require 'serrano' | ||
@@ -146,2 +149,8 @@ # Serrano.configuration do |config| | ||
| # limits are. | ||
| # | ||
| # | ||
| # URL Encoding | ||
| # We do URL encoding of DOIs for you for all methods except `Serrano.citation_count` | ||
| # which doesn't work if you encode DOIs beforehand. We use `ERB::Util.url_encode` | ||
| # to encode. | ||
@@ -153,4 +162,4 @@ module Serrano | ||
| define_setting :access_secret | ||
| define_setting :mailto, ENV["CROSSREF_EMAIL"] | ||
| define_setting :base_url, "https://api.crossref.org/" | ||
| define_setting :mailto, ENV['CROSSREF_EMAIL'] | ||
| define_setting :base_url, 'https://api.crossref.org/' | ||
@@ -203,3 +212,3 @@ ## | ||
| # Serrano.works(sample: 2) | ||
| # | ||
| # | ||
| # # select - pass an array or a comma separated string | ||
@@ -232,9 +241,9 @@ # Serrano.works(query: "ecology", select: "DOI,title", limit: 30) | ||
| 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) | ||
| limit: nil, sample: nil, sort: nil, order: nil, facet: nil, | ||
| select: nil, options: nil, verbose: false, cursor: nil, | ||
| cursor_max: 5000, **args) | ||
| RequestCursor.new('works', ids, query, filter, offset, | ||
| limit, sample, sort, order, facet, select, nil, nil, options, | ||
| verbose, cursor, cursor_max, args).perform | ||
| limit, sample, sort, order, facet, select, nil, nil, options, | ||
| verbose, cursor, cursor_max, args).perform | ||
| end | ||
@@ -289,9 +298,9 @@ | ||
| 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) | ||
| limit: nil, sample: nil, sort: nil, order: nil, facet: nil, | ||
| select: nil, works: false, options: nil, verbose: false, | ||
| cursor: nil, cursor_max: 5000, **args) | ||
| RequestCursor.new('members', ids, query, filter, offset, | ||
| limit, sample, sort, order, facet, select, works, nil, | ||
| options, verbose, cursor, cursor_max, args).perform | ||
| limit, sample, sort, order, facet, select, works, nil, | ||
| options, verbose, cursor, cursor_max, args).perform | ||
| end | ||
@@ -335,11 +344,11 @@ | ||
| # # select certain fields | ||
| # Serrano.prefixes(ids: "10.1016", works: true, select: ['DOI', 'title'], limit: 3) | ||
| # Serrano.prefixes(ids: "10.1016", works: true, select: ['DOI', 'title'], limit: 3) | ||
| 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) | ||
| limit: nil, sample: nil, sort: nil, order: nil, facet: nil, | ||
| select: nil, works: false, options: nil, verbose: false, | ||
| cursor: nil, cursor_max: 5000, **args) | ||
| RequestCursor.new('prefixes', ids, nil, filter, offset, | ||
| limit, sample, sort, order, facet, select, works, nil, | ||
| options, verbose, cursor, cursor_max, args).perform | ||
| limit, sample, sort, order, facet, select, works, nil, | ||
| options, verbose, cursor, cursor_max, args).perform | ||
| end | ||
@@ -388,11 +397,11 @@ | ||
| # # select certain fields | ||
| # Serrano.funders(ids: "10.13039/100000001", works: true, select: ['DOI', 'title'], limit: 3) | ||
| # Serrano.funders(ids: "10.13039/100000001", works: true, select: ['DOI', 'title'], limit: 3) | ||
| 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) | ||
| limit: nil, sample: nil, sort: nil, order: nil, facet: nil, | ||
| select: nil, works: false, options: nil, verbose: false, | ||
| cursor: nil, cursor_max: 5000, **args) | ||
| RequestCursor.new('funders', ids, query, filter, offset, | ||
| limit, sample, sort, order, facet, select, works, nil, options, | ||
| verbose, cursor, cursor_max, args).perform | ||
| limit, sample, sort, order, facet, select, works, nil, options, | ||
| verbose, cursor, cursor_max, args).perform | ||
| end | ||
@@ -441,11 +450,11 @@ | ||
| # # select certain fields | ||
| # Serrano.journals(ids: "2167-8359", works: true, select: ['DOI', 'title'], limit: 3) | ||
| # Serrano.journals(ids: "2167-8359", works: true, select: ['DOI', 'title'], limit: 3) | ||
| 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) | ||
| limit: nil, sample: nil, sort: nil, order: nil, facet: nil, | ||
| select: nil, works: false, options: nil, verbose: false, | ||
| cursor: nil, cursor_max: 5000, **args) | ||
| RequestCursor.new('journals', ids, query, filter, offset, | ||
| limit, sample, sort, order, facet, select, works, nil, options, | ||
| verbose, cursor, cursor_max, args).perform | ||
| limit, sample, sort, order, facet, select, works, nil, options, | ||
| verbose, cursor, cursor_max, args).perform | ||
| end | ||
@@ -464,3 +473,3 @@ | ||
| # a subset of elements to return. This can make your API calls much more efficient. Not | ||
| # clear yet which fields are allowed here. | ||
| # clear yet which fields are allowed here. | ||
| # @return [Array] An array of hashes | ||
@@ -487,9 +496,9 @@ # | ||
| # # select certain fields | ||
| # Serrano.types(ids: "journal", works: true, select: ['DOI', 'title'], limit: 3) | ||
| # Serrano.types(ids: "journal", works: true, select: ['DOI', 'title'], limit: 3) | ||
| def self.types(ids: nil, offset: nil, limit: nil, select: nil, works: false, | ||
| options: nil, verbose: false, cursor: nil, cursor_max: 5000, **args) | ||
| 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, options, | ||
| verbose, cursor, cursor_max, args).perform | ||
| limit, nil, nil, nil, nil, select, works, nil, options, | ||
| verbose, cursor, cursor_max, args).perform | ||
| end | ||
@@ -500,5 +509,24 @@ | ||
| # | ||
| # @!macro serrano_params | ||
| # @!macro serrano_options | ||
| # @param query [String] A query string | ||
| # @param offset [Fixnum] Number of record to start at, any non-negative integer up to 10,000 | ||
| # @param limit [Fixnum] Number of results to return. Not relavant when searching with specific dois. | ||
| # Default: 20. Max: 1000 | ||
| # @param sample [Fixnum] Number of random results to return. when you use the sample parameter, | ||
| # the limit and offset parameters are ignored. This parameter only used when works requested. | ||
| # Max: 100. | ||
| # @param sort [String] Field to sort on, one of score, relevance, | ||
| # updated (date of most recent change to metadata - currently the same as deposited), | ||
| # deposited (time of most recent deposit), indexed (time of most recent index), | ||
| # published (publication date), published-print (print publication date), | ||
| # published-online (online publication date), issued (issued date (earliest known publication date)), | ||
| # is-referenced-by-count (number of times this DOI is referenced by other Crossref DOIs), or | ||
| # references-count (number of references included in the references section of the document | ||
| # identified by this DOI). Note: If the API call includes a query, then the sort | ||
| # order will be by the relevance score. If no query is included, then the sort order | ||
| # will be by DOI update date. | ||
| # @param order [String] Sort order, one of 'asc' or 'desc' | ||
| # @param facet [Boolean/String] Include facet results OR a query (e.g., `license:*`) to facet by | ||
| # license. Default: false | ||
| # @param verbose [Boolean] Print request headers to stdout. Default: false | ||
| # @return [Array] An array of hashes | ||
@@ -512,7 +540,7 @@ # | ||
| def self.licenses(query: nil, offset: nil, | ||
| limit: nil, sample: nil, sort: nil, order: nil, | ||
| facet: nil, options: nil, verbose: false) | ||
| 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, options, verbose).perform | ||
| limit, sample, sort, order, facet, nil, nil, nil, options, verbose).perform | ||
| end | ||
@@ -532,5 +560,4 @@ | ||
| def self.registration_agency(ids:, options: nil, verbose: false) | ||
| Request.new('works', ids, nil, nil, nil, | ||
| nil, nil, nil, nil, nil, false, true, options, verbose).perform | ||
| nil, nil, nil, nil, nil, false, true, options, verbose).perform | ||
| end | ||
@@ -556,5 +583,4 @@ | ||
| 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, options, verbose).perform | ||
| nil, sample, nil, nil, nil, nil, false, nil, options, verbose).perform | ||
| tmp['message']['items'].collect { |x| x['DOI'] } | ||
@@ -586,3 +612,3 @@ end | ||
| # | ||
| # # return an R bibentry type | ||
| # # return a bibentry type | ||
| # Serrano.content_negotiation(ids: "10.1126/science.169.3946.635", format: "bibentry") | ||
@@ -600,26 +626,28 @@ # Serrano.content_negotiation(ids: "10.6084/m9.figshare.97218", format: "bibentry") | ||
| # # example with many DOIs | ||
| # dois = cr_r(2) | ||
| # Serrano.content_negotiation(dois, format: "text", style: "apa") | ||
| # dois = Serrano.random_dois(sample: 2) | ||
| # Serrano.content_negotiation(ids: dois, format: "text", style: "apa") | ||
| # | ||
| # # Using DataCite DOIs | ||
| # ## some formats don't work | ||
| # # Serrano.content_negotiation(ids: "10.5284/1011335", format: "text") | ||
| # # Serrano.content_negotiation(ids: "10.5284/1011335", format: "crossref-xml") | ||
| # # Serrano.content_negotiation(ids: "10.5284/1011335", format: "crossref-tdm") | ||
| # doi = "10.1126/science.169.3946.635" | ||
| # Serrano.content_negotiation(ids: doi, format: "text") | ||
| # Serrano.content_negotiation(ids: doi, format: "crossref-xml") | ||
| # Serrano.content_negotiation(ids: doi, format: "crossref-tdm") | ||
| # | ||
| # ## But most do work | ||
| # Serrano.content_negotiation(ids: "10.5284/1011335", format: "datacite-xml") | ||
| # Serrano.content_negotiation(ids: "10.5284/1011335", format: "rdf-xml") | ||
| # Serrano.content_negotiation(ids: "10.5284/1011335", format: "turtle") | ||
| # Serrano.content_negotiation(ids: "10.5284/1011335", format: "citeproc-json") | ||
| # Serrano.content_negotiation(ids: "10.5284/1011335", format: "ris") | ||
| # Serrano.content_negotiation(ids: "10.5284/1011335", format: "bibtex") | ||
| # Serrano.content_negotiation(ids: "10.5284/1011335", format: "bibentry") | ||
| # Serrano.content_negotiation(ids: "10.5284/1011335", format: "bibtex") | ||
| # Serrano.content_negotiation(ids: doi, format: "datacite-xml") | ||
| # Serrano.content_negotiation(ids: doi, format: "rdf-xml") | ||
| # Serrano.content_negotiation(ids: doi, format: "turtle") | ||
| # Serrano.content_negotiation(ids: doi, format: "citeproc-json") | ||
| # Serrano.content_negotiation(ids: doi, format: "ris") | ||
| # Serrano.content_negotiation(ids: doi, format: "bibtex") | ||
| # Serrano.content_negotiation(ids: doi, format: "bibentry") | ||
| # Serrano.content_negotiation(ids: doi, format: "bibtex") | ||
| # | ||
| # # many DOIs | ||
| # dois = ['10.5167/UZH-30455','10.5167/UZH-49216','10.5167/UZH-503', '10.5167/UZH-38402','10.5167/UZH-41217'] | ||
| # dois = ['10.5167/UZH-30455','10.5167/UZH-49216','10.5167/UZH-503', | ||
| # '10.5167/UZH-38402','10.5167/UZH-41217'] | ||
| # x = Serrano.content_negotiation(ids: dois) | ||
| # puts x | ||
| def self.content_negotiation(ids:, format: "bibtex", style: 'apa', locale: "en-US") | ||
| 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 | ||
@@ -643,8 +671,8 @@ end | ||
| # Serrano.citation_count(doi: "10.1016/j.fbr.2012") | ||
| def self.citation_count(doi:, url: "http://www.crossref.org/openurl/", | ||
| key: "cboettig@ropensci.org", options: nil) | ||
| def self.citation_count(doi:, url: 'http://www.crossref.org/openurl/', | ||
| key: 'cboettig@ropensci.org', options: nil) | ||
| args = { id: "doi:" + doi, pid: key, noredirect: true } | ||
| opts = args.delete_if { |k, v| v.nil? } | ||
| conn = Faraday.new(:url => url, :request => options) | ||
| args = { id: 'doi:' + doi, pid: key, noredirect: true } | ||
| opts = args.delete_if { |_k, v| v.nil? } | ||
| conn = Faraday.new(url: url, request: options) | ||
| res = conn.get '', opts | ||
@@ -654,3 +682,3 @@ x = res.body | ||
| value = REXML::XPath.first(oc, '//query').attributes['fl_count'].to_i | ||
| return value | ||
| value | ||
| end | ||
@@ -665,5 +693,4 @@ | ||
| def self.csl_styles | ||
| get_styles() | ||
| fetch_styles | ||
| end | ||
| end |
@@ -1,4 +0,6 @@ | ||
| require "serrano/version" | ||
| require "serrano/cnrequest" | ||
| # frozen_string_literal: true | ||
| require 'serrano/version' | ||
| require 'serrano/cnrequest' | ||
| ## | ||
@@ -9,5 +11,3 @@ # ContentNegotiation - Content Negotiation class | ||
| module Serrano | ||
| class ContentNegotiation | ||
| attr_accessor :ids | ||
@@ -18,3 +18,3 @@ attr_accessor :format | ||
| def initialize(ids, format = "bibtex", style = "apa", locale = "en-US") | ||
| def initialize(ids, format = 'bibtex', style = 'apa', locale = 'en-US') | ||
| self.ids = ids | ||
@@ -27,7 +27,5 @@ self.format = format | ||
| def cn | ||
| CNRequest.new(self.ids, self.format, self.style, self.locale).perform | ||
| CNRequest.new(ids, format, style, locale).perform | ||
| end | ||
| end | ||
| end |
+41
-27
@@ -1,9 +0,21 @@ | ||
| require "faraday" | ||
| require "faraday_middleware" | ||
| require "multi_json" | ||
| require "serrano/error" | ||
| require "serrano/constants" | ||
| # frozen_string_literal: true | ||
| require 'faraday' | ||
| require 'faraday_middleware' | ||
| require 'multi_json' | ||
| require 'serrano/error' | ||
| require 'serrano/utils' | ||
| require 'serrano/helpers/configuration' | ||
| CN_FORMAT_HEADERS = { 'rdf-xml' => 'application/rdf+xml', | ||
| 'turtle' => 'text/turtle', | ||
| 'citeproc-json' => 'transform/application/vnd.citationstyles.csl+json', | ||
| 'text' => 'text/x-bibliography', | ||
| 'ris' => 'application/x-research-info-systems', | ||
| 'bibtex' => 'application/x-bibtex', | ||
| 'crossref-xml' => 'application/vnd.crossref.unixref+xml', | ||
| 'datacite-xml' => 'application/vnd.datacite.datacite+xml', | ||
| 'bibentry' => 'application/x-bibtex', | ||
| 'crossref-tdm' => 'application/vnd.crossref.unixsd+xml' }.freeze | ||
| ## | ||
@@ -15,3 +27,2 @@ # Serrano::CNRequest | ||
| class CNRequest #:nodoc: | ||
| attr_accessor :ids | ||
@@ -22,2 +33,7 @@ attr_accessor :format | ||
| CN_FORMATS = %w[rdf-xml turtle citeproc-json | ||
| citeproc-json-ish text ris bibtex | ||
| crossref-xml datacite-xml bibentry | ||
| crossref-tdm].freeze | ||
| def initialize(ids, format, style, locale) | ||
@@ -31,7 +47,7 @@ self.ids = ids | ||
| def perform | ||
| if !$cn_formats.include? self.format | ||
| raise "format not one of accepted types" | ||
| unless CN_FORMATS.include? format | ||
| raise 'format not one of accepted types' | ||
| end | ||
| $conn = Faraday.new "https://doi.org/" do |c| | ||
| conn = Faraday.new 'https://doi.org/' do |c| | ||
| c.use FaradayMiddleware::FollowRedirects | ||
@@ -41,11 +57,9 @@ c.adapter :net_http | ||
| if self.ids.length == 1 | ||
| if self.ids.class == Array | ||
| self.ids = self.ids[0] | ||
| end | ||
| return make_request(self.ids, self.format, self.style, self.locale) | ||
| if ids.length == 1 | ||
| self.ids = ids[0] if ids.class == Array | ||
| return make_request(conn, ids, format, style, locale) | ||
| else | ||
| coll = [] | ||
| Array(self.ids).each do |x| | ||
| coll << make_request(x, self.format, self.style, self.locale) | ||
| Array(ids).each do |x| | ||
| coll << make_request(conn, x, format, style, locale) | ||
| end | ||
@@ -58,25 +72,25 @@ return coll | ||
| def make_request(ids, format, style, locale) | ||
| type = $cn_format_headers.select { |x, _| x.include? format }.values[0] | ||
| def make_request(conn, ids, format, style, locale) | ||
| type = CN_FORMAT_HEADERS.select { |x, _| x.include? format }.values[0] | ||
| if format == "citeproc-json" | ||
| endpt = "http://api.crossref.org/works/" + ids + "/" + type | ||
| cr_works = Faraday.new(:url => endpt) | ||
| if format == 'citeproc-json' | ||
| endpt = 'http://api.crossref.org/works/' + ids + '/' + type | ||
| cr_works = Faraday.new(url: endpt) | ||
| cr_works.headers[:user_agent] = make_ua | ||
| cr_works.headers["X-USER-AGENT"] = make_ua | ||
| cr_works.headers['X-USER-AGENT'] = make_ua | ||
| res = cr_works.get | ||
| else | ||
| if format == "text" | ||
| type = type + "; style = " + style + "; locale = " + locale | ||
| if format == 'text' | ||
| type = type + '; style = ' + style + '; locale = ' + locale | ||
| end | ||
| res = $conn.get do |req| | ||
| res = conn.get do |req| | ||
| req.url ids | ||
| req.headers['Accept'] = type | ||
| req.headers[:user_agent] = make_ua | ||
| req.headers["X-USER-AGENT"] = make_ua | ||
| req.headers['X-USER-AGENT'] = make_ua | ||
| end | ||
| end | ||
| return res.body | ||
| res.body | ||
| end | ||
@@ -83,0 +97,0 @@ |
@@ -0,1 +1,3 @@ | ||
| # frozen_string_literal: true | ||
| module Serrano | ||
@@ -2,0 +4,0 @@ # Custom error class for rescuing from all Serrano errors |
+15
-14
@@ -0,1 +1,3 @@ | ||
| # frozen_string_literal: true | ||
| require 'faraday' | ||
@@ -16,9 +18,9 @@ require 'multi_json' | ||
| when 500 | ||
| raise Serrano::InternalServerError, error_message_500(response, "Something is technically wrong.") | ||
| raise Serrano::InternalServerError, error_message_500(response, 'Something is technically wrong.') | ||
| when 502 | ||
| raise Serrano::BadGateway, error_message_500(response, "The server returned an invalid or incomplete response.") | ||
| raise Serrano::BadGateway, error_message_500(response, 'The server returned an invalid or incomplete response.') | ||
| when 503 | ||
| raise Serrano::ServiceUnavailable, error_message_500(response, "Crossref is rate limiting your requests.") | ||
| raise Serrano::ServiceUnavailable, error_message_500(response, 'Crossref is rate limiting your requests.') | ||
| when 504 | ||
| raise Serrano::GatewayTimeout, error_message_500(response, "504 Gateway Time-out") | ||
| raise Serrano::GatewayTimeout, error_message_500(response, '504 Gateway Time-out') | ||
| end | ||
@@ -36,12 +38,12 @@ end | ||
| def error_message_400(response) | ||
| "\n #{response[:method].to_s.upcase} #{response[:url].to_s}\n Status #{response[:status]}#{error_body(response[:body])}" | ||
| "\n #{response[:method].to_s.upcase} #{response[:url]}\n Status #{response[:status]}#{error_body(response[:body])}" | ||
| end | ||
| def error_body(body) | ||
| if not body.nil? and not body.empty? and body.kind_of?(String) | ||
| if is_json?(body) | ||
| if !body.nil? && !body.empty? && body.is_a?(String) | ||
| if json?(body) | ||
| body = ::MultiJson.load(body) | ||
| if body['message'].nil? | ||
| body = nil | ||
| elseif body['message'].length == 1 | ||
| elseif body['message'].length == 1 | ||
| body = body['message'] | ||
@@ -61,14 +63,13 @@ else | ||
| def error_message_500(response, body=nil) | ||
| "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{[response[:status].to_s + ':', body].compact.join(' ')}" | ||
| def error_message_500(response, body = nil) | ||
| "#{response[:method].to_s.upcase} #{response[:url]}: #{[response[:status].to_s + ':', body].compact.join(' ')}" | ||
| end | ||
| def is_json?(string) | ||
| def json?(string) | ||
| MultiJson.load(string) | ||
| return true | ||
| true | ||
| rescue MultiJson::ParseError | ||
| return false | ||
| false | ||
| end | ||
| end | ||
| end |
@@ -0,8 +1,8 @@ | ||
| # frozen_string_literal: true | ||
| # helper functions | ||
| module Helpers | ||
| $others = ['license_url','license_version','license_delay','full_text_version','full_text_type', | ||
| 'award_number','award_funder'] | ||
| def filter_handler(x = nil) | ||
| others = %w[license_url license_version license_delay full_text_version full_text_type | ||
| award_number award_funder] | ||
| if x.nil? | ||
@@ -12,6 +12,6 @@ nil | ||
| x = stringify(x) | ||
| nn = x.keys.collect{ |z| z.to_s } | ||
| if nn.collect{ |w| $others.include? w }.any? | ||
| nn = nn.collect{ |b| | ||
| if $others.include? b | ||
| nn = x.keys.collect(&:to_s) | ||
| if nn.collect { |w| others.include? w }.any? | ||
| nn = nn.collect do |b| | ||
| if others.include? b | ||
| case b | ||
@@ -36,9 +36,9 @@ when 'license_url' | ||
| end | ||
| } | ||
| end | ||
| end | ||
| newnn = nn.collect{ |m| m.gsub("_", "-") } | ||
| newnn = nn.collect { |m| m.tr('_', '-') } | ||
| x = rename_keys(x, newnn) | ||
| x = x.collect{ |k,v| [k, v].join(":") }.join(',') | ||
| return x | ||
| x = x.collect { |k, v| [k, v].join(':') }.join(',') | ||
| x | ||
| end | ||
@@ -48,3 +48,3 @@ end | ||
| def stringify(x) | ||
| (x.keys.map{ |k,v| k.to_s }.zip x.values).to_h | ||
| (x.keys.map { |k, _v| k.to_s }.zip x.values).to_h | ||
| end | ||
@@ -55,3 +55,2 @@ | ||
| end | ||
| end | ||
@@ -68,2 +67,1 @@ | ||
| end | ||
+72
-70
@@ -0,1 +1,3 @@ | ||
| # frozen_string_literal: true | ||
| ## | ||
@@ -17,7 +19,7 @@ # Serrano::Filters | ||
| def self.names | ||
| $filter_details.keys | ||
| filter_details.keys | ||
| end | ||
| def self.filters | ||
| $filter_details | ||
| filter_details | ||
| end | ||
@@ -27,70 +29,70 @@ end | ||
| $filter_details = { | ||
| "has_funder" => { "possible_values" => nil, "description" => "metadata which includes one or more funder entry" }, | ||
| "funder" => { "possible_values" => "{funder_id}", "description" => "metadata which include the {funder_id} in FundRef data" }, | ||
| "location" => { "possible_values" => "{country_name}", "description" => "funder records where location = {country name}. Only works on /funders route" }, | ||
| "prefix" => { "possible_values" => "{owner_prefix}", "description" => "metadata belonging to a DOI owner prefix {owner_prefix} (e.g. '10.1016' )" }, | ||
| "member" => { "possible_values" => "{member_id}", "description" => "metadata belonging to a CrossRef member" }, | ||
| "from_index_date" => { "possible_values" => '{date}', "description" => "metadata indexed since (inclusive) {date}" }, | ||
| "until_index_date" => { "possible_values" => '{date}', "description" => "metadata indexed before (inclusive) {date}" }, | ||
| "from_deposit_date" => { "possible_values" => '{date}', "description" => "metadata last (re)deposited since (inclusive) {date}" }, | ||
| "until_deposit_date" => { "possible_values" => '{date}', "description" => "metadata last (re)deposited before (inclusive) {date}" }, | ||
| "from_update_date" => { "possible_values" => '{date}', "description" => "Metadata updated since (inclusive) {date} Currently the same as 'from_deposit_date'" }, | ||
| "until_update_date" => { "possible_values" => '{date}', "description" => "Metadata updated before (inclusive) {date} Currently the same as 'until_deposit_date'" }, | ||
| "from_created_date" => { "possible_values" => '{date}', "description" => "metadata first deposited since (inclusive) {date}" }, | ||
| "until_created_date" => { "possible_values" => '{date}', "description" => "metadata first deposited before (inclusive) {date}" }, | ||
| "from_pub_date" => { "possible_values" => '{date}', "description" => "metadata where published date is since (inclusive) {date}" }, | ||
| "until_pub_date" => { "possible_values" => '{date}', "description" => "metadata where published date is before (inclusive) {date}" }, | ||
| "from_online_pub_date" => { "possible_values" => '{date}', "description" => "metadata where online published date is since (inclusive) {date}" }, | ||
| "until_online_pub_date" => { "possible_values" => '{date}', "description" => "metadata where online published date is before (inclusive) {date}" }, | ||
| "from_print_pub_date" => { "possible_values" => '{date}', "description" => "metadata where print published date is since (inclusive) {date}" }, | ||
| "until_print_pub_date" => { "possible_values" => '{date}', "description" => "metadata where print published date is before (inclusive) {date}" }, | ||
| "from_posted_date" => { "possible_values" => '{date}', "description" => "metadata where posted date is since (inclusive) {date}" }, | ||
| "until_posted_date" => { "possible_values" => '{date}', "description" => "metadata where posted date is before (inclusive) {date}" }, | ||
| "from_accepted_date" => { "possible_values" => '{date}', "description" => "metadata where accepted date is since (inclusive) {date}" }, | ||
| "until_accepted_date" => { "possible_values" => '{date}', "description" => "metadata where accepted date is before (inclusive) {date}" }, | ||
| "has_license" => { "possible_values" => nil, "description" => "metadata that includes any '<license_ref>' elements" }, | ||
| "license_url" => { "possible_values" => '{url}', "description" => "metadata where '<license_ref>' value equals {url}" }, | ||
| "license_version" => { "possible_values" => '{string}', "description" => "metadata where the '<license_ref>''s 'applies_to' attribute is '{string}'"}, | ||
| "license_delay" => { "possible_values" => "{integer}", "description" => "metadata where difference between publication date and the '<license_ref>''s 'start_date' attribute is <= '{integer}' (in days"}, | ||
| "has_full_text" => { "possible_values" => nil, "description" => "metadata that includes any full text '<resource>' elements_" }, | ||
| "full_text_version" => { "possible_values" => '{string}' , "description" => "metadata where '<resource>' element's 'content_version' attribute is '{string}'" }, | ||
| "full_text_type" => { "possible_values" => '{mime_type}' , "description" => "metadata where '<resource>' element's 'content_type' attribute is '{mime_type}' (e.g. 'application/pdf')" }, | ||
| "full_text_application" => { "possible_values" => '{string}' , "description" => "metadata where <resource> link has one of the following intended applications: text-mining, similarity-checking or unspecified" }, | ||
| "has_references" => { "possible_values" => nil , "description" => "metadata for works that have a list of references" }, | ||
| "has_archive" => { "possible_values" => nil , "description" => "metadata which include name of archive partner" }, | ||
| "archive" => { "possible_values" => '{string}', "description" => "metadata which where value of archive partner is '{string}'" }, | ||
| "has_orcid" => { "possible_values" => nil, "description" => "metadata which includes one or more ORCIDs" }, | ||
| "has_authenticated_orcid" => { "possible_values" => nil , "description" => "metadata which includes one or more ORCIDs where the depositing publisher claims to have witness the ORCID owner authenticate with ORCID"}, | ||
| "orcid" => { "possible_values" => '{orcid}', "description" => "metadata where '<orcid>' element's value = '{orcid}'" }, | ||
| "issn" => { "possible_values" => '{issn}', "description" => "metadata where record has an ISSN = '{issn}' Format is 'xxxx_xxxx'." }, | ||
| "directory" => { "possible_values" => "{directory}", "description" => "metadata records whose article or serial are mentioned in the given '{directory}'. Currently the only supported value is 'doaj'" }, | ||
| "doi" => { "possible_values" => '{doi}', "description" => "metadata describing the DOI '{doi}'" }, | ||
| "updates" => { "possible_values" => '{doi}', "description" => "metadata for records that represent editorial updates to the DOI '{doi}'" }, | ||
| "is_update" => { "possible_values" => nil, "description" => "metadata for records that represent editorial updates" }, | ||
| "has_update_policy" => { "possible_values" => nil, "description" => "metadata for records that include a link to an editorial update policy" }, | ||
| "container_title" => { "possible_values" => nil, "description" => "metadata for records with a publication title exactly with an exact match" }, | ||
| "category_name" => { "possible_values" => nil, "description" => "metadata for records with an exact matching category label" }, | ||
| "type" => { "possible_values" => '{type}', "description" => "metadata records whose type = '{type}' Type must be an ID value from the list of types returned by the '/types' resource" }, | ||
| "type_name" => { "possible_values" => nil, "description" => "metadata for records with an exacty matching type label" }, | ||
| "award_number" => { "possible_values" => "{award_number}", "description" => "metadata for records with a matching award nunber_ Optionally combine with 'award_funder'" }, | ||
| "award_funder" => { "possible_values" => '{funder doi or id}', "description" => "metadata for records with an award with matching funder. Optionally combine with 'award_number'" }, | ||
| "has_assertion" => { "possible_values" => nil, "description" => "metadata for records with any assertions" }, | ||
| "assertion_group" => { "possible_values" => nil, "description" => "metadata for records with an assertion in a particular group" }, | ||
| "assertion" => { "possible_values" => nil, "description" => "metadata for records with a particular named assertion" }, | ||
| "has_affiliation" => { "possible_values" => nil, "description" => "metadata for records that have any affiliation information" }, | ||
| "alternative_id" => { "possible_values" => nil, "description" => "metadata for records with the given alternative ID, which may be a publisher_specific ID, or any other identifier a publisher may have provided" }, | ||
| "article_number" => { "possible_values" => nil, "description" => "metadata for records with a given article number" }, | ||
| "has_abstract" => { "possible_values" => nil, "description" => "metadata for records which include an abstract" }, | ||
| "has_clinical_trial_number" => { "possible_values" => nil, "description" => "metadata for records which include a clinical trial number" }, | ||
| "content_domain" => { "possible_values" => nil, "description" => "metadata where the publisher records a particular domain name as the location Crossmark content will appear" }, | ||
| "has_content_domain" => { "possible_values" => nil, "description" => "metadata where the publisher records a domain name location for Crossmark content" }, | ||
| "has_crossmark_restriction" => { "possible_values" => nil, "description" => "metadata where the publisher restricts Crossmark usage to content domains" }, | ||
| "has_relation" => { "possible_values" => nil, "description" => "metadata for records that either assert or are the object of a relation" }, | ||
| "relation_type" => { "possible_values" => nil, "description" => "One of the relation types from the Crossref relations schema (e.g. is-referenced-by, is-parent-of, is-preprint-of)" }, | ||
| "relation_object" => { "possible_values" => nil, "description" => "Relations where the object identifier matches the identifier provided" }, | ||
| "relation_object_type" => { "possible_values" => nil, "description" => "One of the identifier types from the Crossref relations schema (e.g. doi, issn)" }, | ||
| "public_references" => { "possible_values" => nil, "description" => "metadata where publishers allow references to be distributed publically" }, | ||
| "publisher_name" => { "possible_values" => nil, "description" => "metadata for records with an exact matching publisher name" }, | ||
| "affiliation" => { "possible_values" => nil, "description" => "metadata for records with at least one contributor with the given affiliation" } | ||
| filter_details = { | ||
| 'has_funder' => { 'possible_values' => nil, 'description' => 'metadata which includes one or more funder entry' }, | ||
| 'funder' => { 'possible_values' => '{funder_id}', 'description' => 'metadata which include the {funder_id} in FundRef data' }, | ||
| 'location' => { 'possible_values' => '{country_name}', 'description' => 'funder records where location = {country name}. Only works on /funders route' }, | ||
| 'prefix' => { 'possible_values' => '{owner_prefix}', 'description' => "metadata belonging to a DOI owner prefix {owner_prefix} (e.g. '10.1016' )" }, | ||
| 'member' => { 'possible_values' => '{member_id}', 'description' => 'metadata belonging to a CrossRef member' }, | ||
| 'from_index_date' => { 'possible_values' => '{date}', 'description' => 'metadata indexed since (inclusive) {date}' }, | ||
| 'until_index_date' => { 'possible_values' => '{date}', 'description' => 'metadata indexed before (inclusive) {date}' }, | ||
| 'from_deposit_date' => { 'possible_values' => '{date}', 'description' => 'metadata last (re)deposited since (inclusive) {date}' }, | ||
| 'until_deposit_date' => { 'possible_values' => '{date}', 'description' => 'metadata last (re)deposited before (inclusive) {date}' }, | ||
| 'from_update_date' => { 'possible_values' => '{date}', 'description' => "Metadata updated since (inclusive) {date} Currently the same as 'from_deposit_date'" }, | ||
| 'until_update_date' => { 'possible_values' => '{date}', 'description' => "Metadata updated before (inclusive) {date} Currently the same as 'until_deposit_date'" }, | ||
| 'from_created_date' => { 'possible_values' => '{date}', 'description' => 'metadata first deposited since (inclusive) {date}' }, | ||
| 'until_created_date' => { 'possible_values' => '{date}', 'description' => 'metadata first deposited before (inclusive) {date}' }, | ||
| 'from_pub_date' => { 'possible_values' => '{date}', 'description' => 'metadata where published date is since (inclusive) {date}' }, | ||
| 'until_pub_date' => { 'possible_values' => '{date}', 'description' => 'metadata where published date is before (inclusive) {date}' }, | ||
| 'from_online_pub_date' => { 'possible_values' => '{date}', 'description' => 'metadata where online published date is since (inclusive) {date}' }, | ||
| 'until_online_pub_date' => { 'possible_values' => '{date}', 'description' => 'metadata where online published date is before (inclusive) {date}' }, | ||
| 'from_print_pub_date' => { 'possible_values' => '{date}', 'description' => 'metadata where print published date is since (inclusive) {date}' }, | ||
| 'until_print_pub_date' => { 'possible_values' => '{date}', 'description' => 'metadata where print published date is before (inclusive) {date}' }, | ||
| 'from_posted_date' => { 'possible_values' => '{date}', 'description' => 'metadata where posted date is since (inclusive) {date}' }, | ||
| 'until_posted_date' => { 'possible_values' => '{date}', 'description' => 'metadata where posted date is before (inclusive) {date}' }, | ||
| 'from_accepted_date' => { 'possible_values' => '{date}', 'description' => 'metadata where accepted date is since (inclusive) {date}' }, | ||
| 'until_accepted_date' => { 'possible_values' => '{date}', 'description' => 'metadata where accepted date is before (inclusive) {date}' }, | ||
| 'has_license' => { 'possible_values' => nil, 'description' => "metadata that includes any '<license_ref>' elements" }, | ||
| 'license_url' => { 'possible_values' => '{url}', 'description' => "metadata where '<license_ref>' value equals {url}" }, | ||
| 'license_version' => { 'possible_values' => '{string}', 'description' => "metadata where the '<license_ref>''s 'applies_to' attribute is '{string}'" }, | ||
| 'license_delay' => { 'possible_values' => '{integer}', 'description' => "metadata where difference between publication date and the '<license_ref>''s 'start_date' attribute is <= '{integer}' (in days" }, | ||
| 'has_full_text' => { 'possible_values' => nil, 'description' => "metadata that includes any full text '<resource>' elements_" }, | ||
| 'full_text_version' => { 'possible_values' => '{string}', 'description' => "metadata where '<resource>' element's 'content_version' attribute is '{string}'" }, | ||
| 'full_text_type' => { 'possible_values' => '{mime_type}', 'description' => "metadata where '<resource>' element's 'content_type' attribute is '{mime_type}' (e.g. 'application/pdf')" }, | ||
| 'full_text_application' => { 'possible_values' => '{string}', 'description' => 'metadata where <resource> link has one of the following intended applications: text-mining, similarity-checking or unspecified' }, | ||
| 'has_references' => { 'possible_values' => nil, 'description' => 'metadata for works that have a list of references' }, | ||
| 'has_archive' => { 'possible_values' => nil, 'description' => 'metadata which include name of archive partner' }, | ||
| 'archive' => { 'possible_values' => '{string}', 'description' => "metadata which where value of archive partner is '{string}'" }, | ||
| 'has_orcid' => { 'possible_values' => nil, 'description' => 'metadata which includes one or more ORCIDs' }, | ||
| 'has_authenticated_orcid' => { 'possible_values' => nil, 'description' => 'metadata which includes one or more ORCIDs where the depositing publisher claims to have witness the ORCID owner authenticate with ORCID' }, | ||
| 'orcid' => { 'possible_values' => '{orcid}', 'description' => "metadata where '<orcid>' element's value = '{orcid}'" }, | ||
| 'issn' => { 'possible_values' => '{issn}', 'description' => "metadata where record has an ISSN = '{issn}' Format is 'xxxx_xxxx'." }, | ||
| 'directory' => { 'possible_values' => '{directory}', 'description' => "metadata records whose article or serial are mentioned in the given '{directory}'. Currently the only supported value is 'doaj'" }, | ||
| 'doi' => { 'possible_values' => '{doi}', 'description' => "metadata describing the DOI '{doi}'" }, | ||
| 'updates' => { 'possible_values' => '{doi}', 'description' => "metadata for records that represent editorial updates to the DOI '{doi}'" }, | ||
| 'is_update' => { 'possible_values' => nil, 'description' => 'metadata for records that represent editorial updates' }, | ||
| 'has_update_policy' => { 'possible_values' => nil, 'description' => 'metadata for records that include a link to an editorial update policy' }, | ||
| 'container_title' => { 'possible_values' => nil, 'description' => 'metadata for records with a publication title exactly with an exact match' }, | ||
| 'category_name' => { 'possible_values' => nil, 'description' => 'metadata for records with an exact matching category label' }, | ||
| 'type' => { 'possible_values' => '{type}', 'description' => "metadata records whose type = '{type}' Type must be an ID value from the list of types returned by the '/types' resource" }, | ||
| 'type_name' => { 'possible_values' => nil, 'description' => 'metadata for records with an exacty matching type label' }, | ||
| 'award_number' => { 'possible_values' => '{award_number}', 'description' => "metadata for records with a matching award nunber_ Optionally combine with 'award_funder'" }, | ||
| 'award_funder' => { 'possible_values' => '{funder doi or id}', 'description' => "metadata for records with an award with matching funder. Optionally combine with 'award_number'" }, | ||
| 'has_assertion' => { 'possible_values' => nil, 'description' => 'metadata for records with any assertions' }, | ||
| 'assertion_group' => { 'possible_values' => nil, 'description' => 'metadata for records with an assertion in a particular group' }, | ||
| 'assertion' => { 'possible_values' => nil, 'description' => 'metadata for records with a particular named assertion' }, | ||
| 'has_affiliation' => { 'possible_values' => nil, 'description' => 'metadata for records that have any affiliation information' }, | ||
| 'alternative_id' => { 'possible_values' => nil, 'description' => 'metadata for records with the given alternative ID, which may be a publisher_specific ID, or any other identifier a publisher may have provided' }, | ||
| 'article_number' => { 'possible_values' => nil, 'description' => 'metadata for records with a given article number' }, | ||
| 'has_abstract' => { 'possible_values' => nil, 'description' => 'metadata for records which include an abstract' }, | ||
| 'has_clinical_trial_number' => { 'possible_values' => nil, 'description' => 'metadata for records which include a clinical trial number' }, | ||
| 'content_domain' => { 'possible_values' => nil, 'description' => 'metadata where the publisher records a particular domain name as the location Crossmark content will appear' }, | ||
| 'has_content_domain' => { 'possible_values' => nil, 'description' => 'metadata where the publisher records a domain name location for Crossmark content' }, | ||
| 'has_crossmark_restriction' => { 'possible_values' => nil, 'description' => 'metadata where the publisher restricts Crossmark usage to content domains' }, | ||
| 'has_relation' => { 'possible_values' => nil, 'description' => 'metadata for records that either assert or are the object of a relation' }, | ||
| 'relation_type' => { 'possible_values' => nil, 'description' => 'One of the relation types from the Crossref relations schema (e.g. is-referenced-by, is-parent-of, is-preprint-of)' }, | ||
| 'relation_object' => { 'possible_values' => nil, 'description' => 'Relations where the object identifier matches the identifier provided' }, | ||
| 'relation_object_type' => { 'possible_values' => nil, 'description' => 'One of the identifier types from the Crossref relations schema (e.g. doi, issn)' }, | ||
| 'public_references' => { 'possible_values' => nil, 'description' => 'metadata where publishers allow references to be distributed publically' }, | ||
| 'publisher_name' => { 'possible_values' => nil, 'description' => 'metadata for records with an exact matching publisher name' }, | ||
| 'affiliation' => { 'possible_values' => nil, 'description' => 'metadata for records with at least one contributor with the given affiliation' } | ||
| } |
@@ -0,4 +1,5 @@ | ||
| # frozen_string_literal: true | ||
| # taken from: https://viget.com/extend/easy-gem-configuration-variables-with-defaults | ||
| module Configuration | ||
| def configuration | ||
@@ -25,3 +26,2 @@ yield self | ||
| end | ||
| end |
@@ -1,6 +0,8 @@ | ||
| require "faraday" | ||
| # frozen_string_literal: true | ||
| require 'erb' | ||
| require 'faraday' | ||
| require 'faraday_middleware' | ||
| require "multi_json" | ||
| require "serrano/error" | ||
| require "serrano/constants" | ||
| require 'multi_json' | ||
| require 'serrano/error' | ||
| require 'serrano/helpers/configuration' | ||
@@ -18,3 +20,2 @@ require 'serrano/filterhandler' | ||
| class RequestCursor #:nodoc: | ||
| attr_accessor :endpt | ||
@@ -40,5 +41,5 @@ attr_accessor :id | ||
| def initialize(endpt, id, query, filter, offset, | ||
| limit, sample, sort, order, facet, select, | ||
| works, agency, options, verbose, cursor, | ||
| cursor_max, args) | ||
| limit, sample, sort, order, facet, select, | ||
| works, agency, options, verbose, cursor, | ||
| cursor_max, args) | ||
@@ -66,59 +67,60 @@ self.endpt = endpt | ||
| def perform | ||
| filt = filter_handler(self.filter) | ||
| fieldqueries = field_query_handler(self.args) | ||
| self.select = self.select.join(",") if self.select && self.select.class == Array | ||
| filt = filter_handler(filter) | ||
| fieldqueries = field_query_handler(args) | ||
| self.select = select.join(',') if select && select.class == Array | ||
| if self.cursor_max.class != nil | ||
| if !self.cursor_max.kind_of?(Integer) | ||
| raise "cursor_max must be of class int" | ||
| end | ||
| unless cursor_max.class.nil? | ||
| raise 'cursor_max must be of class int' unless cursor_max.is_a?(Integer) | ||
| end | ||
| arguments = { query: self.query, filter: filt, offset: self.offset, | ||
| rows: self.limit, sample: self.sample, sort: self.sort, | ||
| order: self.order, facet: self.facet, select: self.select, | ||
| cursor: self.cursor }.tostrings | ||
| arguments = { query: query, filter: filt, offset: offset, | ||
| rows: limit, sample: sample, sort: sort, | ||
| order: order, facet: facet, select: select, | ||
| cursor: cursor }.tostrings | ||
| arguments = arguments.merge(fieldqueries) | ||
| opts = arguments.delete_if { |k, v| v.nil? } | ||
| opts = arguments.delete_if { |_k, v| v.nil? } | ||
| if verbose | ||
| $conn = Faraday.new(:url => Serrano.base_url, :request => options || []) do |f| | ||
| f.response :logger | ||
| f.use FaradayMiddleware::RaiseHttpException | ||
| f.adapter Faraday.default_adapter | ||
| end | ||
| else | ||
| $conn = Faraday.new(:url => Serrano.base_url, :request => options || []) do |f| | ||
| f.use FaradayMiddleware::RaiseHttpException | ||
| f.adapter Faraday.default_adapter | ||
| end | ||
| end | ||
| conn = if verbose | ||
| Faraday.new(url: Serrano.base_url, request: options || []) do |f| | ||
| f.response :logger | ||
| f.use FaradayMiddleware::RaiseHttpException | ||
| f.adapter Faraday.default_adapter | ||
| end | ||
| else | ||
| Faraday.new(url: Serrano.base_url, request: options || []) do |f| | ||
| f.use FaradayMiddleware::RaiseHttpException | ||
| f.adapter Faraday.default_adapter | ||
| end | ||
| end | ||
| $conn.headers[:user_agent] = make_ua | ||
| $conn.headers["X-USER-AGENT"] = make_ua | ||
| conn.headers[:user_agent] = make_ua | ||
| conn.headers['X-USER-AGENT'] = make_ua | ||
| if self.id.nil? | ||
| $endpt2 = self.endpt | ||
| js = self._req(self.endpt, opts) | ||
| if id.nil? | ||
| endpt2 = endpt | ||
| js = _req(conn, endpt, opts) | ||
| cu = js['message']['next-cursor'] | ||
| max_avail = js['message']['total-results'] | ||
| res = self._redo_req(js, opts, cu, max_avail) | ||
| res = _redo_req(conn, js, opts, cu, max_avail) | ||
| return res | ||
| else | ||
| self.id = Array(id) | ||
| # url encoding | ||
| self.id = id.map { |x| ERB::Util.url_encode(x) } | ||
| coll = [] | ||
| Array(self.id).each do |x| | ||
| if self.works | ||
| $endpt2 = self.endpt + '/' + x.to_s + "/works" | ||
| else | ||
| if self.agency | ||
| $endpt2 = self.endpt + '/' + x.to_s + "/agency" | ||
| else | ||
| $endpt2 = self.endpt + '/' + x.to_s | ||
| end | ||
| end | ||
| id.each do |x| | ||
| endpt2 = if works | ||
| endpt + '/' + x.to_s + '/works' | ||
| else | ||
| endpt2 = if agency | ||
| endpt + '/' + x.to_s + '/agency' | ||
| else | ||
| endpt + '/' + x.to_s | ||
| end | ||
| end | ||
| js = self._req($endpt2, opts) | ||
| js = _req(conn, endpt2, opts) | ||
| cu = js['message']['next-cursor'] | ||
| max_avail = js['message']['total-results'] | ||
| coll << self._redo_req(js, opts, cu, max_avail) | ||
| coll << _redo_req(conn, js, opts, cu, max_avail) | ||
| end | ||
@@ -129,25 +131,24 @@ return coll | ||
| def _redo_req(js, opts, cu, max_avail) | ||
| if !cu.nil? and self.cursor_max > js['message']['items'].length | ||
| def _redo_req(conn, js, opts, cu, max_avail) | ||
| if !cu.nil? && (cursor_max > js['message']['items'].length) | ||
| res = [js] | ||
| total = js['message']['items'].length | ||
| while !cu.nil? and self.cursor_max > total and total < max_avail do | ||
| while !cu.nil? && (cursor_max > total) && (total < max_avail) | ||
| opts[:cursor] = cu | ||
| out = self._req($endpt2, opts) | ||
| out = _req(conn, endpt2, opts) | ||
| cu = out['message']['next-cursor'] | ||
| res << out | ||
| total = res.collect {|x| x['message']['items'].length}.reduce(0, :+) | ||
| total = res.collect { |x| x['message']['items'].length }.reduce(0, :+) | ||
| end | ||
| return res | ||
| res | ||
| else | ||
| return js | ||
| js | ||
| end | ||
| end | ||
| def _req(path, opts) | ||
| res = $conn.get path, opts | ||
| return MultiJson.load(res.body) | ||
| def _req(conn, path, opts) | ||
| res = conn.get path, opts | ||
| MultiJson.load(res.body) | ||
| end | ||
| end | ||
| end |
+41
-39
@@ -1,5 +0,7 @@ | ||
| require "faraday" | ||
| require "multi_json" | ||
| require "serrano/error" | ||
| require "serrano/constants" | ||
| # frozen_string_literal: true | ||
| require 'erb' | ||
| require 'faraday' | ||
| require 'multi_json' | ||
| require 'serrano/error' | ||
| require 'serrano/utils' | ||
@@ -14,3 +16,2 @@ require 'serrano/helpers/configuration' | ||
| class Request #:nodoc: | ||
| attr_accessor :endpt | ||
@@ -33,4 +34,4 @@ attr_accessor :id | ||
| def initialize(endpt, id, query, filter, offset, | ||
| limit, sample, sort, order, facet, select, | ||
| works, agency, options, verbose) | ||
| limit, sample, sort, order, facet, select, | ||
| works, agency, options, verbose) | ||
@@ -55,43 +56,44 @@ self.endpt = endpt | ||
| def perform | ||
| filt = filter_handler(self.filter) | ||
| filt = filter_handler(filter) | ||
| self.select = self.select.join(",") if self.select && self.select.class == Array | ||
| self.select = select.join(',') if select && select.class == Array | ||
| args = { query: self.query, filter: filt, offset: self.offset, | ||
| rows: self.limit, sample: self.sample, sort: self.sort, | ||
| order: self.order, facet: self.facet, | ||
| select: self.select } | ||
| opts = args.delete_if { |k, v| v.nil? } | ||
| args = { query: query, filter: filt, offset: offset, | ||
| rows: limit, sample: sample, sort: sort, | ||
| order: order, facet: facet, | ||
| select: select } | ||
| opts = args.delete_if { |_k, v| v.nil? } | ||
| if verbose | ||
| conn = Faraday.new(:url => Serrano.base_url, :request => options || []) do |f| | ||
| f.response :logger | ||
| f.use FaradayMiddleware::RaiseHttpException | ||
| f.adapter Faraday.default_adapter | ||
| end | ||
| else | ||
| conn = Faraday.new(:url => Serrano.base_url, :request => options || []) do |f| | ||
| f.use FaradayMiddleware::RaiseHttpException | ||
| f.adapter Faraday.default_adapter | ||
| end | ||
| end | ||
| conn = if verbose | ||
| Faraday.new(url: Serrano.base_url, request: options || []) do |f| | ||
| f.response :logger | ||
| f.use FaradayMiddleware::RaiseHttpException | ||
| f.adapter Faraday.default_adapter | ||
| end | ||
| else | ||
| Faraday.new(url: Serrano.base_url, request: options || []) do |f| | ||
| f.use FaradayMiddleware::RaiseHttpException | ||
| f.adapter Faraday.default_adapter | ||
| end | ||
| end | ||
| conn.headers[:user_agent] = make_ua | ||
| conn.headers["X-USER-AGENT"] = make_ua | ||
| conn.headers['X-USER-AGENT'] = make_ua | ||
| if self.id.nil? | ||
| res = conn.get self.endpt, opts | ||
| if id.nil? | ||
| res = conn.get endpt, opts | ||
| return MultiJson.load(res.body) | ||
| else | ||
| self.id = Array(id) | ||
| # url encoding | ||
| self.id = id.map { |x| ERB::Util.url_encode(x) } | ||
| coll = [] | ||
| Array(self.id).each do |x| | ||
| if self.works | ||
| endpt = self.endpt + '/' + x.to_s + "/works" | ||
| else | ||
| if self.agency | ||
| endpt = self.endpt + '/' + x.to_s + "/agency" | ||
| else | ||
| endpt = self.endpt + '/' + x.to_s | ||
| end | ||
| end | ||
| id.each do |x| | ||
| endpt = if works | ||
| self.endpt + '/' + x.to_s + '/works' | ||
| elsif agency | ||
| self.endpt + '/' + x.to_s + '/agency' | ||
| else | ||
| self.endpt + '/' + x.to_s | ||
| end | ||
@@ -98,0 +100,0 @@ res = conn.get endpt, opts |
@@ -1,7 +0,12 @@ | ||
| require "faraday" | ||
| require "multi_json" | ||
| # frozen_string_literal: true | ||
| def get_styles | ||
| base = "https://api.github.com/repos/citation-style-language/styles" | ||
| conn = Faraday.new(:url => base) | ||
| require 'faraday' | ||
| require 'multi_json' | ||
| def fetch_styles | ||
| base = 'https://api.github.com/repos/citation-style-language/styles' | ||
| conn = Faraday.new(url: base) do |f| | ||
| f.use FaradayMiddleware::RaiseHttpException | ||
| f.adapter Faraday.default_adapter | ||
| end | ||
| args = { per_page: 1 } | ||
@@ -11,6 +16,6 @@ tt = conn.get 'commits', args | ||
| sha = commres[0]['sha'] | ||
| sty = conn.get "git/trees/" + sha | ||
| sty = conn.get 'git/trees/' + sha | ||
| res = MultiJson.load(sty.body) | ||
| files = res['tree'].collect { |x| x['path'] } | ||
| matches = files.collect { |x| | ||
| matches = files.collect do |x| | ||
| if x.match('csl').nil? | ||
@@ -21,5 +26,5 @@ nil | ||
| end | ||
| } | ||
| end | ||
| csls = matches.compact | ||
| return csls.collect { |z| z.gsub('.csl', '') } | ||
| csls.collect { |z| z.gsub('.csl', '') } | ||
| end |
+16
-13
@@ -0,1 +1,3 @@ | ||
| # frozen_string_literal: true | ||
| def make_ua | ||
@@ -8,27 +10,28 @@ requa = 'Faraday/v' + Faraday::VERSION | ||
| end | ||
| return ua | ||
| # ua += format(' (mailto:%s)', Serrano.mailto) if Serrano.mailto | ||
| ua | ||
| end | ||
| def field_query_handler(x) | ||
| tmp = x.keep_if { |z| z.match(/query_/) } | ||
| return rename_query_filters(tmp) | ||
| tmp = x.keep_if { |z| z.match(/query_/) } | ||
| rename_query_filters(tmp) | ||
| end | ||
| def rename_query_filters(foo) | ||
| foo = foo.tostrings | ||
| foo = foo.map { |x,y| [x.to_s.sub('container_title', 'container-title'), y] }.to_h | ||
| foo = foo.map { |x,y| [x.to_s.sub('query_', 'query.'), y] }.to_h | ||
| return foo | ||
| foo = foo.tostrings | ||
| foo = foo.map { |x, y| [x.to_s.sub('container_title', 'container-title'), y] }.to_h | ||
| foo = foo.map { |x, y| [x.to_s.sub('query_', 'query.'), y] }.to_h | ||
| foo | ||
| end | ||
| class Hash | ||
| def tostrings | ||
| Hash[self.map{|(k,v)| [k.to_s,v]}] | ||
| end | ||
| def tostrings | ||
| Hash[map { |(k, v)| [k.to_s, v] }] | ||
| end | ||
| end | ||
| class Hash | ||
| def tosymbols | ||
| Hash[self.map{|(k,v)| [k.to_sym,v]}] | ||
| end | ||
| def tosymbols | ||
| Hash[map { |(k, v)| [k.to_sym, v] }] | ||
| end | ||
| end |
@@ -0,3 +1,5 @@ | ||
| # frozen_string_literal: true | ||
| module Serrano | ||
| VERSION = "0.5.0" | ||
| VERSION = '0.5.2' | ||
| end |
+1
-1
@@ -1,2 +0,2 @@ | ||
| Copyright (C) 2018 Scott Chamberlain | ||
| Copyright (C) 2019 Scott Chamberlain | ||
@@ -3,0 +3,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
+25
-18
@@ -1,7 +0,10 @@ | ||
| require "bundler/gem_tasks" | ||
| # frozen_string_literal: true | ||
| require 'bundler/gem_tasks' | ||
| require 'rake/testtask' | ||
| require 'rubocop/rake_task' | ||
| Rake::TestTask.new do |t| | ||
| t.libs << "test" | ||
| t.test_files = FileList['test/test-*.rb'] | ||
| t.libs << 'test' | ||
| t.test_files = FileList['test/test_*.rb'] | ||
| t.verbose = true | ||
@@ -11,33 +14,37 @@ t.warning = false | ||
| desc "Run tests" | ||
| task :default => :test | ||
| desc 'Run tests' | ||
| task default: :test | ||
| desc "Build serrano docs" | ||
| RuboCop::RakeTask.new(:rubocop) do |t| | ||
| t.options = ['--display-cop-names'] | ||
| end | ||
| desc 'Build serrano docs' | ||
| task :docs do | ||
| system "yardoc" | ||
| system 'yardoc' | ||
| end | ||
| desc "bundle install" | ||
| desc 'bundle install' | ||
| task :bundle do | ||
| system "bundle install" | ||
| system 'bundle install' | ||
| end | ||
| desc "clean out builds" | ||
| desc 'clean out builds' | ||
| task :clean do | ||
| system "ls | grep [0-9].gem | xargs rm" | ||
| system 'ls | grep [0-9].gem | xargs rm' | ||
| end | ||
| desc "Build serrano" | ||
| desc 'Build serrano' | ||
| task :build do | ||
| system "gem build serrano.gemspec" | ||
| system 'gem build serrano.gemspec' | ||
| end | ||
| desc "Install serrano" | ||
| task :install => [:bundle, :build] do | ||
| system "gem install serrano-#{Serrano::VERSION}.gem" | ||
| desc 'Install serrano' | ||
| task install: %i[bundle build] do | ||
| system "gem install serrano-#{Serrano::VERSION}.gem" | ||
| end | ||
| desc "Release to Rubygems" | ||
| task :release => :build do | ||
| desc 'Release to Rubygems' | ||
| task release: :build do | ||
| system "gem push serrano-#{Serrano::VERSION}.gem" | ||
| end |
+5
-0
@@ -63,2 +63,7 @@ serrano | ||
| URL Encoding: | ||
| We do URL encoding of DOIs for you for all methods except `Serrano.citation_count` which doesn't work if you encode DOIs beforehand. We use `ERB::Util.url_encode` to encode. | ||
| ## Install | ||
@@ -65,0 +70,0 @@ |
+19
-17
@@ -1,3 +0,4 @@ | ||
| # coding: utf-8 | ||
| lib = File.expand_path('../lib', __FILE__) | ||
| # frozen_string_literal: true | ||
| lib = File.expand_path('lib', __dir__) | ||
| $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
@@ -11,6 +12,6 @@ require 'serrano/version' | ||
| s.required_ruby_version = '>= 2.1' | ||
| s.date = '2018-04-08' | ||
| s.summary = "Crossref Client" | ||
| s.description = "Low Level Ruby Client for the Crossref Search API" | ||
| s.authors = "Scott Chamberlain" | ||
| s.date = '2019-08-07' | ||
| s.summary = 'Crossref Client' | ||
| s.description = 'Low Level Ruby Client for the Crossref Search API' | ||
| s.authors = 'Scott Chamberlain' | ||
| s.email = 'myrmecocystus@gmail.com' | ||
@@ -20,4 +21,4 @@ s.homepage = 'https://github.com/sckott/serrano' | ||
| s.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) } | ||
| s.require_paths = ["lib"] | ||
| s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } | ||
| s.require_paths = ['lib'] | ||
@@ -27,15 +28,16 @@ s.bindir = 'bin' | ||
| s.add_development_dependency 'bundler', '~> 1.16', '>= 1.16.1' | ||
| s.add_development_dependency 'bundler', '~> 2.0', '>= 2.0.2' | ||
| s.add_development_dependency 'codecov', '~> 0.1.10' | ||
| s.add_development_dependency 'json', '~> 2.1' | ||
| s.add_development_dependency 'rake', '~> 12.3', '>= 12.3.1' | ||
| s.add_development_dependency 'rubocop', '~> 0.74.0' | ||
| s.add_development_dependency 'simplecov', '~> 0.17.0' | ||
| s.add_development_dependency 'test-unit', '~> 3.2', '>= 3.2.7' | ||
| s.add_development_dependency 'simplecov', '~> 0.16.1' | ||
| s.add_development_dependency 'codecov', '~> 0.1.10' | ||
| s.add_development_dependency 'json', '~> 2.1' | ||
| s.add_development_dependency 'vcr', '~> 4.0' | ||
| s.add_development_dependency 'webmock', '~> 3.3' | ||
| s.add_development_dependency 'vcr', '~> 5.0' | ||
| s.add_development_dependency 'webmock', '~> 3.4', '>= 3.4.1' | ||
| s.add_runtime_dependency 'faraday', '~> 0.14.0' | ||
| s.add_runtime_dependency 'faraday_middleware', '~> 0.12.2' | ||
| s.add_runtime_dependency 'faraday', '~> 0.15.0' | ||
| s.add_runtime_dependency 'faraday_middleware', '>= 0.12.2', '< 0.14.0' | ||
| s.add_runtime_dependency 'multi_json', '~> 1.13', '>= 1.13.1' | ||
| s.add_runtime_dependency 'thor', '~> 0.20.0' | ||
| s.add_runtime_dependency 'multi_json', '~> 1.13', '>= 1.13.1' | ||
| end |
| require 'net/http' | ||
| NETWORKABLE_EXCEPTIONS = [Faraday::Error::ClientError, | ||
| URI::InvalidURIError, | ||
| Encoding::UndefinedConversionError, | ||
| ArgumentError, | ||
| NoMethodError, | ||
| TypeError] | ||
| $cn_formats = ["rdf-xml", "turtle", "citeproc-json", | ||
| "citeproc-json-ish", "text", "ris", "bibtex", | ||
| "crossref-xml", "datacite-xml", "bibentry", | ||
| "crossref-tdm"] | ||
| $cn_format_headers = {"rdf-xml" => "application/rdf+xml", | ||
| "turtle" => "text/turtle", | ||
| "citeproc-json" => "transform/application/vnd.citationstyles.csl+json", | ||
| "text" => "text/x-bibliography", | ||
| "ris" => "application/x-research-info-systems", | ||
| "bibtex" => "application/x-bibtex", | ||
| "crossref-xml" => "application/vnd.crossref.unixref+xml", | ||
| "datacite-xml" => "application/vnd.datacite.datacite+xml", | ||
| "bibentry" => "application/x-bibtex", | ||
| "crossref-tdm" => "application/vnd.crossref.unixsd+xml"} | ||
| $cn_types = {"rdf-xml" => "text/xml", | ||
| "turtle" => "text/plain", | ||
| "citeproc-json" => "application/json", | ||
| "citeproc-json-ish" => "application/json", | ||
| "text" => "text/plain", | ||
| "ris" => "text/plain", | ||
| "bibtex" => "text/plain", | ||
| "crossref-xml" => "text/xml", | ||
| "datacite-xml" => "text/xml", | ||
| "bibentry" => "text/plain", | ||
| "crossref-tdm" => "text/xml"} |
| require 'faraday' | ||
| require "multi_json" | ||
| query = "widget" | ||
| cursor = "*" | ||
| limit = 100 | ||
| cursor_max = 500 | ||
| rows = limit | ||
| filter = nil | ||
| offset = nil | ||
| sample = nil | ||
| sort = nil | ||
| order = nil | ||
| facet = nil | ||
| args = { query: query, filter: filter, offset: offset, | ||
| rows: limit, sample: sample, sort: sort, | ||
| order: order, facet: facet, cursor: cursor } | ||
| opts = args.delete_if { |k, v| v.nil? } | ||
| conn = Faraday.new(:url => "http://api.crossref.org/", :request => nil) | ||
| def _req(conn, path, opts) | ||
| res = conn.get path, opts | ||
| return MultiJson.load(res.body) | ||
| end | ||
| def _redo_req(conn, path, js, opts, cu, max_avail, cursor_max) | ||
| if !cu.nil? and cursor_max > js['message']['items'].length | ||
| res = [js] | ||
| total = js['message']['items'].length | ||
| while (!cu.nil? and cursor_max > total and total < max_avail) | ||
| opts[:cursor] = cu | ||
| out = _req(conn, path, opts) | ||
| cu = out['message']['next-cursor'] | ||
| res << out | ||
| total = res.collect { |x| x['message']['items'].length }.inject(:+) | ||
| end | ||
| return res | ||
| else | ||
| return js | ||
| end | ||
| end | ||
| path = 'works' | ||
| js = _req(conn, path, opts) | ||
| cu = js['message']['next-cursor'] | ||
| max_avail = js['message']['total-results'] | ||
| res = _redo_req(conn, path, js, opts, cu, max_avail, cursor_max) | ||
Sorry, the diff of this file is not supported yet