serrano 0.5.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +30 -0
- data/.gitignore +3 -1
- data/CHANGELOG.md +26 -0
- data/CODE_OF_CONDUCT.md +2 -2
- data/Gemfile +3 -1
- data/LICENSE +1 -1
- data/README.md +21 -7
- data/Rakefile +12 -8
- data/bin/serrano +96 -98
- data/lib/serrano.rb +112 -63
- data/lib/serrano/cn.rb +4 -6
- data/lib/serrano/cnrequest.rb +36 -22
- data/lib/serrano/error.rb +2 -0
- data/lib/serrano/faraday.rb +16 -15
- data/lib/serrano/filterhandler.rb +26 -28
- data/lib/serrano/filters.rb +91 -85
- data/lib/serrano/helpers/configuration.rb +2 -2
- data/lib/serrano/request.rb +31 -29
- data/lib/serrano/request_cursor.rb +59 -58
- data/lib/serrano/styles.rb +14 -9
- data/lib/serrano/utils.rb +19 -17
- data/lib/serrano/version.rb +3 -1
- data/serrano.gemspec +41 -28
- metadata +75 -48
- data/.travis.yml +0 -8
- data/Gemfile.lock +0 -64
- data/lib/serrano/constants.rb +0 -36
- data/lib/serrano/cursor_testing.rb +0 -52
data/lib/serrano/error.rb
CHANGED
data/lib/serrano/faraday.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "faraday"
|
4
|
+
require "multi_json"
|
3
5
|
|
4
6
|
# @private
|
5
7
|
module FaradayMiddleware
|
@@ -32,19 +34,19 @@ module FaradayMiddleware
|
|
32
34
|
private
|
33
35
|
|
34
36
|
def error_message_400(response)
|
35
|
-
"\n #{response[:method].to_s.upcase} #{response[:url]
|
37
|
+
"\n #{response[:method].to_s.upcase} #{response[:url]}\n Status #{response[:status]}#{error_body(response[:body])}"
|
36
38
|
end
|
37
39
|
|
38
40
|
def error_body(body)
|
39
|
-
if
|
40
|
-
if
|
41
|
+
if !body.nil? && !body.empty? && body.is_a?(String)
|
42
|
+
if json?(body)
|
41
43
|
body = ::MultiJson.load(body)
|
42
|
-
if body[
|
44
|
+
if body["message"].nil?
|
43
45
|
body = nil
|
44
|
-
|
45
|
-
body = body[
|
46
|
+
elseif body["message"].length == 1
|
47
|
+
body = body["message"]
|
46
48
|
else
|
47
|
-
body = body[
|
49
|
+
body = body["message"].collect { |x| x["message"] }.join("; ")
|
48
50
|
end
|
49
51
|
end
|
50
52
|
end
|
@@ -56,16 +58,15 @@ module FaradayMiddleware
|
|
56
58
|
end
|
57
59
|
end
|
58
60
|
|
59
|
-
def error_message_500(response, body=nil)
|
60
|
-
"#{response[:method].to_s.upcase} #{response[:url]
|
61
|
+
def error_message_500(response, body = nil)
|
62
|
+
"#{response[:method].to_s.upcase} #{response[:url]}: #{[response[:status].to_s + ":", body].compact.join(" ")}"
|
61
63
|
end
|
62
64
|
|
63
|
-
def
|
65
|
+
def json?(string)
|
64
66
|
MultiJson.load(string)
|
65
|
-
|
67
|
+
true
|
66
68
|
rescue MultiJson::ParseError
|
67
|
-
|
69
|
+
false
|
68
70
|
end
|
69
|
-
|
70
71
|
end
|
71
72
|
end
|
@@ -1,33 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# helper functions
|
2
4
|
module Helpers
|
3
|
-
|
4
|
-
$others = ['license_url','license_version','license_delay','full_text_version','full_text_type',
|
5
|
-
'award_number','award_funder']
|
6
|
-
|
7
5
|
def filter_handler(x = nil)
|
6
|
+
others = %w[license_url license_version license_delay full_text_version full_text_type
|
7
|
+
award_number award_funder]
|
8
8
|
if x.nil?
|
9
9
|
nil
|
10
10
|
else
|
11
11
|
x = stringify(x)
|
12
|
-
nn = x.keys.collect
|
13
|
-
if nn.collect{ |w|
|
14
|
-
nn = nn.collect{ |b|
|
15
|
-
if
|
12
|
+
nn = x.keys.collect(&:to_s)
|
13
|
+
if nn.collect { |w| others.include? w }.any?
|
14
|
+
nn = nn.collect { |b|
|
15
|
+
if others.include? b
|
16
16
|
case b
|
17
|
-
when
|
18
|
-
|
19
|
-
when
|
20
|
-
|
21
|
-
when
|
22
|
-
|
23
|
-
when
|
24
|
-
|
25
|
-
when
|
26
|
-
|
27
|
-
when
|
28
|
-
|
29
|
-
when
|
30
|
-
|
17
|
+
when "license_url"
|
18
|
+
"license.url"
|
19
|
+
when "license_version"
|
20
|
+
"license.version"
|
21
|
+
when "license_delay"
|
22
|
+
"license.delay"
|
23
|
+
when "full_text_version"
|
24
|
+
"full-text.version"
|
25
|
+
when "full_text_type"
|
26
|
+
"full-text.type"
|
27
|
+
when "award_number"
|
28
|
+
"award.number"
|
29
|
+
when "award_funder"
|
30
|
+
"award.funder"
|
31
31
|
end
|
32
32
|
else
|
33
33
|
b
|
@@ -35,21 +35,20 @@ module Helpers
|
|
35
35
|
}
|
36
36
|
end
|
37
37
|
|
38
|
-
newnn = nn.collect{ |m| m.
|
38
|
+
newnn = nn.collect { |m| m.tr("_", "-") }
|
39
39
|
x = rename_keys(x, newnn)
|
40
|
-
x
|
41
|
-
|
40
|
+
x.collect { |k, v| [k, v].join(":") }.join(",")
|
41
|
+
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
def stringify(x)
|
46
|
-
(x.keys.map{ |k,
|
46
|
+
(x.keys.map { |k, _v| k.to_s }.zip x.values).to_h
|
47
47
|
end
|
48
48
|
|
49
49
|
def rename_keys(x, y)
|
50
50
|
(y.zip x.values).to_h
|
51
51
|
end
|
52
|
-
|
53
52
|
end
|
54
53
|
|
55
54
|
module Serrano
|
@@ -61,4 +60,3 @@ module Serrano
|
|
61
60
|
include Helpers
|
62
61
|
end
|
63
62
|
end
|
64
|
-
|
data/lib/serrano/filters.rb
CHANGED
@@ -1,94 +1,100 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#
|
4
|
-
# Information on Crossref API filters
|
5
|
-
#
|
6
|
-
# @example
|
7
|
-
# require 'serrano'
|
8
|
-
# # List filter names
|
9
|
-
# Serrano::Filters.names
|
10
|
-
# # List filter values and description
|
11
|
-
# Serrano::Filters.filters
|
12
|
-
# Serrano::Filters.filters['has_funder']
|
13
|
-
# Serrano::Filters.filters['has_funder']['description']
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
14
3
|
module Serrano
|
4
|
+
def self.filters
|
5
|
+
Filters
|
6
|
+
end
|
7
|
+
|
8
|
+
##
|
9
|
+
# Serrano::Filters
|
10
|
+
#
|
11
|
+
# Information on Crossref API filters
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# require 'serrano'
|
15
|
+
# # List filter names
|
16
|
+
# Serrano::Filters.names
|
17
|
+
# # List filter values and description
|
18
|
+
# Serrano::Filters.filters
|
19
|
+
# Serrano::Filters.filters['has_funder']
|
20
|
+
# Serrano::Filters.filters['has_funder']['description']
|
15
21
|
module Filters
|
16
22
|
def self.names
|
17
|
-
|
23
|
+
FILTER_DETAILS.keys
|
18
24
|
end
|
19
25
|
|
20
26
|
def self.filters
|
21
|
-
|
27
|
+
FILTER_DETAILS
|
22
28
|
end
|
29
|
+
|
30
|
+
FILTER_DETAILS = {
|
31
|
+
"has_funder" => {"possible_values" => nil, "description" => "metadata which includes one or more funder entry"},
|
32
|
+
"funder" => {"possible_values" => "{funder_id}", "description" => "metadata which include the {funder_id} in FundRef data"},
|
33
|
+
"location" => {"possible_values" => "{country_name}", "description" => "funder records where location = {country name}. Only works on /funders route"},
|
34
|
+
"prefix" => {"possible_values" => "{owner_prefix}", "description" => "metadata belonging to a DOI owner prefix {owner_prefix} (e.g. '10.1016' )"},
|
35
|
+
"member" => {"possible_values" => "{member_id}", "description" => "metadata belonging to a CrossRef member"},
|
36
|
+
"from_index_date" => {"possible_values" => "{date}", "description" => "metadata indexed since (inclusive) {date}"},
|
37
|
+
"until_index_date" => {"possible_values" => "{date}", "description" => "metadata indexed before (inclusive) {date}"},
|
38
|
+
"from_deposit_date" => {"possible_values" => "{date}", "description" => "metadata last (re)deposited since (inclusive) {date}"},
|
39
|
+
"until_deposit_date" => {"possible_values" => "{date}", "description" => "metadata last (re)deposited before (inclusive) {date}"},
|
40
|
+
"from_update_date" => {"possible_values" => "{date}", "description" => "Metadata updated since (inclusive) {date} Currently the same as 'from_deposit_date'"},
|
41
|
+
"until_update_date" => {"possible_values" => "{date}", "description" => "Metadata updated before (inclusive) {date} Currently the same as 'until_deposit_date'"},
|
42
|
+
"from_created_date" => {"possible_values" => "{date}", "description" => "metadata first deposited since (inclusive) {date}"},
|
43
|
+
"until_created_date" => {"possible_values" => "{date}", "description" => "metadata first deposited before (inclusive) {date}"},
|
44
|
+
"from_pub_date" => {"possible_values" => "{date}", "description" => "metadata where published date is since (inclusive) {date}"},
|
45
|
+
"until_pub_date" => {"possible_values" => "{date}", "description" => "metadata where published date is before (inclusive) {date}"},
|
46
|
+
"from_online_pub_date" => {"possible_values" => "{date}", "description" => "metadata where online published date is since (inclusive) {date}"},
|
47
|
+
"until_online_pub_date" => {"possible_values" => "{date}", "description" => "metadata where online published date is before (inclusive) {date}"},
|
48
|
+
"from_print_pub_date" => {"possible_values" => "{date}", "description" => "metadata where print published date is since (inclusive) {date}"},
|
49
|
+
"until_print_pub_date" => {"possible_values" => "{date}", "description" => "metadata where print published date is before (inclusive) {date}"},
|
50
|
+
"from_posted_date" => {"possible_values" => "{date}", "description" => "metadata where posted date is since (inclusive) {date}"},
|
51
|
+
"until_posted_date" => {"possible_values" => "{date}", "description" => "metadata where posted date is before (inclusive) {date}"},
|
52
|
+
"from_accepted_date" => {"possible_values" => "{date}", "description" => "metadata where accepted date is since (inclusive) {date}"},
|
53
|
+
"until_accepted_date" => {"possible_values" => "{date}", "description" => "metadata where accepted date is before (inclusive) {date}"},
|
54
|
+
"has_license" => {"possible_values" => nil, "description" => "metadata that includes any '<license_ref>' elements"},
|
55
|
+
"license_url" => {"possible_values" => "{url}", "description" => "metadata where '<license_ref>' value equals {url}"},
|
56
|
+
"license_version" => {"possible_values" => "{string}", "description" => "metadata where the '<license_ref>''s 'applies_to' attribute is '{string}'"},
|
57
|
+
"license_delay" => {"possible_values" => "{integer}", "description" => "metadata where difference between publication date and the '<license_ref>''s 'start_date' attribute is <= '{integer}' (in days"},
|
58
|
+
"has_full_text" => {"possible_values" => nil, "description" => "metadata that includes any full text '<resource>' elements_"},
|
59
|
+
"full_text_version" => {"possible_values" => "{string}", "description" => "metadata where '<resource>' element's 'content_version' attribute is '{string}'"},
|
60
|
+
"full_text_type" => {"possible_values" => "{mime_type}", "description" => "metadata where '<resource>' element's 'content_type' attribute is '{mime_type}' (e.g. 'application/pdf')"},
|
61
|
+
"full_text_application" => {"possible_values" => "{string}", "description" => "metadata where <resource> link has one of the following intended applications: text-mining, similarity-checking or unspecified"},
|
62
|
+
"has_references" => {"possible_values" => nil, "description" => "metadata for works that have a list of references"},
|
63
|
+
"has_archive" => {"possible_values" => nil, "description" => "metadata which include name of archive partner"},
|
64
|
+
"archive" => {"possible_values" => "{string}", "description" => "metadata which where value of archive partner is '{string}'"},
|
65
|
+
"has_orcid" => {"possible_values" => nil, "description" => "metadata which includes one or more ORCIDs"},
|
66
|
+
"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"},
|
67
|
+
"orcid" => {"possible_values" => "{orcid}", "description" => "metadata where '<orcid>' element's value = '{orcid}'"},
|
68
|
+
"issn" => {"possible_values" => "{issn}", "description" => "metadata where record has an ISSN = '{issn}' Format is 'xxxx_xxxx'."},
|
69
|
+
"directory" => {"possible_values" => "{directory}", "description" => "metadata records whose article or serial are mentioned in the given '{directory}'. Currently the only supported value is 'doaj'"},
|
70
|
+
"doi" => {"possible_values" => "{doi}", "description" => "metadata describing the DOI '{doi}'"},
|
71
|
+
"updates" => {"possible_values" => "{doi}", "description" => "metadata for records that represent editorial updates to the DOI '{doi}'"},
|
72
|
+
"is_update" => {"possible_values" => nil, "description" => "metadata for records that represent editorial updates"},
|
73
|
+
"has_update_policy" => {"possible_values" => nil, "description" => "metadata for records that include a link to an editorial update policy"},
|
74
|
+
"container_title" => {"possible_values" => nil, "description" => "metadata for records with a publication title exactly with an exact match"},
|
75
|
+
"category_name" => {"possible_values" => nil, "description" => "metadata for records with an exact matching category label"},
|
76
|
+
"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"},
|
77
|
+
"type_name" => {"possible_values" => nil, "description" => "metadata for records with an exacty matching type label"},
|
78
|
+
"award_number" => {"possible_values" => "{award_number}", "description" => "metadata for records with a matching award nunber_ Optionally combine with 'award_funder'"},
|
79
|
+
"award_funder" => {"possible_values" => "{funder doi or id}", "description" => "metadata for records with an award with matching funder. Optionally combine with 'award_number'"},
|
80
|
+
"has_assertion" => {"possible_values" => nil, "description" => "metadata for records with any assertions"},
|
81
|
+
"assertion_group" => {"possible_values" => nil, "description" => "metadata for records with an assertion in a particular group"},
|
82
|
+
"assertion" => {"possible_values" => nil, "description" => "metadata for records with a particular named assertion"},
|
83
|
+
"has_affiliation" => {"possible_values" => nil, "description" => "metadata for records that have any affiliation information"},
|
84
|
+
"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"},
|
85
|
+
"article_number" => {"possible_values" => nil, "description" => "metadata for records with a given article number"},
|
86
|
+
"has_abstract" => {"possible_values" => nil, "description" => "metadata for records which include an abstract"},
|
87
|
+
"has_clinical_trial_number" => {"possible_values" => nil, "description" => "metadata for records which include a clinical trial number"},
|
88
|
+
"content_domain" => {"possible_values" => nil, "description" => "metadata where the publisher records a particular domain name as the location Crossmark content will appear"},
|
89
|
+
"has_content_domain" => {"possible_values" => nil, "description" => "metadata where the publisher records a domain name location for Crossmark content"},
|
90
|
+
"has_crossmark_restriction" => {"possible_values" => nil, "description" => "metadata where the publisher restricts Crossmark usage to content domains"},
|
91
|
+
"has_relation" => {"possible_values" => nil, "description" => "metadata for records that either assert or are the object of a relation"},
|
92
|
+
"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)"},
|
93
|
+
"relation_object" => {"possible_values" => nil, "description" => "Relations where the object identifier matches the identifier provided"},
|
94
|
+
"relation_object_type" => {"possible_values" => nil, "description" => "One of the identifier types from the Crossref relations schema (e.g. doi, issn)"},
|
95
|
+
"public_references" => {"possible_values" => nil, "description" => "metadata where publishers allow references to be distributed publically"},
|
96
|
+
"publisher_name" => {"possible_values" => nil, "description" => "metadata for records with an exact matching publisher name"},
|
97
|
+
"affiliation" => {"possible_values" => nil, "description" => "metadata for records with at least one contributor with the given affiliation"}
|
98
|
+
}.freeze
|
23
99
|
end
|
24
100
|
end
|
25
|
-
|
26
|
-
$filter_details = {
|
27
|
-
"has_funder" => { "possible_values" => nil, "description" => "metadata which includes one or more funder entry" },
|
28
|
-
"funder" => { "possible_values" => "{funder_id}", "description" => "metadata which include the {funder_id} in FundRef data" },
|
29
|
-
"location" => { "possible_values" => "{country_name}", "description" => "funder records where location = {country name}. Only works on /funders route" },
|
30
|
-
"prefix" => { "possible_values" => "{owner_prefix}", "description" => "metadata belonging to a DOI owner prefix {owner_prefix} (e.g. '10.1016' )" },
|
31
|
-
"member" => { "possible_values" => "{member_id}", "description" => "metadata belonging to a CrossRef member" },
|
32
|
-
"from_index_date" => { "possible_values" => '{date}', "description" => "metadata indexed since (inclusive) {date}" },
|
33
|
-
"until_index_date" => { "possible_values" => '{date}', "description" => "metadata indexed before (inclusive) {date}" },
|
34
|
-
"from_deposit_date" => { "possible_values" => '{date}', "description" => "metadata last (re)deposited since (inclusive) {date}" },
|
35
|
-
"until_deposit_date" => { "possible_values" => '{date}', "description" => "metadata last (re)deposited before (inclusive) {date}" },
|
36
|
-
"from_update_date" => { "possible_values" => '{date}', "description" => "Metadata updated since (inclusive) {date} Currently the same as 'from_deposit_date'" },
|
37
|
-
"until_update_date" => { "possible_values" => '{date}', "description" => "Metadata updated before (inclusive) {date} Currently the same as 'until_deposit_date'" },
|
38
|
-
"from_created_date" => { "possible_values" => '{date}', "description" => "metadata first deposited since (inclusive) {date}" },
|
39
|
-
"until_created_date" => { "possible_values" => '{date}', "description" => "metadata first deposited before (inclusive) {date}" },
|
40
|
-
"from_pub_date" => { "possible_values" => '{date}', "description" => "metadata where published date is since (inclusive) {date}" },
|
41
|
-
"until_pub_date" => { "possible_values" => '{date}', "description" => "metadata where published date is before (inclusive) {date}" },
|
42
|
-
"from_online_pub_date" => { "possible_values" => '{date}', "description" => "metadata where online published date is since (inclusive) {date}" },
|
43
|
-
"until_online_pub_date" => { "possible_values" => '{date}', "description" => "metadata where online published date is before (inclusive) {date}" },
|
44
|
-
"from_print_pub_date" => { "possible_values" => '{date}', "description" => "metadata where print published date is since (inclusive) {date}" },
|
45
|
-
"until_print_pub_date" => { "possible_values" => '{date}', "description" => "metadata where print published date is before (inclusive) {date}" },
|
46
|
-
"from_posted_date" => { "possible_values" => '{date}', "description" => "metadata where posted date is since (inclusive) {date}" },
|
47
|
-
"until_posted_date" => { "possible_values" => '{date}', "description" => "metadata where posted date is before (inclusive) {date}" },
|
48
|
-
"from_accepted_date" => { "possible_values" => '{date}', "description" => "metadata where accepted date is since (inclusive) {date}" },
|
49
|
-
"until_accepted_date" => { "possible_values" => '{date}', "description" => "metadata where accepted date is before (inclusive) {date}" },
|
50
|
-
"has_license" => { "possible_values" => nil, "description" => "metadata that includes any '<license_ref>' elements" },
|
51
|
-
"license_url" => { "possible_values" => '{url}', "description" => "metadata where '<license_ref>' value equals {url}" },
|
52
|
-
"license_version" => { "possible_values" => '{string}', "description" => "metadata where the '<license_ref>''s 'applies_to' attribute is '{string}'"},
|
53
|
-
"license_delay" => { "possible_values" => "{integer}", "description" => "metadata where difference between publication date and the '<license_ref>''s 'start_date' attribute is <= '{integer}' (in days"},
|
54
|
-
"has_full_text" => { "possible_values" => nil, "description" => "metadata that includes any full text '<resource>' elements_" },
|
55
|
-
"full_text_version" => { "possible_values" => '{string}' , "description" => "metadata where '<resource>' element's 'content_version' attribute is '{string}'" },
|
56
|
-
"full_text_type" => { "possible_values" => '{mime_type}' , "description" => "metadata where '<resource>' element's 'content_type' attribute is '{mime_type}' (e.g. 'application/pdf')" },
|
57
|
-
"full_text_application" => { "possible_values" => '{string}' , "description" => "metadata where <resource> link has one of the following intended applications: text-mining, similarity-checking or unspecified" },
|
58
|
-
"has_references" => { "possible_values" => nil , "description" => "metadata for works that have a list of references" },
|
59
|
-
"has_archive" => { "possible_values" => nil , "description" => "metadata which include name of archive partner" },
|
60
|
-
"archive" => { "possible_values" => '{string}', "description" => "metadata which where value of archive partner is '{string}'" },
|
61
|
-
"has_orcid" => { "possible_values" => nil, "description" => "metadata which includes one or more ORCIDs" },
|
62
|
-
"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"},
|
63
|
-
"orcid" => { "possible_values" => '{orcid}', "description" => "metadata where '<orcid>' element's value = '{orcid}'" },
|
64
|
-
"issn" => { "possible_values" => '{issn}', "description" => "metadata where record has an ISSN = '{issn}' Format is 'xxxx_xxxx'." },
|
65
|
-
"directory" => { "possible_values" => "{directory}", "description" => "metadata records whose article or serial are mentioned in the given '{directory}'. Currently the only supported value is 'doaj'" },
|
66
|
-
"doi" => { "possible_values" => '{doi}', "description" => "metadata describing the DOI '{doi}'" },
|
67
|
-
"updates" => { "possible_values" => '{doi}', "description" => "metadata for records that represent editorial updates to the DOI '{doi}'" },
|
68
|
-
"is_update" => { "possible_values" => nil, "description" => "metadata for records that represent editorial updates" },
|
69
|
-
"has_update_policy" => { "possible_values" => nil, "description" => "metadata for records that include a link to an editorial update policy" },
|
70
|
-
"container_title" => { "possible_values" => nil, "description" => "metadata for records with a publication title exactly with an exact match" },
|
71
|
-
"category_name" => { "possible_values" => nil, "description" => "metadata for records with an exact matching category label" },
|
72
|
-
"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" },
|
73
|
-
"type_name" => { "possible_values" => nil, "description" => "metadata for records with an exacty matching type label" },
|
74
|
-
"award_number" => { "possible_values" => "{award_number}", "description" => "metadata for records with a matching award nunber_ Optionally combine with 'award_funder'" },
|
75
|
-
"award_funder" => { "possible_values" => '{funder doi or id}', "description" => "metadata for records with an award with matching funder. Optionally combine with 'award_number'" },
|
76
|
-
"has_assertion" => { "possible_values" => nil, "description" => "metadata for records with any assertions" },
|
77
|
-
"assertion_group" => { "possible_values" => nil, "description" => "metadata for records with an assertion in a particular group" },
|
78
|
-
"assertion" => { "possible_values" => nil, "description" => "metadata for records with a particular named assertion" },
|
79
|
-
"has_affiliation" => { "possible_values" => nil, "description" => "metadata for records that have any affiliation information" },
|
80
|
-
"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" },
|
81
|
-
"article_number" => { "possible_values" => nil, "description" => "metadata for records with a given article number" },
|
82
|
-
"has_abstract" => { "possible_values" => nil, "description" => "metadata for records which include an abstract" },
|
83
|
-
"has_clinical_trial_number" => { "possible_values" => nil, "description" => "metadata for records which include a clinical trial number" },
|
84
|
-
"content_domain" => { "possible_values" => nil, "description" => "metadata where the publisher records a particular domain name as the location Crossmark content will appear" },
|
85
|
-
"has_content_domain" => { "possible_values" => nil, "description" => "metadata where the publisher records a domain name location for Crossmark content" },
|
86
|
-
"has_crossmark_restriction" => { "possible_values" => nil, "description" => "metadata where the publisher restricts Crossmark usage to content domains" },
|
87
|
-
"has_relation" => { "possible_values" => nil, "description" => "metadata for records that either assert or are the object of a relation" },
|
88
|
-
"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)" },
|
89
|
-
"relation_object" => { "possible_values" => nil, "description" => "Relations where the object identifier matches the identifier provided" },
|
90
|
-
"relation_object_type" => { "possible_values" => nil, "description" => "One of the identifier types from the Crossref relations schema (e.g. doi, issn)" },
|
91
|
-
"public_references" => { "possible_values" => nil, "description" => "metadata where publishers allow references to be distributed publically" },
|
92
|
-
"publisher_name" => { "possible_values" => nil, "description" => "metadata for records with an exact matching publisher name" },
|
93
|
-
"affiliation" => { "possible_values" => nil, "description" => "metadata for records with at least one contributor with the given affiliation" }
|
94
|
-
}
|
@@ -1,6 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# taken from: https://viget.com/extend/easy-gem-configuration-variables-with-defaults
|
2
4
|
module Configuration
|
3
|
-
|
4
5
|
def configuration
|
5
6
|
yield self
|
6
7
|
end
|
@@ -22,5 +23,4 @@ module Configuration
|
|
22
23
|
define_method name, &block
|
23
24
|
end
|
24
25
|
end
|
25
|
-
|
26
26
|
end
|
data/lib/serrano/request.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "erb"
|
1
4
|
require "faraday"
|
2
5
|
require "multi_json"
|
3
6
|
require "serrano/error"
|
4
|
-
require "serrano/
|
5
|
-
require
|
6
|
-
require 'serrano/helpers/configuration'
|
7
|
+
require "serrano/utils"
|
8
|
+
require "serrano/helpers/configuration"
|
7
9
|
|
8
10
|
##
|
9
11
|
# Serrano::Request
|
@@ -11,7 +13,6 @@ require 'serrano/helpers/configuration'
|
|
11
13
|
# Class to perform HTTP requests to the Crossref API
|
12
14
|
module Serrano
|
13
15
|
class Request #:nodoc:
|
14
|
-
|
15
16
|
attr_accessor :endpt
|
16
17
|
attr_accessor :id
|
17
18
|
attr_accessor :query
|
@@ -29,7 +30,7 @@ module Serrano
|
|
29
30
|
attr_accessor :verbose
|
30
31
|
|
31
32
|
def initialize(endpt, id, query, filter, offset,
|
32
|
-
limit, sample, sort, order, facet, select,
|
33
|
+
limit, sample, sort, order, facet, select,
|
33
34
|
works, agency, options, verbose)
|
34
35
|
|
35
36
|
self.endpt = endpt
|
@@ -50,52 +51,53 @@ module Serrano
|
|
50
51
|
end
|
51
52
|
|
52
53
|
def perform
|
53
|
-
filt = filter_handler(
|
54
|
+
filt = filter_handler(filter)
|
54
55
|
|
55
|
-
self.select =
|
56
|
+
self.select = select.join(",") if select && select.class == Array
|
56
57
|
|
57
|
-
args = {
|
58
|
-
rows:
|
59
|
-
order:
|
60
|
-
select:
|
61
|
-
opts = args.delete_if { |
|
58
|
+
args = {query: query, filter: filt, offset: offset,
|
59
|
+
rows: limit, sample: sample, sort: sort,
|
60
|
+
order: order, facet: facet,
|
61
|
+
select: select}
|
62
|
+
opts = args.delete_if { |_k, v| v.nil? }
|
62
63
|
|
63
|
-
if verbose
|
64
|
-
|
64
|
+
conn = if verbose
|
65
|
+
Faraday.new(url: Serrano.base_url, request: options || []) do |f|
|
65
66
|
f.response :logger
|
66
67
|
f.use FaradayMiddleware::RaiseHttpException
|
67
|
-
f.adapter
|
68
|
+
f.adapter Faraday.default_adapter
|
68
69
|
end
|
69
70
|
else
|
70
|
-
|
71
|
+
Faraday.new(url: Serrano.base_url, request: options || []) do |f|
|
71
72
|
f.use FaradayMiddleware::RaiseHttpException
|
72
|
-
f.adapter
|
73
|
+
f.adapter Faraday.default_adapter
|
73
74
|
end
|
74
75
|
end
|
75
76
|
|
76
77
|
conn.headers[:user_agent] = make_ua
|
77
78
|
conn.headers["X-USER-AGENT"] = make_ua
|
78
79
|
|
79
|
-
if
|
80
|
-
res = conn.get
|
81
|
-
|
80
|
+
if id.nil?
|
81
|
+
res = conn.get endpt, opts
|
82
|
+
MultiJson.load(res.body)
|
82
83
|
else
|
84
|
+
self.id = Array(id)
|
85
|
+
# url encoding
|
86
|
+
self.id = id.map { |x| ERB::Util.url_encode(x) }
|
83
87
|
coll = []
|
84
|
-
|
85
|
-
if
|
86
|
-
|
88
|
+
id.each do |x|
|
89
|
+
endpt = if works
|
90
|
+
self.endpt + "/" + x.to_s + "/works"
|
91
|
+
elsif agency
|
92
|
+
self.endpt + "/" + x.to_s + "/agency"
|
87
93
|
else
|
88
|
-
|
89
|
-
endpt = self.endpt + '/' + x.to_s + "/agency"
|
90
|
-
else
|
91
|
-
endpt = self.endpt + '/' + x.to_s
|
92
|
-
end
|
94
|
+
self.endpt + "/" + x.to_s
|
93
95
|
end
|
94
96
|
|
95
97
|
res = conn.get endpt, opts
|
96
98
|
coll << MultiJson.load(res.body)
|
97
99
|
end
|
98
|
-
|
100
|
+
coll
|
99
101
|
end
|
100
102
|
end
|
101
103
|
end
|