ebsco-eds 0.3.6.pre → 0.3.7.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.env.test +3 -4
- data/lib/ebsco/eds/configuration.rb +1 -1
- data/lib/ebsco/eds/error.rb +3 -0
- data/lib/ebsco/eds/options.rb +1 -1
- data/lib/ebsco/eds/session.rb +20 -10
- data/lib/ebsco/eds/version.rb +1 -1
- data/lib/faraday/eds_caching_middleware.rb +20 -34
- data/lib/faraday/eds_exception_middleware.rb +23 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 318f90b31dc58e67ca6276ab181e871ce2616378
|
4
|
+
data.tar.gz: 57bad731d288837bb5618e580007f097220a7e91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db4f93c0f4e5af5f125eae40e51e8ef1a869aa03c0a856bbe0b28b12900e53c5b998385a0fb316667204cab1adaa1788fc4461ba30a711620dbfc95e947762dc
|
7
|
+
data.tar.gz: b8c6a81124f2dada7caebf6a813e9b85f87e89dffc25acffd71975f070ee1999cce9ce7f85f875c7895ac474bea63b6aec513faa24cb697859453b9f37991ca0
|
data/.env.test
CHANGED
@@ -17,7 +17,7 @@ module EBSCO
|
|
17
17
|
:auth => 'user',
|
18
18
|
:auth_token => '',
|
19
19
|
:session_token => '',
|
20
|
-
:
|
20
|
+
:api_hosts_list => ['eds-api.ebscohost.com'],
|
21
21
|
:uid_auth_url => '/authservice/rest/uidauth',
|
22
22
|
:ip_auth_url => '/authservice/rest/ipauth',
|
23
23
|
:create_session_url => '/edsapi/rest/CreateSession',
|
data/lib/ebsco/eds/error.rb
CHANGED
data/lib/ebsco/eds/options.rb
CHANGED
data/lib/ebsco/eds/session.rb
CHANGED
@@ -70,7 +70,8 @@ module EBSCO
|
|
70
70
|
@auth_token = ''
|
71
71
|
@config = {}
|
72
72
|
@guest = true
|
73
|
-
@
|
73
|
+
@api_hosts_list = ''
|
74
|
+
@api_host_index = 0
|
74
75
|
|
75
76
|
eds_config = EBSCO::EDS::Configuration.new
|
76
77
|
if options[:config]
|
@@ -130,7 +131,7 @@ module EBSCO
|
|
130
131
|
end :
|
131
132
|
@debug = @config[:debug]
|
132
133
|
|
133
|
-
(ENV.has_key? '
|
134
|
+
(ENV.has_key? 'EDS_HOSTS') ? @api_hosts_list = ENV['EDS_HOSTS'].split(',') : @api_hosts_list = @config[:api_hosts_list]
|
134
135
|
|
135
136
|
# use cache for auth token, info, search and retrieve calls?
|
136
137
|
if @use_cache
|
@@ -710,7 +711,19 @@ module EBSCO
|
|
710
711
|
end
|
711
712
|
resp.body
|
712
713
|
rescue Error => e
|
714
|
+
|
715
|
+
# try alternate EDS hosts
|
716
|
+
if e.is_a?(EBSCO::EDS::InternalServerError) || e.is_a?(EBSCO::EDS::ServiceUnavailable) || e.is_a?(EBSCO::EDS::ConnectionFailed)
|
717
|
+
if @api_hosts_list.length > @api_host_index+1
|
718
|
+
@api_host_index = @api_host_index+1
|
719
|
+
do_request(method, path: path, payload: payload, attempt: attempt+1)
|
720
|
+
else
|
721
|
+
raise EBSCO::EDS::ApiError, 'EBSCO API error: Unable to establish a connection to any EDS host.'
|
722
|
+
end
|
723
|
+
end
|
724
|
+
|
713
725
|
if e.respond_to? 'fault'
|
726
|
+
|
714
727
|
error_code = e.fault[:error_body]['ErrorNumber'] || e.fault[:error_body]['ErrorCode']
|
715
728
|
unless error_code.nil?
|
716
729
|
case error_code
|
@@ -727,8 +740,6 @@ module EBSCO
|
|
727
740
|
# trying to paginate in results list beyond 250 results
|
728
741
|
when '138'
|
729
742
|
|
730
|
-
puts 'JUMP ERROR: ' + e.inspect
|
731
|
-
|
732
743
|
is_jump_retry = false
|
733
744
|
is_orig_retry = false
|
734
745
|
|
@@ -828,9 +839,9 @@ module EBSCO
|
|
828
839
|
begin
|
829
840
|
if @debug
|
830
841
|
if payload.instance_variable_defined?(:@Actions)
|
831
|
-
puts 'JUMP ACTION: ' + payload.Actions.inspect
|
842
|
+
puts 'JUMP ACTION: ' + payload.Actions.inspect if @debug
|
832
843
|
end
|
833
|
-
puts 'JUMP ATTEMPT: ' + attempt.to_s
|
844
|
+
puts 'JUMP ATTEMPT: ' + attempt.to_s if @debug
|
834
845
|
end
|
835
846
|
# turn off caching
|
836
847
|
resp = jump_connection.send(method) do |req|
|
@@ -908,7 +919,7 @@ module EBSCO
|
|
908
919
|
def connection
|
909
920
|
logger = Logger.new(@config[:log])
|
910
921
|
logger.level = Logger.const_get(@config[:log_level])
|
911
|
-
Faraday.new(url: @
|
922
|
+
Faraday.new(url: 'https://' + @api_hosts_list[@api_host_index]) do |conn|
|
912
923
|
conn.headers['Content-Type'] = 'application/json;charset=UTF-8'
|
913
924
|
conn.headers['Accept'] = 'application/json'
|
914
925
|
conn.headers['x-sessionToken'] = @session_token ? @session_token : ''
|
@@ -929,7 +940,7 @@ module EBSCO
|
|
929
940
|
def jump_connection
|
930
941
|
logger = Logger.new(@config[:log])
|
931
942
|
logger.level = Logger.const_get(@config[:log_level])
|
932
|
-
Faraday.new(url: @
|
943
|
+
Faraday.new(url: 'https://' + @api_hosts_list[@api_host_index]) do |conn|
|
933
944
|
conn.headers['Content-Type'] = 'application/json;charset=UTF-8'
|
934
945
|
conn.headers['Accept'] = 'application/json'
|
935
946
|
conn.headers['x-sessionToken'] = @session_token ? @session_token : ''
|
@@ -1021,7 +1032,7 @@ module EBSCO
|
|
1021
1032
|
end
|
1022
1033
|
|
1023
1034
|
def eds_sanitize(str)
|
1024
|
-
pattern = /(
|
1035
|
+
pattern = /([)(:,])/
|
1025
1036
|
str = str.gsub(pattern){ |match| '\\' + match }
|
1026
1037
|
str
|
1027
1038
|
end
|
@@ -1031,7 +1042,6 @@ module EBSCO
|
|
1031
1042
|
jump_incr = 250/search_options.RetrievalCriteria.ResultsPerPage.to_i
|
1032
1043
|
attempts = dest_page/jump_incr
|
1033
1044
|
jump_pages = []
|
1034
|
-
puts 'CURRENT PAGE: ' + @current_page.inspect
|
1035
1045
|
(1..attempts).to_a.each do |n|
|
1036
1046
|
jump_pages.push(jump_incr*n)
|
1037
1047
|
end
|
data/lib/ebsco/eds/version.rb
CHANGED
@@ -19,19 +19,7 @@ module Faraday
|
|
19
19
|
|
20
20
|
initialize_store
|
21
21
|
|
22
|
-
|
23
|
-
if options[:config]
|
24
|
-
@config = eds_config.configure_with(options[:config])
|
25
|
-
@config = eds_config.configure if @config.nil?
|
26
|
-
else
|
27
|
-
@config = eds_config.configure(options)
|
28
|
-
end
|
29
|
-
(ENV.has_key? 'EDS_API_BASE') ? @api_base = ENV['EDS_API_BASE'] : @api_base = @config[:eds_api_base]
|
30
|
-
|
31
|
-
@info_uri = URI.parse(@api_base + '/edsapi/rest/Info')
|
32
|
-
@auth_uri = URI.parse(@api_base + '/authservice/rest/uidauth')
|
33
|
-
@search_uri = URI.parse(@api_base + '/edsapi/rest/Search?')
|
34
|
-
@retrieve_uri = URI.parse(@api_base + '/edsapi/rest/Retrieve?')
|
22
|
+
@cacheable_paths = %w(/edsapi/rest/Info /authservice/rest/uidauth /authservice/rest/uidauth /edsapi/rest/Retrieve? /edsapi/rest/Search?)
|
35
23
|
|
36
24
|
end
|
37
25
|
|
@@ -56,29 +44,28 @@ module Faraday
|
|
56
44
|
end
|
57
45
|
|
58
46
|
def cache_response(env)
|
59
|
-
#puts 'ENV: ' + env.inspect
|
60
47
|
return unless cacheable?(env) && !env.request_headers['x-faraday-eds-cache']
|
61
48
|
|
62
|
-
|
49
|
+
info "Cache WRITE: #{key(env)}"
|
63
50
|
custom_expires_in = @expires_in
|
64
51
|
uri = env.url
|
65
52
|
|
66
|
-
if uri
|
53
|
+
if uri.request_uri.include?('/authservice/rest/uidauth')
|
67
54
|
custom_expires_in = 1800 # 30 minutes
|
68
55
|
info "#{uri} - Setting custom expires: #{custom_expires_in}"
|
69
56
|
end
|
70
57
|
|
71
|
-
if uri
|
58
|
+
if uri.request_uri.include?('/edsapi/rest/Info')
|
72
59
|
custom_expires_in = 86400 # 24 hours
|
73
60
|
info "#{uri} - Setting custom expires: #{custom_expires_in}"
|
74
61
|
end
|
75
62
|
|
76
|
-
if uri.request_uri.
|
63
|
+
if uri.request_uri.include?('/edsapi/rest/Search?')
|
77
64
|
custom_expires_in = 1800 # 30 minutes
|
78
65
|
info "#{uri} - Setting custom expires: #{custom_expires_in}"
|
79
66
|
end
|
80
67
|
|
81
|
-
if uri.request_uri.
|
68
|
+
if uri.request_uri.include?('/edsapi/rest/Retrieve?')
|
82
69
|
custom_expires_in = 1800 # 30 minutes
|
83
70
|
info "#{uri} - Setting custom expires: #{custom_expires_in}"
|
84
71
|
end
|
@@ -88,20 +75,19 @@ module Faraday
|
|
88
75
|
|
89
76
|
def cacheable?(env)
|
90
77
|
uri = env.url
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
78
|
+
@cacheable_paths.any? { |path|
|
79
|
+
if uri.request_uri.include?(path)
|
80
|
+
if !env.body.nil? && env.body.include?('"jump_request"')
|
81
|
+
info "NOT CACHEABLE URI (jump_request): #{uri}"
|
82
|
+
return false
|
83
|
+
else
|
84
|
+
info "CACHEABLE URI: #{uri}"
|
85
|
+
return true
|
86
|
+
end
|
100
87
|
end
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
88
|
+
}
|
89
|
+
info "NOT CACHEABLE URI: #{uri}"
|
90
|
+
false
|
105
91
|
end
|
106
92
|
|
107
93
|
def cached_response(env)
|
@@ -111,9 +97,9 @@ module Faraday
|
|
111
97
|
end
|
112
98
|
|
113
99
|
if response_env
|
114
|
-
|
100
|
+
info "Cache HIT: #{key(env)}"
|
115
101
|
else
|
116
|
-
|
102
|
+
info "Cache MISS: #{key(env)}"
|
117
103
|
end
|
118
104
|
response_env
|
119
105
|
end
|
@@ -9,26 +9,30 @@ module Faraday
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def call(env)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
12
|
+
begin
|
13
|
+
@app.call(env).on_complete do |response|
|
14
|
+
case response.status
|
15
|
+
when 200
|
16
|
+
when 400
|
17
|
+
raise EBSCO::EDS::BadRequest.new(error_message(response))
|
18
|
+
# when 401
|
19
|
+
# raise EBSCO::EDS::Unauthorized.new
|
20
|
+
# when 403
|
21
|
+
# raise EBSCO::EDS::Forbidden.new
|
22
|
+
# when 404
|
23
|
+
# raise EBSCO::EDS::NotFound.new
|
24
|
+
# when 429
|
25
|
+
# raise EBSCO::EDS::TooManyRequests.new
|
26
|
+
when 500
|
27
|
+
raise EBSCO::EDS::InternalServerError.new
|
28
|
+
when 503
|
29
|
+
raise EBSCO::EDS::ServiceUnavailable.new
|
30
|
+
else
|
31
|
+
raise EBSCO::EDS::BadRequest.new(error_message(response))
|
32
|
+
end
|
31
33
|
end
|
34
|
+
rescue Faraday::ConnectionFailed
|
35
|
+
raise EBSCO::EDS::ConnectionFailed.new
|
32
36
|
end
|
33
37
|
end
|
34
38
|
|
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: 0.3.
|
4
|
+
version: 0.3.7.pre
|
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: 2017-08-
|
12
|
+
date: 2017-08-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|