ebsco-eds 0.3.6.pre → 0.3.7.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a58056a9b170977e96d0538c7c656e7d8809cb8d
4
- data.tar.gz: 51d4f45f67dfbf40efbf512298053351e6c5e06a
3
+ metadata.gz: 318f90b31dc58e67ca6276ab181e871ce2616378
4
+ data.tar.gz: 57bad731d288837bb5618e580007f097220a7e91
5
5
  SHA512:
6
- metadata.gz: 42ffb1d9f4516cd381f4f66e0ffc8c2e89249f9073e966fb3a5467aa26ff3b78e0566ebbcd7835087c98ba83d096e76ba129371b941c07e4a6e5fb4826e82631
7
- data.tar.gz: 199c710a0e5d9bf105a53ba800c606531e71e638a4461e71f5c7e138f0906a444102bd783b4acdbf6afde321b7178b4b0c9e13f9f5869ed28e0ac6cc87116eb9
6
+ metadata.gz: db4f93c0f4e5af5f125eae40e51e8ef1a869aa03c0a856bbe0b28b12900e53c5b998385a0fb316667204cab1adaa1788fc4461ba30a711620dbfc95e947762dc
7
+ data.tar.gz: b8c6a81124f2dada7caebf6a813e9b85f87e89dffc25acffd71975f070ee1999cce9ce7f85f875c7895ac474bea63b6aec513faa24cb697859453b9f37991ca0
data/.env.test CHANGED
@@ -1,7 +1,6 @@
1
1
  EDS_PROFILE=edsapi
2
- EDS_USER=stanford
3
- EDS_PASS=trial
2
+ EDS_USER=user
3
+ EDS_PASS=secret
4
4
  EDS_AUTH=user
5
5
  EDS_GUEST=n
6
- EDS_ORG=none
7
- EDS_DEBUG=false
6
+ EDS_ORG=none
@@ -17,7 +17,7 @@ module EBSCO
17
17
  :auth => 'user',
18
18
  :auth_token => '',
19
19
  :session_token => '',
20
- :eds_api_base => 'https://eds-api-b.ebscohost.com',
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',
@@ -43,5 +43,8 @@ module EBSCO
43
43
  # Raised when EDS returns the HTTP status code 503
44
44
  class ServiceUnavailable < Error; end
45
45
 
46
+ # raised when connection fails
47
+ class ConnectionFailed < Error; end
48
+
46
49
  end
47
50
  end
@@ -220,7 +220,7 @@ module EBSCO
220
220
  end
221
221
 
222
222
  def eds_sanitize(str)
223
- pattern = /(\'|\"|\*|\/|\\|\)|\$|\+|\(|\^|\?|\!|\~|\`|\:)/
223
+ pattern = /([)(:,])/
224
224
  str = str.gsub(pattern){ |match| '\\' + match }
225
225
  str
226
226
  end
@@ -70,7 +70,8 @@ module EBSCO
70
70
  @auth_token = ''
71
71
  @config = {}
72
72
  @guest = true
73
- @api_base = ''
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? 'EDS_API_BASE') ? @api_base = ENV['EDS_API_BASE'] : @api_base = @config[:eds_api_base]
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: @api_base) do |conn|
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: @api_base) do |conn|
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
@@ -1,5 +1,5 @@
1
1
  module EBSCO
2
2
  module EDS
3
- VERSION = '0.3.6.pre'
3
+ VERSION = '0.3.7.pre'
4
4
  end
5
5
  end
@@ -19,19 +19,7 @@ module Faraday
19
19
 
20
20
  initialize_store
21
21
 
22
- eds_config = EBSCO::EDS::Configuration.new
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
- puts "Cache WRITE: #{key(env)}"
49
+ info "Cache WRITE: #{key(env)}"
63
50
  custom_expires_in = @expires_in
64
51
  uri = env.url
65
52
 
66
- if uri == @auth_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 == @info_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.start_with?(@search_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.start_with?(@retrieve_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
- if uri == @auth_uri || uri == @info_uri ||
92
- uri.request_uri.start_with?(@search_uri.request_uri) ||
93
- uri.request_uri.start_with?(@retrieve_uri.request_uri)
94
- if !env.body.nil? && env.body.include?('"jump_request"')
95
- puts "NOT CACHEABLE URI (jump_request): #{uri}"
96
- false
97
- else
98
- puts "CACHEABLE URI: #{uri}"
99
- true
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
- else
102
- puts "NOT CACHEABLE URI: #{uri}"
103
- false
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
- puts "Cache HIT: #{key(env)}"
100
+ info "Cache HIT: #{key(env)}"
115
101
  else
116
- puts "Cache MISS: #{key(env)}"
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
- @app.call(env).on_complete do |response|
13
- case response.status
14
- when 200
15
- when 400
16
- raise EBSCO::EDS::BadRequest.new(error_message(response))
17
- # when 401
18
- # raise EBSCO::EDS::Unauthorized.new
19
- # when 403
20
- # raise EBSCO::EDS::Forbidden.new
21
- # when 404
22
- # raise EBSCO::EDS::NotFound.new
23
- # when 429
24
- # raise EBSCO::EDS::TooManyRequests.new
25
- # when 500
26
- # raise EBSCO::EDS::InternalServerError.new
27
- # when 503
28
- # raise EBSCO::EDS::ServiceUnavailable.new
29
- else
30
- raise EBSCO::EDS::BadRequest.new(error_message(response))
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.6.pre
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-28 00:00:00.000000000 Z
12
+ date: 2017-08-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday