ebsco-eds 1.0.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +1 -2
- data/CHANGELOG.md +20 -1
- data/README.md +1 -1
- data/ebsco-eds.gemspec +15 -15
- data/lib/ebsco/eds/configuration.rb +8 -1
- data/lib/ebsco/eds/record.rb +6 -1
- data/lib/ebsco/eds/results.rb +67 -56
- data/lib/ebsco/eds/session.rb +72 -25
- data/lib/ebsco/eds/version.rb +1 -1
- data/lib/faraday/eds_caching_middleware.rb +28 -18
- data/lib/faraday/eds_exception_middleware.rb +13 -9
- metadata +61 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a98621f9b0ef365e1fca3f814127d8a1a20ff7fa70113d254c2ff90d33b62777
|
4
|
+
data.tar.gz: 639b960e78cbe5c01aaaefc88b524286371a7c6aca32c9c16dc26e70b99b3b97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b50c885e10fd0c126736c69af927e5d69e76eb3af3c3985f63acdcf49c385f9285bbee9bd4185b177d64279ad8778218a665fd51c01efd957113c75431ef0c1
|
7
|
+
data.tar.gz: 848222290962eec5901b0bf0f871e64ed8066a375aea7785a8ca1066ac3d84a03f1f513388886049b33958eeb8d9e4230911b276c6fdac7a13eaffcdf080ace0
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,12 +4,28 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [1.0.8] - 2019-08-12
|
8
|
+
### Fixed
|
9
|
+
- Throws error when query fails with a 200 status code and html error message (query = `the meaning of life or 4=2`), see #90.
|
10
|
+
- Raises a specific "record not found" error instead of a generic "bad request" error when a record cannot be retrieved, see #88.
|
11
|
+
|
12
|
+
## [1.0.7] - 2018-12-05
|
13
|
+
### Changed
|
14
|
+
- logger dependency removed since it's been part of the standard library.
|
15
|
+
|
16
|
+
## [1.0.6] - 2018-11-14
|
17
|
+
### Fixed
|
18
|
+
- Fixed a bug where the cached auth key isn't deleted if it expires before its cache expiration. This should only occur in rare cases where the auth token cache expiration exceeds 30 minutes.
|
19
|
+
### Added
|
20
|
+
- Cache expiration is configurable for individual EDS API calls (time unit = seconds).
|
21
|
+
### Changed
|
22
|
+
- Default cache expiration for auth keys is now 25 minutes instead of 30 to make sure they are always refreshed before their 30 minute expiration. If an expiration is configured longer than 25 minutes, it is reset to 25 minutes automatically.
|
23
|
+
|
7
24
|
## [1.0.5] - 2018-11-02
|
8
25
|
### Fixed
|
9
26
|
- Fixed a bug where fulltext html becomes nil after sanitizing. [#85](https://github.com/ebsco/edsapi-ruby/issues/85)
|
10
27
|
- Fixed a bug where the url protocol is missing from fulltext custom links. [#86](https://github.com/ebsco/edsapi-ruby/issues/86)
|
11
28
|
|
12
|
-
|
13
29
|
## [1.0.4] - 2018-10-29
|
14
30
|
### Fixed
|
15
31
|
- List retrieval returns a repeating list of just the first record.
|
@@ -81,6 +97,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
81
97
|
### Added
|
82
98
|
- Adds KW (keywords) and SH (subject heading) to solr search fields
|
83
99
|
|
100
|
+
[1.0.8]: https://github.com/ebsco/edsapi-ruby/compare/1.0.7...1.0.8
|
101
|
+
[1.0.7]: https://github.com/ebsco/edsapi-ruby/compare/1.0.6...1.0.7
|
102
|
+
[1.0.6]: https://github.com/ebsco/edsapi-ruby/compare/1.0.5...1.0.6
|
84
103
|
[1.0.5]: https://github.com/ebsco/edsapi-ruby/compare/1.0.4...1.0.5
|
85
104
|
[1.0.4]: https://github.com/ebsco/edsapi-ruby/compare/1.0.3...1.0.4
|
86
105
|
[1.0.3]: https://github.com/ebsco/edsapi-ruby/compare/1.0.2...1.0.3
|
data/README.md
CHANGED
data/ebsco-eds.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'ebsco/eds/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'ebsco-eds'
|
8
8
|
spec.version = EBSCO::EDS::VERSION
|
9
|
-
spec.authors = ['
|
10
|
-
spec.email = ['
|
9
|
+
spec.authors = ['Madeline Dale','Eric Frierson']
|
10
|
+
spec.email = ['mdale@ebsco.com, efrierson@ebsco.com']
|
11
11
|
spec.summary = 'Summary: EBSCO EDS API'
|
12
12
|
spec.description = 'Description: EBSCO EDS API'
|
13
13
|
spec.homepage = 'https://github.com/ebsco/edsapi-ruby'
|
@@ -29,31 +29,31 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
30
|
spec.require_paths = ['lib']
|
31
31
|
|
32
|
-
spec.required_ruby_version = '>=
|
32
|
+
spec.required_ruby_version = '>= 2.4'
|
33
33
|
|
34
34
|
spec.add_dependency 'faraday', '~> 0'
|
35
35
|
spec.add_dependency 'faraday-detailed_logger', '~> 2.0'
|
36
36
|
spec.add_dependency 'faraday_middleware', '~> 0.11'
|
37
|
-
spec.add_dependency 'logger', '~> 1.2'
|
38
37
|
spec.add_dependency 'dotenv', '~> 2.2'
|
39
38
|
spec.add_dependency 'climate_control', '~> 0'
|
40
|
-
spec.add_dependency 'require_all', '~>
|
41
|
-
spec.add_dependency 'bibtex-ruby', '~>
|
39
|
+
spec.add_dependency 'require_all', '~> 2.0'
|
40
|
+
spec.add_dependency 'bibtex-ruby', '~> 5.1', '>= 5.1.0'
|
42
41
|
spec.add_dependency 'citeproc', '>= 1.0.4', '< 2.0'
|
43
42
|
spec.add_dependency 'csl', '~> 1.4'
|
44
43
|
spec.add_dependency 'citeproc-ruby', '~> 1.0', '>= 1.0.2'
|
45
44
|
spec.add_dependency 'csl-styles', '~> 1.0', '>= 1.0.1.5'
|
46
|
-
spec.add_dependency 'activesupport', '~> 5.
|
47
|
-
spec.add_dependency 'net-http-persistent', '~>
|
48
|
-
spec.add_dependency 'sanitize', '~>
|
45
|
+
spec.add_dependency 'activesupport', '~> 5.2'
|
46
|
+
spec.add_dependency 'net-http-persistent', '~> 3.1'
|
47
|
+
spec.add_dependency 'sanitize', '~> 5.0'
|
48
|
+
spec.add_dependency 'public_suffix', '~>4.0'
|
49
49
|
|
50
|
-
spec.add_development_dependency 'bundler'
|
51
|
-
spec.add_development_dependency 'rake', '~> 12.
|
50
|
+
spec.add_development_dependency 'bundler'
|
51
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
52
52
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
53
|
-
spec.add_development_dependency 'simplecov', '~> 0'
|
53
|
+
spec.add_development_dependency 'simplecov', '~> 0.17.0'
|
54
54
|
spec.add_development_dependency 'codecov', '~> 0.1'
|
55
|
-
spec.add_development_dependency 'vcr', '~>
|
56
|
-
spec.add_development_dependency 'minitest-vcr', '~>
|
57
|
-
spec.add_development_dependency 'webmock', '~>
|
55
|
+
spec.add_development_dependency 'vcr', '~> 5.0', '>= 5.0.0'
|
56
|
+
spec.add_development_dependency 'minitest-vcr', '~> 1.4', '>= 1.4.0'
|
57
|
+
spec.add_development_dependency 'webmock', '~> 3.6'
|
58
58
|
|
59
59
|
end
|
@@ -38,6 +38,12 @@ module EBSCO
|
|
38
38
|
:ebook_preferred_format => 'ebook-pdf',
|
39
39
|
:use_cache => true,
|
40
40
|
:eds_cache_dir => ENV['TMPDIR'] || '/tmp',
|
41
|
+
:auth_cache_expires_in => 1500,
|
42
|
+
:info_cache_expires_in => 86400,
|
43
|
+
:retrieve_cache_expires_in => 1800,
|
44
|
+
:search_cache_expires_in => 1800,
|
45
|
+
:export_format_cache_expires_in => 86400,
|
46
|
+
:citation_styles_cache_expires_in => 86400,
|
41
47
|
:timeout => 60,
|
42
48
|
:open_timeout => 12,
|
43
49
|
:max_page_jumps => 6,
|
@@ -53,7 +59,8 @@ module EBSCO
|
|
53
59
|
:ris_link_find => '',
|
54
60
|
:ris_link_replace => '',
|
55
61
|
:ris_db_find => '',
|
56
|
-
:ris_db_replace => ''
|
62
|
+
:ris_db_replace => '',
|
63
|
+
:smarttext_failover => false
|
57
64
|
}
|
58
65
|
@valid_config_keys = @config.keys
|
59
66
|
end
|
data/lib/ebsco/eds/record.rb
CHANGED
@@ -961,7 +961,12 @@ module EBSCO
|
|
961
961
|
html = html.gsub(/\\n /, '')
|
962
962
|
end
|
963
963
|
|
964
|
-
Sanitize.fragment(html, sanitize_config)
|
964
|
+
sanitized_html = Sanitize.fragment(html, sanitize_config)
|
965
|
+
# sanitize 5.0 fails to restore element case after doing lowercase
|
966
|
+
sanitized_html = sanitized_html.gsub(/<searchlink/, '<searchLink')
|
967
|
+
sanitized_html = sanitized_html.gsub(/<\/searchlink>/, '</searchLink>')
|
968
|
+
sanitized_html
|
969
|
+
|
965
970
|
end
|
966
971
|
|
967
972
|
# dynamically add item metadata as 'eds_extra_ItemNameOrLabel'
|
data/lib/ebsco/eds/results.rb
CHANGED
@@ -29,76 +29,87 @@ module EBSCO
|
|
29
29
|
|
30
30
|
# Creates search results from the \EDS API search response. It includes information about the results and a list
|
31
31
|
# of Record items.
|
32
|
-
def initialize(search_results, eds_config = {}, additional_limiters = {}, options = {})
|
32
|
+
def initialize(search_results, eds_config = {}, additional_limiters = {}, options = {}, smarttext_failover = false)
|
33
33
|
|
34
34
|
@results = search_results
|
35
|
-
@limiters = additional_limiters
|
36
|
-
@raw_options = options
|
37
|
-
|
38
|
-
# titleize facets?
|
39
|
-
(ENV.has_key? 'EDS_TITLEIZE_FACETS') ?
|
40
|
-
if %w(y Y yes Yes true True).include?(ENV['EDS_TITLEIZE_FACETS'])
|
41
|
-
@titleize_facets_on = true
|
42
|
-
else
|
43
|
-
@titleize_facets_on = false
|
44
|
-
end :
|
45
|
-
@titleize_facets_on = eds_config[:titleize_facets]
|
46
|
-
|
47
|
-
# convert all results to a list of records
|
48
|
-
@records = []
|
49
|
-
if @results['SearchResult']['Data']['Records']
|
50
|
-
@results['SearchResult']['Data']['Records'].each { |record|
|
51
|
-
|
52
|
-
@records.push(EBSCO::EDS::Record.new(record, eds_config))
|
53
|
-
|
54
|
-
# # records hidden in guest mode
|
55
|
-
# if record['Header']['AccessLevel']
|
56
|
-
# if record['Header']['AccessLevel'].to_i > 1
|
57
|
-
# @records.push(EBSCO::EDS::Record.new(record))
|
58
|
-
# else
|
59
|
-
# @records.push(EBSCO::EDS::Record.new(record))
|
60
|
-
# end
|
61
|
-
# else
|
62
|
-
# @records.push(EBSCO::EDS::Record.new(record))
|
63
|
-
# end
|
64
35
|
|
65
|
-
|
66
|
-
|
36
|
+
if @results.is_a?(Hash)
|
37
|
+
|
38
|
+
@limiters = additional_limiters
|
39
|
+
@raw_options = options
|
40
|
+
|
41
|
+
# titleize facets?
|
42
|
+
(ENV.has_key? 'EDS_TITLEIZE_FACETS') ?
|
43
|
+
if %w(y Y yes Yes true True).include?(ENV['EDS_TITLEIZE_FACETS'])
|
44
|
+
@titleize_facets_on = true
|
45
|
+
else
|
46
|
+
@titleize_facets_on = false
|
47
|
+
end :
|
48
|
+
@titleize_facets_on = eds_config[:titleize_facets]
|
49
|
+
|
50
|
+
# convert all results to a list of records
|
51
|
+
@records = []
|
52
|
+
if @results['SearchResult']['Data']['Records']
|
53
|
+
@results['SearchResult']['Data']['Records'].each { |record|
|
54
|
+
|
55
|
+
@records.push(EBSCO::EDS::Record.new(record, eds_config))
|
56
|
+
|
57
|
+
# # records hidden in guest mode
|
58
|
+
# if record['Header']['AccessLevel']
|
59
|
+
# if record['Header']['AccessLevel'].to_i > 1
|
60
|
+
# @records.push(EBSCO::EDS::Record.new(record))
|
61
|
+
# else
|
62
|
+
# @records.push(EBSCO::EDS::Record.new(record))
|
63
|
+
# end
|
64
|
+
# else
|
65
|
+
# @records.push(EBSCO::EDS::Record.new(record))
|
66
|
+
# end
|
67
|
+
|
68
|
+
}
|
69
|
+
end
|
67
70
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
71
|
+
# create a special list of research starter records
|
72
|
+
@research_starters = []
|
73
|
+
_related_records = @results.fetch('SearchResult',{}).fetch('RelatedContent',{}).fetch('RelatedRecords',{})
|
74
|
+
if _related_records.count > 0
|
75
|
+
_related_records.each do |related_item|
|
76
|
+
if related_item['Type'] == 'rs'
|
77
|
+
rs_entries = related_item.fetch('Records',{})
|
78
|
+
if rs_entries.count > 0
|
79
|
+
rs_entries.each do |rs_record|
|
80
|
+
@research_starters.push(EBSCO::EDS::Record.new(rs_record, eds_config))
|
81
|
+
end
|
78
82
|
end
|
79
83
|
end
|
80
84
|
end
|
81
85
|
end
|
82
|
-
end
|
83
86
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
87
|
+
# create a special list of exact match publications
|
88
|
+
@publication_match = []
|
89
|
+
_related_publications = @results.fetch('SearchResult',{}).fetch('RelatedContent',{}).fetch('RelatedPublications',{})
|
90
|
+
if _related_publications.count > 0
|
91
|
+
_related_publications.each do |related_item|
|
92
|
+
if related_item['Type'] == 'emp'
|
93
|
+
_publication_matches = related_item.fetch('PublicationRecords',{})
|
94
|
+
if _publication_matches.count > 0
|
95
|
+
_publication_matches.each do |publication_record|
|
96
|
+
@publication_match.push(EBSCO::EDS::Record.new(publication_record, eds_config))
|
97
|
+
end
|
94
98
|
end
|
95
99
|
end
|
96
100
|
end
|
97
101
|
end
|
98
|
-
end
|
99
102
|
|
100
|
-
|
101
|
-
|
103
|
+
# titleize facets
|
104
|
+
@titleize_facets = %w[Language Journal SubjectEDS SubjectGeographic Publisher]
|
105
|
+
|
106
|
+
# set flag that query was rerun with smarttext after no results were found
|
107
|
+
@smarttext_failover = smarttext_failover
|
108
|
+
|
109
|
+
else
|
110
|
+
# response isn't a hash (eg, html error page)
|
111
|
+
raise EBSCO::EDS::ApiError, 'EBSCO API error: Query failed.'
|
112
|
+
end
|
102
113
|
|
103
114
|
end
|
104
115
|
|
data/lib/ebsco/eds/session.rb
CHANGED
@@ -105,9 +105,17 @@ module EBSCO
|
|
105
105
|
raise EBSCO::EDS::InvalidParameter, 'Session must specify a valid api profile.' if blank?(@profile)
|
106
106
|
|
107
107
|
# these config options can be overridden by environment vars
|
108
|
-
@auth_type
|
109
|
-
@org
|
110
|
-
@cache_dir
|
108
|
+
@auth_type = (ENV.has_key? 'EDS_AUTH') ? ENV['EDS_AUTH'] : @config[:auth]
|
109
|
+
@org = (ENV.has_key? 'EDS_ORG') ? ENV['EDS_ORG'] : @config[:org]
|
110
|
+
@cache_dir = (ENV.has_key? 'EDS_CACHE_DIR') ? ENV['EDS_CACHE_DIR'] : @config[:eds_cache_dir]
|
111
|
+
@auth_expire = (ENV.has_key? 'EDS_AUTH_CACHE_EXPIRES_IN') ? ENV['EDS_AUTH_CACHE_EXPIRES_IN'] : @config[:auth_cache_expires_in]
|
112
|
+
@info_expire = (ENV.has_key? 'EDS_INFO_CACHE_EXPIRES_IN') ? ENV['EDS_INFO_CACHE_EXPIRES_IN'] : @config[:info_cache_expires_in]
|
113
|
+
@retrieve_expire = (ENV.has_key? 'EDS_RETRIEVE_CACHE_EXPIRES_IN') ? ENV['EDS_RETRIEVE_CACHE_EXPIRES_IN'] : @config[:retrieve_cache_expires_in]
|
114
|
+
@search_expire = (ENV.has_key? 'EDS_SEARCH_CACHE_EXPIRES_IN') ? ENV['EDS_SEARCH_CACHE_EXPIRES_IN'] : @config[:search_cache_expires_in]
|
115
|
+
@export_format_expire = (ENV.has_key? 'EDS_EXPORT_FORMAT_CACHE_EXPIRES_IN') ? ENV['EDS_EXPORT_FORMAT_CACHE_EXPIRES_IN'] : @config[:export_format_cache_expires_in]
|
116
|
+
@citation_styles_expire = (ENV.has_key? 'EDS_CITATION_STYLES_CACHE_EXPIRES_IN') ? ENV['EDS_CITATION_STYLES_CACHE_EXPIRES_IN'] : @config[:citation_styles_cache_expires_in]
|
117
|
+
|
118
|
+
|
111
119
|
@log_level = (ENV.has_key? 'EDS_LOG_LEVEL') ? ENV['EDS_LOG_LEVEL'] : @config[:log_level]
|
112
120
|
|
113
121
|
(ENV.has_key? 'EDS_GUEST') ?
|
@@ -235,11 +243,15 @@ module EBSCO
|
|
235
243
|
if @search_options.nil? || !add_actions
|
236
244
|
@search_options = EBSCO::EDS::Options.new(options, @info)
|
237
245
|
end
|
238
|
-
|
239
246
|
_response = do_request(:post, path: '/edsapi/rest/Search', payload: @search_options)
|
240
247
|
@search_results = EBSCO::EDS::Results.new(_response, @config,
|
241
248
|
@info.available_limiters, options)
|
242
|
-
|
249
|
+
if @search_results.stat_total_hits.to_i == 0 && @config[:smarttext_failover] == true
|
250
|
+
@search_options.add_actions('SetSearchMode(smart)', @info)
|
251
|
+
_response = do_request(:post, path: '/edsapi/rest/Search', payload: @search_options)
|
252
|
+
@search_results = EBSCO::EDS::Results.new(_response, @config,
|
253
|
+
@info.available_limiters, options, true)
|
254
|
+
end
|
243
255
|
# create temp format facet results if needed
|
244
256
|
if options['f']
|
245
257
|
if options['f'].key?('eds_publication_type_facet')
|
@@ -332,21 +344,24 @@ module EBSCO
|
|
332
344
|
citation_exports_params = "?an=#{an}&dbid=#{dbid}&format=#{format}"
|
333
345
|
citation_exports_response = do_request(:get, path: @config[:citation_exports_url] + citation_exports_params)
|
334
346
|
EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: citation_exports_response, eds_config: @config)
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
347
|
+
rescue EBSCO::EDS::NotFound => e
|
348
|
+
custom_error_message = JSON.parse e.message.gsub('=>', ':')
|
349
|
+
# ErrorNumber 132 - Record not found
|
350
|
+
if custom_error_message['ErrorNumber'] == '132'
|
351
|
+
record_not_found = {"Format"=>format, "Label"=>"", "Data"=>"", "Error"=>"Record not found"}
|
352
|
+
EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: record_not_found, eds_config: @config)
|
353
|
+
end
|
354
|
+
rescue EBSCO::EDS::BadRequest => e
|
355
|
+
custom_error_message = JSON.parse e.message.gsub('=>', ':')
|
356
|
+
# ErrorNumber 112 - Invalid Argument Value
|
357
|
+
if custom_error_message['ErrorNumber'] == '112'
|
358
|
+
unknown_export_format = {"Format"=>format, "Label"=>"", "Data"=>"", "Error"=>"Invalid citation export format"}
|
359
|
+
EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: unknown_export_format, eds_config: @config)
|
360
|
+
else
|
361
|
+
unknown_error = {"Format"=>format, "Label"=>"", "Data"=>"", "Error"=>custom_error_message['ErrorDescription']}
|
362
|
+
EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: unknown_error, eds_config: @config)
|
363
|
+
end
|
348
364
|
end
|
349
|
-
end
|
350
365
|
end
|
351
366
|
|
352
367
|
# fetch the citation from the citation rest endpoint
|
@@ -355,6 +370,13 @@ module EBSCO
|
|
355
370
|
citation_styles_params = "?an=#{an}&dbid=#{dbid}&styles=#{format}"
|
356
371
|
citation_styles_response = do_request(:get, path: @config[:citation_styles_url] + citation_styles_params)
|
357
372
|
EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: citation_styles_response, eds_config: @config)
|
373
|
+
rescue EBSCO::EDS::NotFound => e
|
374
|
+
custom_error_message = JSON.parse e.message.gsub('=>', ':')
|
375
|
+
# ErrorNumber 132 - Record not found
|
376
|
+
if custom_error_message['ErrorNumber'] == '132'
|
377
|
+
record_not_found = {"Format"=>format, "Label"=>"", "Data"=>"", "Error"=>"Record not found"}
|
378
|
+
EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: record_not_found, eds_config: @config)
|
379
|
+
end
|
358
380
|
rescue EBSCO::EDS::BadRequest => e
|
359
381
|
custom_error_message = JSON.parse e.message.gsub('=>', ':')
|
360
382
|
unknown_error = {"Id"=>format, "Label"=>"", "Data"=>"", "Error"=>custom_error_message['ErrorDescription']}
|
@@ -462,9 +484,13 @@ module EBSCO
|
|
462
484
|
list.each.with_index(1) { |id, index|
|
463
485
|
dbid = id.split('__',2).first
|
464
486
|
accession = id.split('__',2).last
|
465
|
-
|
466
|
-
|
467
|
-
|
487
|
+
begin
|
488
|
+
current_rec = retrieve(dbid: dbid, an: accession, highlight: highlight, ebook: @config[:ebook_preferred_format])
|
489
|
+
current_rec.eds_result_id = index
|
490
|
+
records.push current_rec
|
491
|
+
rescue EBSCO::EDS::BadRequest, EBSCO::EDS::NotFound => e
|
492
|
+
puts "Request for #{id} in #{self.class.name}#solr_retrieve_list failed with #{e}" if @debug
|
493
|
+
end
|
468
494
|
}
|
469
495
|
end
|
470
496
|
r = empty_results(records.length)
|
@@ -847,6 +873,11 @@ module EBSCO
|
|
847
873
|
do_request(method, path: path, payload: payload, attempt: attempt+1)
|
848
874
|
# auth token invalid
|
849
875
|
when '104', '107'
|
876
|
+
# delete the auth cache to make sure we have an unexpired auth token
|
877
|
+
if @use_cache
|
878
|
+
puts 'DELETING AUTH CACHE...' if @debug
|
879
|
+
@cache_store.delete_matched('https://' + @api_hosts_list[@api_host_index] + @config[:uid_auth_url])
|
880
|
+
end
|
850
881
|
@auth_token = nil
|
851
882
|
@auth_token = create_auth_token
|
852
883
|
do_request(method, path: path, payload: payload, attempt: attempt+1)
|
@@ -1069,7 +1100,15 @@ module EBSCO
|
|
1069
1100
|
conn.headers['x-authenticationToken'] = @auth_token ? @auth_token : ''
|
1070
1101
|
conn.headers['User-Agent'] = @config[:user_agent]
|
1071
1102
|
conn.request :url_encoded
|
1072
|
-
conn.use :eds_caching_middleware,
|
1103
|
+
conn.use :eds_caching_middleware,
|
1104
|
+
store: @cache_store,
|
1105
|
+
auth_expire: @auth_expire,
|
1106
|
+
info_expire: @info_expire,
|
1107
|
+
search_expire: @search_expire,
|
1108
|
+
retrieve_expire: @retrieve_expire,
|
1109
|
+
export_format_expire: @export_format_expire,
|
1110
|
+
citation_styles_expire: @citation_styles_expire,
|
1111
|
+
logger: @debug ? logger : nil if @use_cache
|
1073
1112
|
conn.use :eds_exception_middleware
|
1074
1113
|
conn.response :json, content_type: /\bjson$/
|
1075
1114
|
conn.response :detailed_logger, logger if @debug
|
@@ -1109,7 +1148,15 @@ module EBSCO
|
|
1109
1148
|
conn.headers['x-authenticationToken'] = @auth_token ? @auth_token : ''
|
1110
1149
|
conn.headers['User-Agent'] = @config[:user_agent]
|
1111
1150
|
conn.request :url_encoded
|
1112
|
-
conn.use :eds_caching_middleware,
|
1151
|
+
conn.use :eds_caching_middleware,
|
1152
|
+
store: @cache_store,
|
1153
|
+
auth_expire: @auth_expire,
|
1154
|
+
info_expire: @info_expire,
|
1155
|
+
search_expire: @search_expire,
|
1156
|
+
retrieve_expire: @retrieve_expire,
|
1157
|
+
export_format_expire: @export_format_expire,
|
1158
|
+
citation_styles_expire: @citation_styles_expire,
|
1159
|
+
logger: @debug ? logger : nil if @use_cache
|
1113
1160
|
conn.use :eds_exception_middleware
|
1114
1161
|
conn.response :json, content_type: /\bjson$/
|
1115
1162
|
conn.response :detailed_logger, logger if @debug
|
@@ -1222,4 +1269,4 @@ module EBSCO
|
|
1222
1269
|
|
1223
1270
|
end
|
1224
1271
|
end
|
1225
|
-
end
|
1272
|
+
end
|
data/lib/ebsco/eds/version.rb
CHANGED
@@ -9,11 +9,16 @@ module Faraday
|
|
9
9
|
def initialize(app, *args)
|
10
10
|
super(app)
|
11
11
|
options = args.first || {}
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@
|
16
|
-
@
|
12
|
+
@auth_expire = options.fetch(:auth_expire, 1500)
|
13
|
+
@info_expire = options.fetch(:info_expire, 86400)
|
14
|
+
@retrieve_expire = options.fetch(:retrieve_expire, 1800)
|
15
|
+
@search_expire = options.fetch(:search_expire, 1800)
|
16
|
+
@export_format_expire = options.fetch(:export_format_expire, 86400)
|
17
|
+
@citation_styles_expire = options.fetch(:citation_styles_expire, 86400)
|
18
|
+
@logger = options.fetch(:logger, nil)
|
19
|
+
@namespace = options.fetch(:namespace, 'faraday-eds-cache')
|
20
|
+
@store = options.fetch(:store, :memory_store)
|
21
|
+
@store_options = options.fetch(:store_options, {})
|
17
22
|
|
18
23
|
@store_options[:namespace] ||= @namespace
|
19
24
|
|
@@ -44,40 +49,45 @@ module Faraday
|
|
44
49
|
end
|
45
50
|
|
46
51
|
def cache_response(env)
|
52
|
+
|
47
53
|
return unless cacheable?(env) && !env.request_headers['x-faraday-eds-cache']
|
48
54
|
|
49
55
|
info "Cache WRITE: #{key(env)}"
|
50
|
-
custom_expires_in =
|
56
|
+
custom_expires_in = 1800 # 30 mins
|
51
57
|
uri = env.url
|
52
58
|
|
53
59
|
if uri.request_uri.include?('/authservice/rest/uidauth')
|
54
|
-
custom_expires_in =
|
55
|
-
|
60
|
+
custom_expires_in = @auth_expire
|
61
|
+
# don't allow expiration to exceed 25 minutes since auth tokens always expire in 30 minutes
|
62
|
+
if custom_expires_in > 1500
|
63
|
+
custom_expires_in = 1500
|
64
|
+
end
|
65
|
+
info "#{uri} - Setting expires: #{custom_expires_in}"
|
56
66
|
end
|
57
67
|
|
58
68
|
if uri.request_uri.include?('/edsapi/rest/Info')
|
59
|
-
custom_expires_in =
|
60
|
-
info "#{uri} - Setting
|
69
|
+
custom_expires_in = @info_expire
|
70
|
+
info "#{uri} - Setting /edsapi/rest/Info expires: #{custom_expires_in}"
|
61
71
|
end
|
62
72
|
|
63
73
|
if uri.request_uri.include?('/edsapi/rest/Search?')
|
64
|
-
custom_expires_in =
|
65
|
-
info "#{uri} - Setting
|
74
|
+
custom_expires_in = @search_expire
|
75
|
+
info "#{uri} - Setting /edsapi/rest/Search expires: #{custom_expires_in}"
|
66
76
|
end
|
67
77
|
|
68
78
|
if uri.request_uri.include?('/edsapi/rest/Retrieve?')
|
69
|
-
custom_expires_in =
|
70
|
-
info "#{uri} - Setting
|
79
|
+
custom_expires_in = @retrieve_expire
|
80
|
+
info "#{uri} - Setting /edsapi/rest/Retrieve expires: #{custom_expires_in}"
|
71
81
|
end
|
72
82
|
|
73
83
|
if uri.request_uri.include?('/edsapi/rest/ExportFormat')
|
74
|
-
custom_expires_in =
|
75
|
-
info "#{uri} - Setting
|
84
|
+
custom_expires_in = @export_format_expire
|
85
|
+
info "#{uri} - Setting /edsapi/rest/ExportFormat expires: #{custom_expires_in}"
|
76
86
|
end
|
77
87
|
|
78
88
|
if uri.request_uri.include?('/edsapi/rest/CitationStyles')
|
79
|
-
custom_expires_in =
|
80
|
-
info "#{uri} - Setting
|
89
|
+
custom_expires_in = @citation_styles_expire
|
90
|
+
info "#{uri} - Setting /edsapi/rest/CitationStyles expires: #{custom_expires_in}"
|
81
91
|
end
|
82
92
|
|
83
93
|
@store.write(key(env), env, expires_in: custom_expires_in)
|
@@ -14,15 +14,19 @@ module Faraday
|
|
14
14
|
case response.status
|
15
15
|
when 200
|
16
16
|
when 400
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
17
|
+
if response.body['ErrorNumber'] == '132'
|
18
|
+
raise EBSCO::EDS::NotFound.new(error_message(response))
|
19
|
+
else
|
20
|
+
raise EBSCO::EDS::BadRequest.new(error_message(response))
|
21
|
+
end
|
22
|
+
# when 401
|
23
|
+
# raise EBSCO::EDS::Unauthorized.new
|
24
|
+
# when 403
|
25
|
+
# raise EBSCO::EDS::Forbidden.new
|
26
|
+
# when 404
|
27
|
+
# raise EBSCO::EDS::NotFound.new
|
28
|
+
# when 429
|
29
|
+
# raise EBSCO::EDS::TooManyRequests.new
|
26
30
|
when 500
|
27
31
|
raise EBSCO::EDS::InternalServerError.new
|
28
32
|
when 503
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ebsco-eds
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Madeline Dale
|
8
8
|
- Eric Frierson
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-08-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -53,20 +53,6 @@ dependencies:
|
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0.11'
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: logger
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - "~>"
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '1.2'
|
63
|
-
type: :runtime
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - "~>"
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '1.2'
|
70
56
|
- !ruby/object:Gem::Dependency
|
71
57
|
name: dotenv
|
72
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,28 +87,34 @@ dependencies:
|
|
101
87
|
requirements:
|
102
88
|
- - "~>"
|
103
89
|
- !ruby/object:Gem::Version
|
104
|
-
version: '
|
90
|
+
version: '2.0'
|
105
91
|
type: :runtime
|
106
92
|
prerelease: false
|
107
93
|
version_requirements: !ruby/object:Gem::Requirement
|
108
94
|
requirements:
|
109
95
|
- - "~>"
|
110
96
|
- !ruby/object:Gem::Version
|
111
|
-
version: '
|
97
|
+
version: '2.0'
|
112
98
|
- !ruby/object:Gem::Dependency
|
113
99
|
name: bibtex-ruby
|
114
100
|
requirement: !ruby/object:Gem::Requirement
|
115
101
|
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 5.1.0
|
116
105
|
- - "~>"
|
117
106
|
- !ruby/object:Gem::Version
|
118
|
-
version: '
|
107
|
+
version: '5.1'
|
119
108
|
type: :runtime
|
120
109
|
prerelease: false
|
121
110
|
version_requirements: !ruby/object:Gem::Requirement
|
122
111
|
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: 5.1.0
|
123
115
|
- - "~>"
|
124
116
|
- !ruby/object:Gem::Version
|
125
|
-
version: '
|
117
|
+
version: '5.1'
|
126
118
|
- !ruby/object:Gem::Dependency
|
127
119
|
name: citeproc
|
128
120
|
requirement: !ruby/object:Gem::Requirement
|
@@ -203,76 +195,84 @@ dependencies:
|
|
203
195
|
requirements:
|
204
196
|
- - "~>"
|
205
197
|
- !ruby/object:Gem::Version
|
206
|
-
version: '5.
|
198
|
+
version: '5.2'
|
207
199
|
type: :runtime
|
208
200
|
prerelease: false
|
209
201
|
version_requirements: !ruby/object:Gem::Requirement
|
210
202
|
requirements:
|
211
203
|
- - "~>"
|
212
204
|
- !ruby/object:Gem::Version
|
213
|
-
version: '5.
|
205
|
+
version: '5.2'
|
214
206
|
- !ruby/object:Gem::Dependency
|
215
207
|
name: net-http-persistent
|
216
208
|
requirement: !ruby/object:Gem::Requirement
|
217
209
|
requirements:
|
218
210
|
- - "~>"
|
219
211
|
- !ruby/object:Gem::Version
|
220
|
-
version: '
|
212
|
+
version: '3.1'
|
221
213
|
type: :runtime
|
222
214
|
prerelease: false
|
223
215
|
version_requirements: !ruby/object:Gem::Requirement
|
224
216
|
requirements:
|
225
217
|
- - "~>"
|
226
218
|
- !ruby/object:Gem::Version
|
227
|
-
version: '
|
219
|
+
version: '3.1'
|
228
220
|
- !ruby/object:Gem::Dependency
|
229
221
|
name: sanitize
|
230
222
|
requirement: !ruby/object:Gem::Requirement
|
231
223
|
requirements:
|
232
224
|
- - "~>"
|
233
225
|
- !ruby/object:Gem::Version
|
234
|
-
version: '
|
235
|
-
- - ">="
|
236
|
-
- !ruby/object:Gem::Version
|
237
|
-
version: 4.5.0
|
226
|
+
version: '5.0'
|
238
227
|
type: :runtime
|
239
228
|
prerelease: false
|
240
229
|
version_requirements: !ruby/object:Gem::Requirement
|
241
230
|
requirements:
|
242
231
|
- - "~>"
|
243
232
|
- !ruby/object:Gem::Version
|
244
|
-
version: '
|
245
|
-
|
233
|
+
version: '5.0'
|
234
|
+
- !ruby/object:Gem::Dependency
|
235
|
+
name: public_suffix
|
236
|
+
requirement: !ruby/object:Gem::Requirement
|
237
|
+
requirements:
|
238
|
+
- - "~>"
|
239
|
+
- !ruby/object:Gem::Version
|
240
|
+
version: '4.0'
|
241
|
+
type: :runtime
|
242
|
+
prerelease: false
|
243
|
+
version_requirements: !ruby/object:Gem::Requirement
|
244
|
+
requirements:
|
245
|
+
- - "~>"
|
246
246
|
- !ruby/object:Gem::Version
|
247
|
-
version: 4.
|
247
|
+
version: '4.0'
|
248
248
|
- !ruby/object:Gem::Dependency
|
249
249
|
name: bundler
|
250
250
|
requirement: !ruby/object:Gem::Requirement
|
251
251
|
requirements:
|
252
|
-
- - "
|
252
|
+
- - ">="
|
253
253
|
- !ruby/object:Gem::Version
|
254
|
-
version: '
|
254
|
+
version: '0'
|
255
255
|
type: :development
|
256
256
|
prerelease: false
|
257
257
|
version_requirements: !ruby/object:Gem::Requirement
|
258
258
|
requirements:
|
259
|
-
- - "
|
259
|
+
- - ">="
|
260
260
|
- !ruby/object:Gem::Version
|
261
|
-
version: '
|
261
|
+
version: '0'
|
262
262
|
- !ruby/object:Gem::Dependency
|
263
263
|
name: rake
|
264
264
|
requirement: !ruby/object:Gem::Requirement
|
265
265
|
requirements:
|
266
266
|
- - "~>"
|
267
267
|
- !ruby/object:Gem::Version
|
268
|
-
version: '12.
|
268
|
+
version: '12.3'
|
269
269
|
type: :development
|
270
270
|
prerelease: false
|
271
271
|
version_requirements: !ruby/object:Gem::Requirement
|
272
272
|
requirements:
|
273
273
|
- - "~>"
|
274
274
|
- !ruby/object:Gem::Version
|
275
|
-
version: '12.
|
275
|
+
version: '12.3'
|
276
276
|
- !ruby/object:Gem::Dependency
|
277
277
|
name: minitest
|
278
278
|
requirement: !ruby/object:Gem::Requirement
|
@@ -293,14 +293,14 @@ dependencies:
|
|
293
293
|
requirements:
|
294
294
|
- - "~>"
|
295
295
|
- !ruby/object:Gem::Version
|
296
|
-
version:
|
296
|
+
version: 0.17.0
|
297
297
|
type: :development
|
298
298
|
prerelease: false
|
299
299
|
version_requirements: !ruby/object:Gem::Requirement
|
300
300
|
requirements:
|
301
301
|
- - "~>"
|
302
302
|
- !ruby/object:Gem::Version
|
303
|
-
version:
|
303
|
+
version: 0.17.0
|
304
304
|
- !ruby/object:Gem::Dependency
|
305
305
|
name: codecov
|
306
306
|
requirement: !ruby/object:Gem::Requirement
|
@@ -319,47 +319,59 @@ dependencies:
|
|
319
319
|
name: vcr
|
320
320
|
requirement: !ruby/object:Gem::Requirement
|
321
321
|
requirements:
|
322
|
+
- - ">="
|
323
|
+
- !ruby/object:Gem::Version
|
324
|
+
version: 5.0.0
|
322
325
|
- - "~>"
|
323
326
|
- !ruby/object:Gem::Version
|
324
|
-
version: '
|
327
|
+
version: '5.0'
|
325
328
|
type: :development
|
326
329
|
prerelease: false
|
327
330
|
version_requirements: !ruby/object:Gem::Requirement
|
328
331
|
requirements:
|
332
|
+
- - ">="
|
333
|
+
- !ruby/object:Gem::Version
|
334
|
+
version: 5.0.0
|
329
335
|
- - "~>"
|
330
336
|
- !ruby/object:Gem::Version
|
331
|
-
version: '
|
337
|
+
version: '5.0'
|
332
338
|
- !ruby/object:Gem::Dependency
|
333
339
|
name: minitest-vcr
|
334
340
|
requirement: !ruby/object:Gem::Requirement
|
335
341
|
requirements:
|
342
|
+
- - ">="
|
343
|
+
- !ruby/object:Gem::Version
|
344
|
+
version: 1.4.0
|
336
345
|
- - "~>"
|
337
346
|
- !ruby/object:Gem::Version
|
338
|
-
version:
|
347
|
+
version: '1.4'
|
339
348
|
type: :development
|
340
349
|
prerelease: false
|
341
350
|
version_requirements: !ruby/object:Gem::Requirement
|
342
351
|
requirements:
|
352
|
+
- - ">="
|
353
|
+
- !ruby/object:Gem::Version
|
354
|
+
version: 1.4.0
|
343
355
|
- - "~>"
|
344
356
|
- !ruby/object:Gem::Version
|
345
|
-
version:
|
357
|
+
version: '1.4'
|
346
358
|
- !ruby/object:Gem::Dependency
|
347
359
|
name: webmock
|
348
360
|
requirement: !ruby/object:Gem::Requirement
|
349
361
|
requirements:
|
350
362
|
- - "~>"
|
351
363
|
- !ruby/object:Gem::Version
|
352
|
-
version: '
|
364
|
+
version: '3.6'
|
353
365
|
type: :development
|
354
366
|
prerelease: false
|
355
367
|
version_requirements: !ruby/object:Gem::Requirement
|
356
368
|
requirements:
|
357
369
|
- - "~>"
|
358
370
|
- !ruby/object:Gem::Version
|
359
|
-
version: '
|
371
|
+
version: '3.6'
|
360
372
|
description: 'Description: EBSCO EDS API'
|
361
373
|
email:
|
362
|
-
-
|
374
|
+
- mdale@ebsco.com, efrierson@ebsco.com
|
363
375
|
executables: []
|
364
376
|
extensions: []
|
365
377
|
extra_rdoc_files: []
|
@@ -406,15 +418,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
406
418
|
requirements:
|
407
419
|
- - ">="
|
408
420
|
- !ruby/object:Gem::Version
|
409
|
-
version:
|
421
|
+
version: '2.4'
|
410
422
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
411
423
|
requirements:
|
412
424
|
- - ">="
|
413
425
|
- !ruby/object:Gem::Version
|
414
426
|
version: '0'
|
415
427
|
requirements: []
|
416
|
-
|
417
|
-
rubygems_version: 2.5.2.3
|
428
|
+
rubygems_version: 3.0.6
|
418
429
|
signing_key:
|
419
430
|
specification_version: 4
|
420
431
|
summary: 'Summary: EBSCO EDS API'
|