ebsco-eds 0.0.9.pre → 0.1.0.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: f12e4b479c74c3d70975e92889f809890990e32d
4
- data.tar.gz: 04c6e2c2635d88502436681c27507d4bd2d50ce6
3
+ metadata.gz: 8bf7451cbf86071a743681b657692b002f44f390
4
+ data.tar.gz: 0730b334a687c1af3da7452405e882324475c03c
5
5
  SHA512:
6
- metadata.gz: 8007fbbc454f4ec46618bfafe929b2341fde6f2e31a9a8e4e7133e635b3712537624acad98d4ea98ae1cf7970a219b77787937b54a91235bcfce23931d1690bf
7
- data.tar.gz: 6821b1297656a67a2568a8874c78098cffba292f4460caf83843c6ecafa6ace5d1f9f096f8fb649d2addd0de4c0cd8d02d2a7848600459fdbd567e1694d39afe
6
+ metadata.gz: eeed69e878b466f93c3d1ea562a826f77fef9305a0e9b10f1925342e5ab9917725ea140e50db7b5d2231ab84f409186267d23ee114485a1c2978246ca62f28a5
7
+ data.tar.gz: cf5033d8a83440de5aab54af4b5a440c438d0ddd68cc3a7a4653670257b18a30281d23de14d4d8f1fd15c2f3d330acc52c242bd631eb05fa9e7cd58b629f9a2b
data/lib/ebsco/eds.rb CHANGED
@@ -8,19 +8,7 @@ require 'ebsco/eds/error'
8
8
  module EBSCO
9
9
 
10
10
  module EDS
11
- EDS_API_BASE = 'https://eds-api.ebscohost.com'
12
- UID_AUTH_URL = '/authservice/rest/uidauth'
13
- IP_AUTH_URL = '/authservice/rest/ipauth'
14
- CREATE_SESSION_URL = '/edsapi/rest/CreateSession'
15
- END_SESSION_URL = '/edsapi/rest/EndSession'
16
- INFO_URL = '/edsapi/rest/Info'
17
- SEARCH_URL = '/edsapi/rest/Search'
18
- RETRIEVE_URL = '/edsapi/rest/Retrieve'
19
- USER_AGENT = 'EBSCO EDS GEM v0.0.1'
20
- INTERFACE_ID = 'EBSCO EDS GEM v0.0.1'
21
- LOG = 'faraday.log'
22
- MAX_ATTEMPTS = 2
23
- MAX_RESULTS_PER_PAGE = 100
11
+
24
12
  end
25
13
 
26
14
  end
@@ -0,0 +1,63 @@
1
+ require 'yaml'
2
+
3
+ module EBSCO
4
+
5
+ module EDS
6
+
7
+ class Configuration
8
+
9
+ attr_reader :valid_config_keys
10
+
11
+ def initialize
12
+ # Configuration defaults
13
+ @config = {
14
+ :debug => false,
15
+ :guest => true,
16
+ :org => '',
17
+ :auth => 'user',
18
+ :auth_token => '',
19
+ :session_token => '',
20
+ :eds_api_base => 'https://eds-api.ebscohost.com',
21
+ :uid_auth_url => '/authservice/rest/uidauth',
22
+ :ip_auth_url => '/authservice/rest/ipauth',
23
+ :create_session_url => '/edsapi/rest/CreateSession',
24
+ :end_session_url => '/edsapi/rest/EndSession',
25
+ :info_url => '/edsapi/rest/Info',
26
+ :search_url => '/edsapi/rest/Search',
27
+ :retrieve_url => '/edsapi/rest/Retrieve',
28
+ :user_agent => 'EBSCO EDS GEM v0.0.1',
29
+ :interface_id => 'EBSCO EDS GEM v0.0.1',
30
+ :log => 'faraday.log',
31
+ :max_attempts => 2,
32
+ :max_results_per_page => 100,
33
+ :ebook_preferred_format => 'ebook-pdf',
34
+ :use_cache => true,
35
+ :eds_cache_dir => ENV['TMPDIR'] || '/tmp'
36
+ }
37
+ @valid_config_keys = @config.keys
38
+ end
39
+
40
+ def configure(opts = {})
41
+ opts.each do |k, v|
42
+ @config[k] = v if @valid_config_keys.include? k
43
+ end
44
+ @config
45
+ end
46
+
47
+ def configure_with(file)
48
+ begin
49
+ config = YAML.load_file(file ||= 'eds.yaml')
50
+ rescue Errno::ENOENT
51
+ #puts 'YAML configuration file couldn\'t be found. Using defaults.'
52
+ return
53
+ rescue Psych::SyntaxError
54
+ #puts 'YAML configuration file contains invalid syntax. Using defaults'
55
+ return
56
+ end
57
+ @config[:file] = file
58
+ configure(config)
59
+ end
60
+ end
61
+
62
+ end
63
+ end
@@ -7,7 +7,8 @@ module EBSCO
7
7
 
