ebsco-eds 1.0.4 → 1.0.9
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 +26 -0
- data/README.md +1 -1
- data/ebsco-eds.gemspec +13 -13
- data/lib/ebsco/eds/configuration.rb +6 -0
- data/lib/ebsco/eds/record.rb +18 -3
- data/lib/ebsco/eds/results.rb +63 -55
- data/lib/ebsco/eds/session.rb +58 -19
- 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 +59 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b6540dd6a4557914c9126f0c71ede4b796f24d26cea5434f134e5cbcbdbf23f3
|
4
|
+
data.tar.gz: a1a0f31fa32e934e7a7068d4b21b1ee57bf547ac432a03e02d3fb93590c871d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd6f151c9d6ec779f3bb8dc7cf06dd6950be6ed2e91f4e5cf72cb250603aad08cbb38591b3e06ed0f74de943c4bb8377f4b05f2ed7a0e09a635fff4cb88e9379
|
7
|
+
data.tar.gz: 526d2b6ee244df0d90c1616d30543f4eb1125d4e93bf47cfdd14ed449ca11d89fbe80060b0cbe6f747a530a8f3ff6815df7e26ba23a2c2e655df40e19a98a3e8
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +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
|
+
|
24
|
+
## [1.0.5] - 2018-11-02
|
25
|
+
### Fixed
|
26
|
+
- Fixed a bug where fulltext html becomes nil after sanitizing. [#85](https://github.com/ebsco/edsapi-ruby/issues/85)
|
27
|
+
- Fixed a bug where the url protocol is missing from fulltext custom links. [#86](https://github.com/ebsco/edsapi-ruby/issues/86)
|
28
|
+
|
7
29
|
## [1.0.4] - 2018-10-29
|
8
30
|
### Fixed
|
9
31
|
- List retrieval returns a repeating list of just the first record.
|
@@ -75,6 +97,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
75
97
|
### Added
|
76
98
|
- Adds KW (keywords) and SH (subject heading) to solr search fields
|
77
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
|
103
|
+
[1.0.5]: https://github.com/ebsco/edsapi-ruby/compare/1.0.4...1.0.5
|
78
104
|
[1.0.4]: https://github.com/ebsco/edsapi-ruby/compare/1.0.3...1.0.4
|
79
105
|
[1.0.3]: https://github.com/ebsco/edsapi-ruby/compare/1.0.2...1.0.3
|
80
106
|
[1.0.2]: https://github.com/ebsco/edsapi-ruby/compare/1.0.1...1.0.2
|
data/README.md
CHANGED
data/ebsco-eds.gemspec
CHANGED
@@ -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,
|
data/lib/ebsco/eds/record.rb
CHANGED
@@ -421,6 +421,14 @@ module EBSCO
|
|
421
421
|
fulltext_links.first || {}
|
422
422
|
end
|
423
423
|
|
424
|
+
# add protocol if needed
|
425
|
+
def add_protocol(url)
|
426
|
+
unless url[/\Ahttp:\/\//] || url[/\Ahttps:\/\//]
|
427
|
+
url = "https://#{url}"
|
428
|
+
end
|
429
|
+
url
|
430
|
+
end
|
431
|
+
|
424
432
|
# All available fulltext links.
|
425
433
|
def fulltext_links
|
426
434
|
|
@@ -514,6 +522,7 @@ module EBSCO
|
|
514
522
|
if ft_customlinks.count > 0
|
515
523
|
ft_customlinks.each do |ft_customlink|
|
516
524
|
link_url = ft_customlink['Url']
|
525
|
+
link_url = add_protocol(link_url)
|
517
526
|
link_label = ft_customlink['Text']
|
518
527
|
link_icon = ft_customlink['Icon']
|
519
528
|
links.push({url: link_url, label: link_label, icon: link_icon, type: 'customlink-fulltext', expires: false})
|
@@ -530,6 +539,7 @@ module EBSCO
|
|
530
539
|
if other_customlinks.count > 0
|
531
540
|
other_customlinks.each do |other_customlink|
|
532
541
|
link_url = other_customlink['Url']
|
542
|
+
link_url = add_protocol(link_url)
|
533
543
|
link_label = other_customlink['Text']
|
534
544
|
link_icon = other_customlink['Icon']
|
535
545
|
links.push({url: link_url, label: link_label, icon: link_icon, type: 'customlink-other', expires: false})
|
@@ -947,11 +957,16 @@ module EBSCO
|
|
947
957
|
# need to double-unescape data with an ephtml section
|
948
958
|
if html =~ /<ephtml>/
|
949
959
|
html = CGI.unescapeHTML(html)
|
950
|
-
html = html.gsub
|
951
|
-
html = html.gsub
|
960
|
+
html = html.gsub(/\\"/, '"')
|
961
|
+
html = html.gsub(/\\n /, '')
|
952
962
|
end
|
953
963
|
|
954
|
-
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
|
+
|
955
970
|
end
|
956
971
|
|
957
972
|
# dynamically add item metadata as 'eds_extra_ItemNameOrLabel'
|
data/lib/ebsco/eds/results.rb
CHANGED
@@ -32,73 +32,81 @@ module EBSCO
|
|
32
32
|
def initialize(search_results, eds_config = {}, additional_limiters = {}, options = {})
|
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
|
+
else
|
107
|
+
# response isn't a hash (eg, html error page)
|
108
|
+
raise EBSCO::EDS::ApiError, 'EBSCO API error: Query failed.'
|
109
|
+
end
|
102
110
|
|
103
111
|
end
|
104
112
|
|
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') ?
|
@@ -332,21 +340,24 @@ module EBSCO
|
|
332
340
|
citation_exports_params = "?an=#{an}&dbid=#{dbid}&format=#{format}"
|
333
341
|
citation_exports_response = do_request(:get, path: @config[:citation_exports_url] + citation_exports_params)
|
334
342
|
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
|
-
|
343
|
+
rescue EBSCO::EDS::NotFound => e
|
344
|
+
custom_error_message = JSON.parse e.message.gsub('=>', ':')
|
345
|
+
# ErrorNumber 132 - Record not found
|
346
|
+
if custom_error_message['ErrorNumber'] == '132'
|
347
|
+
record_not_found = {"Format"=>format, "Label"=>"", "Data"=>"", "Error"=>"Record not found"}
|
348
|
+
EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: record_not_found, eds_config: @config)
|
349
|
+
end
|
350
|
+
rescue EBSCO::EDS::BadRequest => e
|
351
|
+
custom_error_message = JSON.parse e.message.gsub('=>', ':')
|
352
|
+
# ErrorNumber 112 - Invalid Argument Value
|
353
|
+
if custom_error_message['ErrorNumber'] == '112'
|
354
|
+
unknown_export_format = {"Format"=>format, "Label"=>"", "Data"=>"", "Error"=>"Invalid citation export format"}
|
355
|
+
EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: unknown_export_format, eds_config: @config)
|
356
|
+
else
|
357
|
+
unknown_error = {"Format"=>format, "Label"=>"", "Data"=>"", "Error"=>custom_error_message['ErrorDescription']}
|
358
|
+
EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: unknown_error, eds_config: @config)
|
359
|
+
end
|
348
360
|
end
|
349
|
-
end
|
350
361
|
end
|
351
362
|
|
352
363
|
# fetch the citation from the citation rest endpoint
|
@@ -355,6 +366,13 @@ module EBSCO
|
|
355
366
|
citation_styles_params = "?an=#{an}&dbid=#{dbid}&styles=#{format}"
|
356
367
|
citation_styles_response = do_request(:get, path: @config[:citation_styles_url] + citation_styles_params)
|
357
368
|
EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: citation_styles_response, eds_config: @config)
|
369
|
+
rescue EBSCO::EDS::NotFound => e
|
370
|
+
custom_error_message = JSON.parse e.message.gsub('=>', ':')
|
371
|
+
# ErrorNumber 132 - Record not found
|
372
|
+
if custom_error_message['ErrorNumber'] == '132'
|
373
|
+
record_not_found = {"Format"=>format, "Label"=>"", "Data"=>"", "Error"=>"Record not found"}
|
374
|
+
EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: record_not_found, eds_config: @config)
|
375
|
+
end
|
358
376
|
rescue EBSCO::EDS::BadRequest => e
|
359
377
|
custom_error_message = JSON.parse e.message.gsub('=>', ':')
|
360
378
|
unknown_error = {"Id"=>format, "Label"=>"", "Data"=>"", "Error"=>custom_error_message['ErrorDescription']}
|
@@ -847,6 +865,11 @@ module EBSCO
|
|
847
865
|
do_request(method, path: path, payload: payload, attempt: attempt+1)
|
848
866
|
# auth token invalid
|
849
867
|
when '104', '107'
|
868
|
+
# delete the auth cache to make sure we have an unexpired auth token
|
869
|
+
if @use_cache
|
870
|
+
puts 'DELETING AUTH CACHE...' if @debug
|
871
|
+
@cache_store.delete_matched('https://' + @api_hosts_list[@api_host_index] + @config[:uid_auth_url])
|
872
|
+
end
|
850
873
|
@auth_token = nil
|
851
874
|
@auth_token = create_auth_token
|
852
875
|
do_request(method, path: path, payload: payload, attempt: attempt+1)
|
@@ -1069,7 +1092,15 @@ module EBSCO
|
|
1069
1092
|
conn.headers['x-authenticationToken'] = @auth_token ? @auth_token : ''
|
1070
1093
|
conn.headers['User-Agent'] = @config[:user_agent]
|
1071
1094
|
conn.request :url_encoded
|
1072
|
-
conn.use :eds_caching_middleware,
|
1095
|
+
conn.use :eds_caching_middleware,
|
1096
|
+
store: @cache_store,
|
1097
|
+
auth_expire: @auth_expire,
|
1098
|
+
info_expire: @info_expire,
|
1099
|
+
search_expire: @search_expire,
|
1100
|
+
retrieve_expire: @retrieve_expire,
|
1101
|
+
export_format_expire: @export_format_expire,
|
1102
|
+
citation_styles_expire: @citation_styles_expire,
|
1103
|
+
logger: @debug ? logger : nil if @use_cache
|
1073
1104
|
conn.use :eds_exception_middleware
|
1074
1105
|
conn.response :json, content_type: /\bjson$/
|
1075
1106
|
conn.response :detailed_logger, logger if @debug
|
@@ -1109,7 +1140,15 @@ module EBSCO
|
|
1109
1140
|
conn.headers['x-authenticationToken'] = @auth_token ? @auth_token : ''
|
1110
1141
|
conn.headers['User-Agent'] = @config[:user_agent]
|
1111
1142
|
conn.request :url_encoded
|
1112
|
-
conn.use :eds_caching_middleware,
|
1143
|
+
conn.use :eds_caching_middleware,
|
1144
|
+
store: @cache_store,
|
1145
|
+
auth_expire: @auth_expire,
|
1146
|
+
info_expire: @info_expire,
|
1147
|
+
search_expire: @search_expire,
|
1148
|
+
retrieve_expire: @retrieve_expire,
|
1149
|
+
export_format_expire: @export_format_expire,
|
1150
|
+
citation_styles_expire: @citation_styles_expire,
|
1151
|
+
logger: @debug ? logger : nil if @use_cache
|
1113
1152
|
conn.use :eds_exception_middleware
|
1114
1153
|
conn.response :json, content_type: /\bjson$/
|
1115
1154
|
conn.response :detailed_logger, logger if @debug
|
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,7 +1,7 @@
|
|
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.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bill McKinney
|
@@ -9,7 +9,7 @@ authors:
|
|
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,44 +319,56 @@ 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
|
- bmckinney@ebsco.com, efrierson@ebsco.com
|
@@ -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'
|