8
8
  attr_accessor :available_search_criteria, :view_result_settings, :application_settings, :api_settings
9
9
 
10
- def initialize(info)
10
+ def initialize(info, config = {})
11
+ @results_per_page = config[:max_results_per_page] ? config[:max_results_per_page] : 100
11
12
  @available_search_criteria = info['AvailableSearchCriteria']
12
13
  @view_result_settings = info['ViewResultSettings']
13
14
  @application_settings = info['ApplicationSettings']
@@ -135,7 +136,7 @@ module EBSCO
135
136
  end
136
137
 
137
138
  def max_results_per_page
138
- MAX_RESULTS_PER_PAGE
139
+ @results_per_page
139
140
  end
140
141
 
141
142
  def available_result_list_views
@@ -82,6 +82,7 @@ module EBSCO
82
82
  if value.has_key?('content_provider_facet')
83
83
  subj_list = value['content_provider_facet']
84
84
  subj_list.each do |item|
85
+ item = eds_sanitize item
85
86
  @Actions.push "addfacetfilter(ContentProvider:#{item})"
86
87
  end
87
88
  end
@@ -89,6 +90,7 @@ module EBSCO
89
90
  if value.has_key?('library_location_facet')
90
91
  subj_list = value['library_location_facet']
91
92
  subj_list.each do |item|
93
+ item = eds_sanitize item
92
94
  @Actions.push "addfacetfilter(LocationLibrary:#{item})"
93
95
  end
94
96
  end
@@ -157,7 +159,13 @@ module EBSCO
157
159
  #end
158
160
  end
159
161
  end
160
-
162
+
163
+ def eds_sanitize(str)
164
+ pattern = /(\'|\"|\.|\*|\/|\-|\\|\)|\$|\+|\(|\^|\?|\!|\~|\`)/
165
+ str = str.gsub(pattern){ |match| '\\' + match }
166
+ str
167
+ end
168
+
161
169
  # def is_valid_action(action, info)
162
170
  # # actions in info that require an enumerated value (e.g., addlimiter(LA99:Bulgarian))
163
171
  # _available_actions = info.available_actions
@@ -40,14 +40,13 @@ module EBSCO
40
40
  .fetch('IsPartOfRelationships', {})[0]
41
41
 
42
42
  @bibtex = BibTeX::Entry.new
43
- @bibtex = retrieve_bibtex
44
43
  end
45
44
 
46
45
  # \Options hash containing accession number and database ID. This can be passed to the retrieve method.
47
46
  def retrieve_options
48
47
  options = {}
49
- options['an'] = self.accession_number
50
- options['dbid'] = self.database_id
48
+ options['an'] = accession_number
49
+ options['dbid'] = database_id
51
50
  options
52
51
  end
53
52
 
@@ -90,6 +89,7 @@ module EBSCO
90
89
  # The source title (e.g., Journal)
91
90
  def source_title
92
91
  _retval = bib_source_title || get_item_data_by_name('TitleSource')
92
+ _reval = nil? if _retval == title # suppress if it's identical to title
93
93
  _retval.nil?? nil : CGI.unescapeHTML(_retval)
94
94
  end
95
95
 
@@ -316,12 +316,12 @@ module EBSCO
316
316
 
317
317
  # A list of all available links.
318
318
  def all_links
319
- self.fulltext_links + self.non_fulltext_links
319
+ fulltext_links + non_fulltext_links
320
320
  end
321
321
 
322
322
  # The first fulltext link.
323
323
  def fulltext_link
324
- self.fulltext_links.first || {}
324
+ fulltext_links.first || {}
325
325
  end
326
326
 
327
327
  # All available fulltext links.
@@ -341,13 +341,14 @@ module EBSCO
341
341
  end
342
342
  end
343
343
 
344
- htmlfulltextcheck = @record.fetch('FullText',{}).fetch('Text',{}).fetch('Availability',{})
345
- if htmlfulltextcheck == '1'
346
- link_url = 'detail'
347
- link_label = 'Full Text in Browser'
348
- link_icon = 'Full Text in Browser Icon'
349
- links.push({url: link_url, label: link_label, icon: link_icon, type: 'html'})
350
- end
344
+ # commenting out for now, not sure how 'detail' urls are useful in a blacklight context?
345
+ # htmlfulltextcheck = @record.fetch('FullText',{}).fetch('Text',{}).fetch('Availability',{})
346
+ # if htmlfulltextcheck == '1'
347
+ # link_url = 'detail'
348
+ # link_label = 'Full Text in Browser'
349
+ # link_icon = 'Full Text in Browser Icon'
350
+ # links.push({url: link_url, label: link_label, icon: link_icon, type: 'html'})
351
+ # end
351
352
 
352
353
  if ebscolinks.count > 0
353
354
  ebscolinks.each do |ebscolink|
@@ -374,15 +375,19 @@ module EBSCO
374
375
  items = @record.fetch('Items',{})
375
376
  if items.count > 0
376
377
  items.each do |item|
377
- if item['Group'] == 'Url'
378
+ if item['Group'] == 'URL'
378
379
  if item['Data'].include? 'linkTerm="'
379
380
  link_start = item['Data'].index('linkTerm="')+15
380
381
  link_url = item['Data'][link_start..-1]
381
382
  link_end = link_url.index('"')-1
382
383
  link_url = link_url[0..link_end]
383
- link_label_start = item['Data'].index('link>')+8
384
- link_label = item['Data'][link_label_start..-1]
385
- link_label = link_label.strip
384
+ if item['Label']
385
+ link_label = item['Label']
386
+ else
387
+ link_label_start = item['Data'].index('link>')+8
388
+ link_label = item['Data'][link_label_start..-1]
389
+ link_label = link_label.strip
390
+ end
386
391
  else
387
392
  link_url = item['Data']
388
393
  link_label = item['Label']
@@ -436,85 +441,6 @@ module EBSCO
436
441
  #:nodoc: all
437
442
  # No need to document methods below
438
443
 
439
- # Experimental bibtex support.
440
- def retrieve_bibtex
441
-
442
- @bibtex.key = accession_number
443
- @bibtex.title = title.gsub('<highlight>', '').gsub('</highlight>', '')
444
- if self.bib_authors_list.length > 0
445
- @bibtex.author = self.bib_authors_list.join(' and ').chomp
446
- end
447
- @bibtex.year = self.publication_year.to_i
448
-
449
- # bibtex type
450
- _type = self.publication_type
451
- case _type
452
- when 'Academic Journal'
453
- @bibtex.type = :article
454
- @bibtex.journal = source_title
455
- unless issue.nil?
456
- @bibtex.issue = issue
457
- end
458
- unless volume.nil?
459
- @bibtex.number = volume
460
- end
461
- if page_start && page_count
462
- @bibtex.pages = page_start + '-' + (page_start.to_i + page_count.to_i-1).to_s
463
- end
464
- if self.bib_publication_month
465
- @bibtex.month = self.bib_publication_month.to_i
466
- end
467
- if doi
468
- @bibtex.doi = doi
469
- @bibtex.url = 'https://doi.org/' + doi
470
- end
471
- when 'Conference'
472
- @bibtex.type = :conference
473
- @bibtex.booktitle = self.source_title
474
- if self.issue
475
- @bibtex.issue = self.issue
476
- end
477
- if self.volume
478
- @bibtex.number = self.volume
479
- end
480
- if self.page_start && self.page_count
481
- @bibtex.pages = self.page_start + '-' + (self.page_start.to_i + self.page_count.to_i-1).to_s
482
- end
483
- if self.bib_publication_month
484
- @bibtex.month = self.bib_publication_month.to_i
485
- end
486
- if self.publisher_info
487
- @bibtex.publisher = self.publisher_info
488
- end
489
- if self.series
490
- @bibtex.series = self.series
491
- end
492
- when 'Book', 'eBook'
493
- @bibtex.type = :book
494
- if self.publisher_info
495
- @bibtex.publisher = self.publisher_info
496
- end
497
- if self.series
498
- @bibtex.series = self.series
499
- end
500
- if self.bib_publication_month
501
- @bibtex.month = self.bib_publication_month.to_i
502
- end
503
- if isbns
504
- @bibtex.isbn = self.isbns.first
505
- end
506
- else
507
- @bibtex.type = :other
508
- end
509
- @bibtex
510
- end
511
-
512
- def bibtex_bibliography
513
- bib = BibTeX::Bibliography.new
514
- bib << @bibtex
515
- bib
516
- end
517
-
518
444
  # ====================================================================================
519
445
  # HEADER: DbId, DbLabel, An, PubType, PubTypeId, AccessLevel
520
446
  # ====================================================================================
@@ -825,14 +751,98 @@ module EBSCO
825
751
  end
826
752
  end
827
753
 
754
+
755
+ # Experimental bibtex support.
756
+ def retrieve_bibtex
757
+
758
+ @bibtex.key = accession_number
759
+ @bibtex.title = title.gsub('<highlight>', '').gsub('</highlight>', '')
760
+ if bib_authors_list.length > 0
761
+ @bibtex.author = bib_authors_list.join(' and ').chomp
762
+ end
763
+ @bibtex.year = publication_year.to_i
764
+
765
+ # bibtex type
766
+ _type = publication_type
767
+ case _type
768
+ when 'Academic Journal', 'Reference'
769
+ @bibtex.type = :article
770
+ @bibtex.journal = source_title
771
+ unless issue.nil?
772
+ @bibtex.issue = issue
773
+ end
774
+ unless volume.nil?
775
+ @bibtex.number = volume
776
+ end
777
+ if page_start && page_count
778
+ @bibtex.pages = page_start + '-' + (page_start.to_i + page_count.to_i-1).to_s
779
+ end
780
+ if bib_publication_month
781
+ @bibtex.month = bib_publication_month.to_i
782
+ end
783
+ if doi
784
+ @bibtex.doi = doi
785
+ @bibtex.url = 'https://doi.org/' + doi
786
+ end
787
+ when 'Conference'
788
+ @bibtex.type = :conference
789
+ @bibtex.booktitle = source_title
790
+ if issue
791
+ @bibtex.issue = issue
792
+ end
793
+ if volume
794
+ @bibtex.number = volume
795
+ end
796
+ if page_start && page_count
797
+ @bibtex.pages = page_start + '-' + (page_start.to_i + page_count.to_i-1).to_s
798
+ end
799
+ if bib_publication_month
800
+ @bibtex.month = bib_publication_month.to_i
801
+ end
802
+ if publisher_info
803
+ @bibtex.publisher = publisher_info
804
+ end
805
+ if series
806
+ @bibtex.series = series
807
+ end
808
+ when 'Book', 'eBook'
809
+ @bibtex.type = :book
810
+ if publisher_info
811
+ @bibtex.publisher = publisher_info
812
+ end
813
+ if series
814
+ @bibtex.series = series
815
+ end
816
+ if bib_publication_month
817
+ @bibtex.month = bib_publication_month.to_i
818
+ end
819
+ if isbns
820
+ @bibtex.isbn = isbns.first
821
+ end
822
+ else
823
+ @bibtex.type = :other
824
+ end
825
+ @bibtex
826
+ end
827
+
828
+ ##
829
+ # wrap bibtex entry in a bibliography so that it can be transformed into citations using citeproc
830
+ def bibtex_bibliography
831
+ bib = BibTeX::Bibliography.new
832
+ bib << @bibtex
833
+ bib
834
+ end
835
+
828
836
  # this is used to generate solr fields
829
- def to_hash
837
+ def to_hash(type = 'compact')
830
838
  hash = {}
839
+
840
+ # information typically required by all views
831
841
  if database_id && accession_number
832
842
  safe_an = accession_number.gsub(/\./,'_')
833
843
  hash['id'] = database_id + '__' + safe_an
834
844
  end
835
- if !title.nil?
845
+ unless title.nil?
836
846
  hash['title_display'] = title.gsub('<highlight>', '').gsub('</highlight>', '')
837
847
  end
838
848
  if source_title
@@ -866,22 +876,36 @@ module EBSCO
866
876
  if cover_medium_url
867
877
  hash['cover_medium_url'] = cover_medium_url
868
878
  end
869
- if all_links
870
- hash['links'] = all_links
879
+ # generate bibtex entry if it hasn't been done already
880
+ if @bibtex.key == 'unknown-a'
881
+ @bibtex = retrieve_bibtex
871
882
  end
872
883
  unless @bibtex.has_type?(:other)
873
884
  hash['citation_apa'] = citation('apa').first.to_s
874
885
  hash['citation_mla'] = citation('modern-language-association').first.to_s
875
886
  hash['citation_chicago'] = citation('chicago-author-date').first.to_s
876
887
  end
877
- if doi
878
- hash['doi'] = doi
888
+
889
+ # extra information typically required by detailed item views
890
+ if type == 'verbose'
891
+ if all_links
892
+ hash['links'] = all_links
893
+ end
894
+ if doi
895
+ hash['doi'] = doi
896
+ end
897
+ if html_fulltext
898
+ hash['html_fulltext'] = html_fulltext
899
+ end
879
900
  end
901
+
880
902
  hash
881
903
  end
882
904
 
883
905
  def to_solr
884
906
  # solr response
907
+ item_hash = to_hash 'verbose'
908
+ solr_response =
885
909
  {
886
910
  'responseHeader' => {
887
911
  'status' => 0
@@ -889,12 +913,18 @@ module EBSCO
889
913
  'response' => {
890
914
  'numFound' => 1,
891
915
  'start' => 0,
892
- 'docs' => [to_hash]
916
+ 'docs' => [item_hash]
893
917
  }
894
918
  }
919
+ # puts 'SOLR RESPONSE: ' + solr_response.inspect
920
+ solr_response
895
921
  end
896
922
 
897
923
  def citation(style = 'apa')
924
+ # generate bibtex entry if it hasn't been done already
925
+ if @bibtex.key == 'unknown-a'
926
+ @bibtex = retrieve_bibtex
927
+ end
898
928
  # TODO: catch CSL::ParseError when style can't be found
899
929
  CSL::Style.root = File.join(__dir__, 'csl/styles')
900
930
  cp = CiteProc::Processor.new style: style, format: 'text'
@@ -7,6 +7,7 @@ require 'logger'
7
7
  require 'json'
8
8
  require 'active_support'
9
9
  require 'faraday_eds_middleware'
10
+ require 'ebsco/eds/configuration'
10
11
 
11
12
  module EBSCO
12
13
 
@@ -23,6 +24,8 @@ module EBSCO
23
24
  attr_accessor :auth_token # :nodoc:
24
25
  # The session token. This is passed along in the x-sessionToken HTTP header.
25
26
  attr_accessor :session_token # :nodoc:
27
+ # The session configuration.
28
+ attr_reader :config
26
29
 
27
30
  # Creates a new session.
28
31
  #
@@ -59,14 +62,20 @@ module EBSCO
59
62
  # }
60
63
  def initialize(options = {})
61
64
 
62
-
63
- cache_dir = File.join(ENV['TMPDIR'] || '/tmp', 'faraday_eds_cache')
64
- @cache_store = ActiveSupport::Cache::FileStore.new cache_dir
65
-
66
65
  @session_token = ''
67
66
  @auth_token = ''
68
- @guest = 'y'
67
+ @config = {}
69
68
 
69
+ eds_config = EBSCO::EDS::Configuration.new
70
+ if options[:config]
71
+ @config = eds_config.configure_with(options[:config])
72
+ # return default if there is some problem with the yaml file (bad syntax, not found, etc.)
73
+ @config = eds_config.configure if @config.nil?
74
+ else
75
+ @config = eds_config.configure(options)
76
+ end
77
+
78
+ # these properties aren't in the config
70
79
  if options.has_key? :user
71
80
  @user = options[:user]
72
81
  elsif ENV.has_key? 'EDS_USER'
@@ -86,27 +95,18 @@ module EBSCO
86
95
  end
87
96
  raise EBSCO::EDS::InvalidParameter, 'Session must specify a valid api profile.' if blank?(@profile)
88
97
 
89
- if options.has_key? :guest
90
- @guest = options[:guest] ? 'y' : 'n'
91
- elsif ENV.has_key? 'EDS_GUEST'
92
- @guest = ENV['EDS_GUEST']
93
- end
98
+ # these config options can be overridden by environment vars
99
+ @auth_type = (ENV.has_key? 'EDS_AUTH') ? ENV['EDS_AUTH'] : @config[:auth]
100
+ @guest = (ENV.has_key? 'EDS_GUEST') ? ENV['EDS_GUEST'] : @config[:guest]
101
+ @org = (ENV.has_key? 'EDS_ORG') ? ENV['EDS_ORG'] : @config[:org]
94
102
 
95
- if options.has_key? :org
96
- @org = options[:org]
97
- elsif ENV.has_key? 'EDS_ORG'
98
- @org = ENV['EDS_ORG']
103
+ # use cache for auth token and info calls?
104
+ if @config[:use_cache]
105
+ cache_dir = File.join(@config[:eds_cache_dir], 'faraday_eds_cache')
106
+ @cache_store = ActiveSupport::Cache::FileStore.new cache_dir
99
107
  end
100
108
 
101
- if options.has_key? :auth
102
- @auth_type = options[:auth]
103
- elsif ENV.has_key? 'EDS_AUTH'
104
- @auth_type = ENV['EDS_AUTH']
105
- else
106
- @auth_type = 'user'
107
- end
108
-
109
- @max_retries = MAX_ATTEMPTS
109
+ @max_retries = @config[:max_attempts]
110
110
 
111
111
  if options.has_key? :auth_token
112
112
  @auth_token = options[:auth_token]
@@ -119,18 +119,18 @@ module EBSCO
119
119
  else
120
120
  @session_token = create_session_token
121
121
  end
122
-
123
- @info = EBSCO::EDS::Info.new(do_request(:get, path: INFO_URL))
122
+ @info = EBSCO::EDS::Info.new(do_request(:get, path: @config[:info_url]), @config)
124
123
  @current_page = 0
125
124
  @search_options = nil
126
125
 
127
- # DEBUG
128
- # if options.key? :caller
129
- # puts 'CREATE SESSION CALLER: ' + options[:caller].inspect
130
- # puts 'CALLER OPTIONS: ' + options.inspect
131
- # end
132
- # puts 'AUTH TOKEN: ' + @auth_token.inspect
133
- # puts 'SESSION TOKEN: ' + @session_token.inspect
126
+ if @config[:debug]
127
+ if options.key? :caller
128
+ puts 'CREATE SESSION CALLER: ' + options[:caller].inspect
129
+ puts 'CALLER OPTIONS: ' + options.inspect
130
+ end
131
+ puts 'AUTH TOKEN: ' + @auth_token.inspect
132
+ puts 'SESSION TOKEN: ' + @session_token.inspect
133
+ end
134
134
 
135
135
  end
136
136
 
@@ -168,7 +168,7 @@ module EBSCO
168
168
  if @search_options.nil?
169
169
  @search_results = EBSCO::EDS::Results.new(empty_results)
170
170
  else
171
- _response = do_request(:post, path: SEARCH_URL, payload: @search_options)
171
+ _response = do_request(:post, path: @config[:search_url], payload: @search_options)
172
172
  @search_results = EBSCO::EDS::Results.new(_response, @info.available_limiters, options)
173
173
  @current_page = @search_results.page_number
174
174
  @search_results
@@ -181,7 +181,7 @@ module EBSCO
181
181
  if @search_options.nil? || !add_actions
182
182
  @search_options = EBSCO::EDS::Options.new(options, @info)
183
183
  end
184
- _response = do_request(:post, path: SEARCH_URL, payload: @search_options)
184
+ _response = do_request(:post, path: @config[:search_url], payload: @search_options)
185
185
  @search_results = EBSCO::EDS::Results.new(_response, @info.available_limiters, options)
186
186
  @current_page = @search_results.page_number
187
187
  @search_results
@@ -223,20 +223,20 @@ module EBSCO
223
223
  #
224
224
  def retrieve(dbid:, an:, highlight: nil, ebook: 'ebook-pdf')
225
225
  payload = { DbId: dbid, An: an, HighlightTerms: highlight, EbookPreferredFormat: ebook }
226
- retrieve_response = do_request(:post, path: RETRIEVE_URL, payload: payload)
226
+ retrieve_response = do_request(:post, path: @config[:retrieve_url], payload: payload)
227
227
  record = EBSCO::EDS::Record.new(retrieve_response)
228
228
  # puts 'RECORD: ' + record.pretty_inspect
229
229
  record
230
230
  end
231
231
 
232
- def solr_retrieve_list(list: [], highlight: nil, ebook: 'ebook-pdf')
232
+ def solr_retrieve_list(list: [], highlight: nil)
233
233
  records = []
234
234
  if list.any?
235
235
  list.each { |id|
236
236
  dbid = id.split('__').first
237
237
  accession = id.split('__').last
238
238
  accession.gsub!(/_/, '.')
239
- records.push retrieve(dbid: dbid, an: accession, highlight: highlight, ebook: ebook)
239
+ records.push retrieve(dbid: dbid, an: accession, highlight: highlight, ebook: @config[:ebook_preferred_format])
240
240
  }
241
241
  end
242
242
  r = empty_results(records.length)
@@ -249,7 +249,7 @@ module EBSCO
249
249
  # Invalidates the session token. End Session should be called when you know a user has logged out.
250
250
  def end
251
251
  # todo: catch when there is no valid session?
252
- do_request(:post, path: END_SESSION_URL, payload: {:SessionToken => @session_token})
252
+ do_request(:post, path: @config[:end_session_url], payload: {:SessionToken => @session_token})
253
253
  connection.headers['x-sessionToken'] = ''
254
254
  @session_token = ''
255
255
  end
@@ -555,10 +555,9 @@ module EBSCO
555
555
 
556
556
  def do_request(method, path:, payload: nil, attempt: 0) # :nodoc:
557
557
 
558
- if attempt > MAX_ATTEMPTS
558
+ if attempt > @config[:max_attempts]
559
559
  raise EBSCO::EDS::ApiError, 'EBSCO API error: Multiple attempts to perform request failed.'
560
560
  end
561
-
562
561
  begin
563
562
  resp = connection.send(method) do |req|
564
563
  case method
@@ -574,7 +573,7 @@ module EBSCO
574
573
  end
575
574
  end
576
575
  resp.body
577
- rescue StandardError => e
576
+ rescue Error => e
578
577
  if e.respond_to? 'fault'
579
578
  error_code = e.fault[:error_body]['ErrorNumber'] || e.fault[:error_body]['ErrorCode']
580
579
  unless error_code.nil?
@@ -640,16 +639,17 @@ module EBSCO
640
639
  private
641
640
 
642
641
  def connection
643
- logger = Logger.new(LOG)
642
+ logger = Logger.new(@config[:log])
644
643
  logger.level = Logger::DEBUG
645
- Faraday.new(url: EDS_API_BASE) do |conn|
644
+ Faraday.new(url: @config[:eds_api_base]) do |conn|
646
645
  conn.headers['Content-Type'] = 'application/json;charset=UTF-8'
647
646
  conn.headers['Accept'] = 'application/json'
648
647
  conn.headers['x-sessionToken'] = @session_token ? @session_token : ''
649
648
  conn.headers['x-authenticationToken'] = @auth_token ? @auth_token : ''
650
- conn.headers['User-Agent'] = USER_AGENT
649
+ conn.headers['User-Agent'] = @config[:user_agent]
651
650
  conn.request :url_encoded
652
- conn.use :eds_middleware, store: @cache_store
651
+ conn.use :eds_caching_middleware, store: @cache_store if @config[:use_cache]
652
+ conn.use :eds_exception_middleware
653
653
  conn.response :json, content_type: /\bjson$/
654
654
  conn.response :logger, logger
655
655
  conn.adapter Faraday.default_adapter
@@ -660,10 +660,10 @@ module EBSCO
660
660
  if blank?(@auth_token)
661
661
  # ip auth
662
662
  if (blank?(@user) && blank?(@pass)) || @auth_type.casecmp('ip').zero?
663
- resp = do_request(:post, path: IP_AUTH_URL)
663
+ resp = do_request(:post, path: @config[:ip_auth_url])
664
664
  # user auth
665
665
  else
666
- resp = do_request(:post, path: UID_AUTH_URL, payload:
666
+ resp = do_request(:post, path: @config[:uid_auth_url], payload:
667
667
  { UserId: @user, Password: @pass })
668
668
  end
669
669
  end
@@ -672,7 +672,7 @@ module EBSCO
672
672
  end
673
673
 
674
674
  def create_session_token
675
- resp = do_request(:get, path: CREATE_SESSION_URL +
675
+ resp = do_request(:get, path: @config[:create_session_url] +
676
676
  '?profile=' + @profile + '&guest=' + @guest +
677
677
  '&displaydatabasename=y')
678
678
  @session_token = resp['SessionToken']
@@ -1,5 +1,5 @@
1
1
  module EBSCO
2
2
  module EDS
3
- VERSION = '0.0.9.pre'
3
+ VERSION = '0.1.0.pre'
4
4
  end
5
5
  end
@@ -2,7 +2,7 @@ require 'faraday'
2
2
 
3
3
  module Faraday
4
4
 
5
- class EdsMiddleware < Faraday::Middleware
5
+ class EdsCachingMiddleware < Faraday::Middleware
6
6
 
7
7
  INFO_URI = URI.parse('https://eds-api.ebscohost.com/edsapi/rest/Info')
8
8
  AUTH_URI = URI.parse('https://eds-api.ebscohost.com/authservice/rest/uidauth')
@@ -35,27 +35,8 @@ module Faraday
35
35
  to_response(response_env)
36
36
  else
37
37
  @app.call(env).on_complete do |response_env|
38
- case response_env.status
39
- when 200
40
- response_env.response_headers['x-faraday-eds-cache'] = 'MISS'
41
- cache_response(response_env)
42
- when 400
43
- raise EBSCO::EDS::BadRequest.new(error_message(response_env))
44
- # when 401
45
- # raise EBSCO::EDS::Unauthorized.new
46
- # when 403
47
- # raise EBSCO::EDS::Forbidden.new
48
- # when 404
49
- # raise EBSCO::EDS::NotFound.new
50
- # when 429
51
- # raise EBSCO::EDS::TooManyRequests.new
52
- # when 500
53
- # raise EBSCO::EDS::InternalServerError.new
54
- # when 503
55
- # raise EBSCO::EDS::ServiceUnavailable.new
56
- else
57
- raise EBSCO::EDS::BadRequest.new(error_message(response_env))
58
- end
38
+ response_env.response_headers['x-faraday-eds-cache'] = 'MISS'
39
+ cache_response(response_env)
59
40
  end
60
41
  end
61
42
  end
@@ -130,14 +111,5 @@ module Faraday
130
111
  env.response = response
131
112
  end
132
113
 
133
- def error_message(response)
134
- # puts response.inspect
135
- {
136
- method: response.method,
137
- url: response.url,
138
- status: response.status,
139
- error_body: response.body
140
- }
141
- end
142
114
  end
143
115
  end
@@ -0,0 +1,49 @@
1
+ require 'faraday'
2
+
3
+ module Faraday
4
+
5
+ class EdsExceptionMiddleware < Faraday::Middleware
6
+
7
+ def initialize(app)
8
+ super app
9
+ end
10
+
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))
31
+ end
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def error_message(response)
38
+ #puts response.inspect
39
+ {
40
+ method: response.method,
41
+ url: response.url,
42
+ status: response.status,
43
+ error_body: response.body
44
+ }
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -1,7 +1,7 @@
1
- require 'faraday/eds_middleware'
1
+ require 'faraday/eds_caching_middleware'
2
+ require 'faraday/eds_exception_middleware'
2
3
 
3
- if Faraday.respond_to?(:register_middleware)
4
- Faraday.register_middleware eds_middleware: Faraday::EdsMiddleware
5
- elsif Faraday::Middleware.respond_to?(:register_middleware)
6
- Faraday::Middleware.register_middleware eds_middleware: Faraday::EdsMiddleware
4
+ if Faraday::Middleware.respond_to?(:register_middleware)
5
+ Faraday::Middleware.register_middleware eds_caching_middleware: Faraday::EdsCachingMiddleware
6
+ Faraday::Middleware.register_middleware eds_exception_middleware: Faraday::EdsExceptionMiddleware
7
7
  end
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.0.9.pre
4
+ version: 0.1.0.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-04-04 00:00:00.000000000 Z
12
+ date: 2017-04-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -300,6 +300,7 @@ files:
300
300
  - bin/setup
301
301
  - ebsco-eds.gemspec
302
302
  - lib/ebsco/eds.rb
303
+ - lib/ebsco/eds/configuration.rb
303
304
  - lib/ebsco/eds/csl/styles/apa.csl
304
305
  - lib/ebsco/eds/csl/styles/chicago-author-date.csl
305
306
  - lib/ebsco/eds/csl/styles/modern-language-association.csl
@@ -311,7 +312,8 @@ files:
311
312
  - lib/ebsco/eds/results.rb
312
313
  - lib/ebsco/eds/session.rb
313
314
  - lib/ebsco/eds/version.rb
314
- - lib/faraday/eds_middleware.rb
315
+ - lib/faraday/eds_caching_middleware.rb
316
+ - lib/faraday/eds_exception_middleware.rb
315
317
  - lib/faraday_eds_middleware.rb
316
318
  homepage: https://github.com/ebsco/edsapi-ruby
317
319
  licenses: