class EBSCO::EDS::Session

Sessions are used to query and retrieve information from the EDS API.

Constants

Actions
Comment
FacetFilters

Attributes

config[R]

The session configuration.

info[RW]

Contains search Info available in the session profile. Includes the sort options, search fields, limiters and expanders available to the profile.

search_options[RW]

Contains the search Options sent as part of each request to the EDS API such as limiters, expanders, search modes, sort order, etc.

Public Class Methods

new(options = {}) click to toggle source

Creates a new session.

This can be done in one of two ways:

1. Environment variables

  • EDS_AUTH - authentication method: 'ip' or 'user'

  • EDS_PROFILE - profile ID for the EDS API

  • EDS_USER - user id attached to the profile

  • EDS_PASS - user password

  • EDS_GUEST - allow guest access: 'y' or 'n'

  • EDS_ORG - name of your institution or company

Example

Once you have environment variables set, simply create a session like this:

session = EBSCO::EDS::Session.new

2. Options

  • :auth

  • :profile

  • :user

  • :pass

  • :guest

  • :org

Example

session = EBSCO::EDS::Session.new {
  :auth => 'user',
  :profile => 'edsapi',
  :user => 'joe'
  :pass => 'secret',
  :guest => false,
  :org => 'Acme University'
}
# File lib/ebsco/eds/session.rb, line 68
def initialize(options = {})

  @session_token = ''
  @citation_token = ''
  @auth_token = ''
  @config = {}
  @guest = true
  @api_hosts_list = ''
  @api_host_index = 0

  eds_config = EBSCO::EDS::Configuration.new
  if options[:config]
    @config = eds_config.configure_with(options[:config])
    # return default if there is some problem with the yaml file (bad syntax, not found, etc.)
    @config = eds_config.configure if @config.nil?
  else
    @config = eds_config.configure(options)
  end

  # these properties aren't in the config
  if options.has_key? :user
    @user = options[:user]
  elsif ENV.has_key? 'EDS_USER'
    @user = ENV['EDS_USER']
  end

  if options.has_key? :pass
    @pass = options[:pass]
  elsif ENV.has_key? 'EDS_PASS'
    @pass = ENV['EDS_PASS']
  end

  if options.has_key? :profile
    @profile = options[:profile]
  elsif ENV.has_key? 'EDS_PROFILE'
    @profile = ENV['EDS_PROFILE']
  end
  raise EBSCO::EDS::InvalidParameter, 'Session must specify a valid api profile.' if blank?(@profile)

  # these config options can be overridden by environment vars
  @auth_type              =  (ENV.has_key? 'EDS_AUTH') ? ENV['EDS_AUTH'] : @config[:auth]
  @org                    =  (ENV.has_key? 'EDS_ORG') ? ENV['EDS_ORG'] : @config[:org]
  @cache_dir              =  (ENV.has_key? 'EDS_CACHE_DIR') ? ENV['EDS_CACHE_DIR'] : @config[:eds_cache_dir]
  @auth_expire            =  (ENV.has_key? 'EDS_AUTH_CACHE_EXPIRES_IN') ? ENV['EDS_AUTH_CACHE_EXPIRES_IN'] : @config[:auth_cache_expires_in]
  @info_expire            =  (ENV.has_key? 'EDS_INFO_CACHE_EXPIRES_IN') ? ENV['EDS_INFO_CACHE_EXPIRES_IN'] : @config[:info_cache_expires_in]
  @retrieve_expire        =  (ENV.has_key? 'EDS_RETRIEVE_CACHE_EXPIRES_IN') ? ENV['EDS_RETRIEVE_CACHE_EXPIRES_IN'] : @config[:retrieve_cache_expires_in]
  @search_expire          =  (ENV.has_key? 'EDS_SEARCH_CACHE_EXPIRES_IN') ? ENV['EDS_SEARCH_CACHE_EXPIRES_IN'] : @config[:search_cache_expires_in]
  @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]
  @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]


  @log_level =  (ENV.has_key? 'EDS_LOG_LEVEL') ? ENV['EDS_LOG_LEVEL'] : @config[:log_level]

  (ENV.has_key? 'EDS_GUEST') ?
      if %w(n N no No false False).include?(ENV['EDS_GUEST'])
        @guest = false
      else
        @guest = true
      end :
      @guest = @config[:guest]

  (ENV.has_key? 'EDS_USE_CACHE') ?
      if %w(n N no No false False).include?(ENV['EDS_USE_CACHE'])
        @use_cache = false
      else
        @use_cache = true
      end :
      @use_cache = @config[:use_cache]

  (ENV.has_key? 'EDS_DEBUG') ?
      if %w(y Y yes Yes true True).include?(ENV['EDS_DEBUG'])
        @debug = true
      else
        @debug = false
      end :
      @debug = @config[:debug]

  (ENV.has_key? 'EDS_HOSTS') ? @api_hosts_list = ENV['EDS_HOSTS'].split(',') : @api_hosts_list = @config[:api_hosts_list]

  (ENV.has_key? 'EDS_RECOVER_FROM_BAD_SOURCE_TYPE') ?
      if %w(y Y yes Yes true True).include?(ENV['EDS_RECOVER_FROM_BAD_SOURCE_TYPE'])
        @recover_130 = true
      else
        @recover_130 = false
      end :
      @recover_130 = @config[:recover_from_bad_source_type]

  # use cache for auth token, info, search and retrieve calls?
  if @use_cache
    cache_dir = File.join(@cache_dir, 'faraday_eds_cache')
    @cache_store = ActiveSupport::Cache::FileStore.new cache_dir
  end

  @max_retries = @config[:max_attempts]

  if options.has_key? :auth_token
    @auth_token = options[:auth_token]
  else
    @auth_token = create_auth_token
  end

  if options.key? :session_token
    @session_token = options[:session_token]
  else
    @session_token = create_session_token
  end

  if options.key? :citation_token
    @citation_token = options[:citation_token]
  else
    @citation_token = create_citation_token
  end

  @info = EBSCO::EDS::Info.new(do_request(:get, path: @config[:info_url]), @config)
  @current_page = 0
  @search_options = nil

  if @debug
    if options.key? :caller
      puts '*** CREATE SESSION CALLER: ' + options[:caller].inspect
      puts '*** CALLER OPTIONS: ' + options.inspect
    end
    puts '*** AUTH TOKEN: ' + @auth_token.inspect
    puts '*** SESSION TOKEN: ' + @session_token.inspect
    puts '*** CITATION TOKEN: ' + @citation_token.inspect
  end

end

Public Instance Methods

get_citation_exports(dbid:, an:, format: 'all') click to toggle source

fetch the citation from the citation rest endpoint

# File lib/ebsco/eds/session.rb, line 341
def get_citation_exports(dbid:, an:, format: 'all')
 begin
   # only available as non-guest otherwise 148 error
   citation_exports_params = "?an=#{an}&dbid=#{dbid}&format=#{format}"
   citation_exports_response = do_request(:get, path: @config[:citation_exports_url] + citation_exports_params)
   EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: citation_exports_response, eds_config: @config)
   rescue EBSCO::EDS::NotFound => e
     custom_error_message = JSON.parse e.message.gsub('=>', ':')
     # ErrorNumber 132 - Record not found
     if custom_error_message['ErrorNumber'] == '132'
       record_not_found = {"Format"=>format, "Label"=>"", "Data"=>"", "Error"=>"Record not found"}
       EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: record_not_found, eds_config: @config)
     end
   rescue EBSCO::EDS::BadRequest => e
      custom_error_message = JSON.parse e.message.gsub('=>', ':')
      # ErrorNumber 112 - Invalid Argument Value
      if custom_error_message['ErrorNumber'] == '112'
        unknown_export_format = {"Format"=>format, "Label"=>"", "Data"=>"", "Error"=>"Invalid citation export format"}
        EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: unknown_export_format, eds_config: @config)
      else
        unknown_error = {"Format"=>format, "Label"=>"", "Data"=>"", "Error"=>custom_error_message['ErrorDescription']}
        EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: unknown_error, eds_config: @config)
      end
    end
end
get_citation_exports_list(id_list: [], format: 'all') click to toggle source

get citation exports for a list of result ids

# File lib/ebsco/eds/session.rb, line 401
def get_citation_exports_list(id_list: [], format: 'all')
  citations = []
  if id_list.any?
    id_list.each { |id|
      dbid = id.split('__',2).first
      accession = id.split('__',2).last
      citations.push get_citation_exports(dbid: dbid, an: accession, format: format)
    }
  end
  citations
end
get_citation_styles(dbid:, an:, format: 'all') click to toggle source

fetch the citation from the citation rest endpoint

# File lib/ebsco/eds/session.rb, line 368
 def get_citation_styles(dbid:, an:, format: 'all')
   begin
     citation_styles_params = "?an=#{an}&dbid=#{dbid}&styles=#{format}"
     citation_styles_response = do_request(:get, path: @config[:citation_styles_url] + citation_styles_params)
     EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: citation_styles_response, eds_config: @config)
   rescue EBSCO::EDS::NotFound => e
     custom_error_message = JSON.parse e.message.gsub('=>', ':')
     # ErrorNumber 132 - Record not found
     if custom_error_message['ErrorNumber'] == '132'
       record_not_found = {"Format"=>format, "Label"=>"", "Data"=>"", "Error"=>"Record not found"}
       EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: record_not_found, eds_config: @config)
     end
   rescue EBSCO::EDS::BadRequest => e
     custom_error_message = JSON.parse e.message.gsub('=>', ':')
     unknown_error = {"Id"=>format, "Label"=>"", "Data"=>"", "Error"=>custom_error_message['ErrorDescription']}
     EBSCO::EDS::Citations.new(dbid: dbid, an: an, citation_result: unknown_error, eds_config: @config)
   end
end
get_citation_styles_list(id_list: [], format: 'all') click to toggle source

get citation styles for a list of result ids

# File lib/ebsco/eds/session.rb, line 388
def get_citation_styles_list(id_list: [], format: 'all')
  citations = []
  if id_list.any?
    id_list.each { |id|
      dbid = id.split('__',2).first
      accession = id.split('__',2).last
      citations.push get_citation_styles(dbid: dbid, an: accession, format: format)
    }
  end
  citations
end
solr_retrieve_list(list: [], highlight: nil) click to toggle source
# File lib/ebsco/eds/session.rb, line 481
def solr_retrieve_list(list: [], highlight: nil)
  records = []
  if list.any?
    list.each.with_index(1) { |id, index|
      dbid = id.split('__',2).first
      accession = id.split('__',2).last
      begin
        current_rec = retrieve(dbid: dbid, an: accession, highlight: highlight, ebook: @config[:ebook_preferred_format])
        current_rec.eds_result_id = index
        records.push current_rec
      rescue EBSCO::EDS::BadRequest, EBSCO::EDS::NotFound => e
        puts "Request for #{id} in #{self.class.name}#solr_retrieve_list failed with #{e}" if @debug
      end
    }
  end
  r = empty_results(records.length)
  results = EBSCO::EDS::Results.new(r, @config)
  results.records = records
  results.to_solr
end
solr_retrieve_previous_next(options = {}) click to toggle source

Create a result set with just the record before and after the current detailed record

# File lib/ebsco/eds/session.rb, line 414
def solr_retrieve_previous_next(options = {})

  rid = options['previous-next-index']

  # set defaults if missing
  if options['page'].nil?
    options['page'] = '1'
  end
  if options['per_page'].nil?
    options['per_page'] = '20'
  end

  rpp = options['per_page'].to_i

  # determine result page and update options
  goto_page = rid / rpp
  if (rid % rpp) > 0
    goto_page += 1
  end
  options['page'] = goto_page.to_s
  pnum = options['page'].to_i

  max = rpp * pnum
  min = max - rpp + 1
  result_index = rid - min
  cached_results = search(options, false, false)
  cached_results_found = cached_results.stat_total_hits

  # last result in set, get next result
  if rid == max
    options_next = options
    options_next['page'] = cached_results.page_number+1
    next_result_set = search(options_next, false, false)
    result_next = next_result_set.records.first
  else
    unless rid == cached_results_found
      result_next = cached_results.records[result_index+1]
    end
  end

  if result_index == 0
    # first result in set that's not the very first result, get previous result
    if rid != 1
      options_previous = options
      options_previous['page'] = cached_results.page_number-1
      previous_result_set = search(options_previous, false, false)
      result_prev = previous_result_set.records.last
    end
  else
    result_prev = cached_results.records[result_index-1]
  end

  # return json result set with just the previous and next records in it
  r = empty_results(cached_results.stat_total_hits)
  results = EBSCO::EDS::Results.new(r, @config)
  next_previous_records = []
  unless result_prev.nil?
    next_previous_records << result_prev
  end
  unless result_next.nil?
    next_previous_records << result_next
  end
  results.records = next_previous_records
  results.to_solr

end

Private Instance Methods

blank?(var) click to toggle source

helper methods

# File lib/ebsco/eds/session.rb, line 1199
def blank?(var)
  var.nil? || var.respond_to?(:length) && var.empty?
end
citation_connection() click to toggle source
# File lib/ebsco/eds/session.rb, line 1141
def citation_connection
  logger = Logger.new(@config[:log])
  logger.level = Logger.const_get(@log_level)
  Faraday.new(url: 'https://' + @api_hosts_list[@api_host_index]) do |conn|
    conn.headers['Content-Type'] = 'application/json;charset=UTF-8'
    conn.headers['Accept'] = 'application/json'
    conn.headers['x-sessionToken'] = @citation_token ? @citation_token : ''
    conn.headers['x-authenticationToken'] = @auth_token ? @auth_token : ''
    conn.headers['User-Agent'] = @config[:user_agent]
    conn.request :url_encoded
    conn.use :eds_caching_middleware,
             store: @cache_store,
             auth_expire: @auth_expire,
             info_expire: @info_expire,
             search_expire: @search_expire,
             retrieve_expire: @retrieve_expire,
             export_format_expire: @export_format_expire,
             citation_styles_expire: @citation_styles_expire,
             logger: @debug ? logger : nil if @use_cache
    conn.use :eds_exception_middleware
    conn.response :json, content_type: /\bjson$/
    conn.response :detailed_logger, logger if @debug
    conn.options[:open_timeout] = @config[:open_timeout]
    conn.options[:timeout] = @config[:timeout]
    conn.adapter :net_http_persistent
  end
end
connection() click to toggle source
# File lib/ebsco/eds/session.rb, line 1093
def connection
  logger = Logger.new(@config[:log])
  logger.level = Logger.const_get(@log_level)
  Faraday.new(url: 'https://' + @api_hosts_list[@api_host_index]) do |conn|
    conn.headers['Content-Type'] = 'application/json;charset=UTF-8'
    conn.headers['Accept'] = 'application/json'
    conn.headers['x-sessionToken'] = @session_token ? @session_token : ''
    conn.headers['x-authenticationToken'] = @auth_token ? @auth_token : ''
    conn.headers['User-Agent'] = @config[:user_agent]
    conn.request :url_encoded
    conn.use :eds_caching_middleware,
             store: @cache_store,
             auth_expire: @auth_expire,
             info_expire: @info_expire,
             search_expire: @search_expire,
             retrieve_expire: @retrieve_expire,
             export_format_expire: @export_format_expire,
             citation_styles_expire: @citation_styles_expire,
             logger: @debug ? logger : nil if @use_cache
    conn.use :eds_exception_middleware
    conn.response :json, content_type: /\bjson$/
    conn.response :detailed_logger, logger if @debug
    conn.options[:open_timeout] = @config[:open_timeout]
    conn.options[:timeout] = @config[:timeout]
    conn.adapter :net_http_persistent
  end
end
create_auth_token() click to toggle source
# File lib/ebsco/eds/session.rb, line 1169
def create_auth_token
  if blank?(@auth_token)
    # ip auth
    if (blank?(@user) && blank?(@pass)) || @auth_type.casecmp('ip').zero?
      resp = do_request(:post, path: @config[:ip_auth_url])
    # user auth
    else
      resp = do_request(:post, path: @config[:uid_auth_url], payload:
          { UserId: @user, Password: @pass, InterfaceId: @config[:interface_id] })
    end
  end
  @auth_token = resp['AuthToken']
  @auth_token
end
create_citation_token() click to toggle source
# File lib/ebsco/eds/session.rb, line 1192
def create_citation_token
  resp = do_request(:get, path: @config[:create_session_url] +
      '?profile=' + @profile + '&guest=n&displaydatabasename=y')
  @citation_token = resp['SessionToken']
end
create_session_token() click to toggle source
# File lib/ebsco/eds/session.rb, line 1184
def create_session_token
  guest_string = @guest ? 'y' : 'n'
  resp = do_request(:get, path: @config[:create_session_url] +
      '?profile=' + @profile + '&guest=' + guest_string +
      '&displaydatabasename=y')
  @session_token = resp['SessionToken']
end
eds_sanitize(str) click to toggle source
# File lib/ebsco/eds/session.rb, line 1252
def eds_sanitize(str)
  pattern = /([)(:,])/
  str = str.gsub(pattern){ |match| '\\' + match }
  str
end
empty_results(hits = 0) click to toggle source

used to reliably create empty results when there are no search terms provided

# File lib/ebsco/eds/session.rb, line 1204
def empty_results(hits = 0)
  {
      'SearchRequest'=>
          {
              'SearchCriteria'=>
                  {
                      'Queries'=>nil,
                      'SearchMode'=>'',
                      'IncludeFacets'=>'y',
                      'Sort'=>'relevance',
                      'AutoSuggest'=>'n',
                      'AutoCorrect'=>'n'
                  },
              'RetrievalCriteria'=>
                  {
                      'View'=>'brief',
                      'ResultsPerPage'=>20,
                      'Highlight'=>'y',
                      'IncludeImageQuickView'=>'n'
                  },
              'SearchCriteriaWithActions'=>
                  {
                      'QueriesWithAction'=>nil
                  }
          },
      'SearchResult'=>
          {
              'Statistics'=>
                  {
                      'TotalHits'=>hits,
                      'TotalSearchTime'=>0,
                      'Databases'=>[]
                  },
              'Data'=> {'RecordFormat'=>'EP Display'},
              'AvailableCriteria'=>{'DateRange'=>{'MinDate'=>'0001-01', 'MaxDate'=>'0001-01'}}
          }
  }
end
get_cache_id(path, payload) click to toggle source

generate a cache id for search and retrieve post requests, using a hash of the payload + guest mode

# File lib/ebsco/eds/session.rb, line 1244
def get_cache_id(path, payload)
  if path == '/edsapi/rest/Search' or path == '/edsapi/rest/Retrieve'
    '?cache_id=' + Digest::MD5.hexdigest(payload + @guest.to_s)
  else
    ''
  end
end
get_jump_pages(search_options) click to toggle source
# File lib/ebsco/eds/session.rb, line 1258
def get_jump_pages(search_options)
  dest_page = search_options.RetrievalCriteria.PageNumber.to_i
  jump_incr = 250/search_options.RetrievalCriteria.ResultsPerPage.to_i
  attempts = dest_page/jump_incr
  jump_pages = []
  (1..attempts).to_a.each do |n|
    jump_pages.push(jump_incr*n)
  end
  puts 'JUMP PAGES: ' + jump_pages.inspect if @debug
  jump_pages
end
jump_connection() click to toggle source

same as above but no caching

# File lib/ebsco/eds/session.rb, line 1122
def jump_connection
  logger = Logger.new(@config[:log])
  logger.level = Logger.const_get(@log_level)
  Faraday.new(url: 'https://' + @api_hosts_list[@api_host_index]) do |conn|
    conn.headers['Content-Type'] = 'application/json;charset=UTF-8'
    conn.headers['Accept'] = 'application/json'
    conn.headers['x-sessionToken'] = @session_token ? @session_token : ''
    conn.headers['x-authenticationToken'] = @auth_token ? @auth_token : ''
    conn.headers['User-Agent'] = @config[:user_agent]
    conn.request :url_encoded
    conn.use :eds_exception_middleware
    conn.response :json, content_type: /\bjson$/
    conn.response :detailed_logger, logger if @debug
    conn.options[:open_timeout] = @config[:open_timeout]
    conn.options[:timeout] = @config[:timeout]
    conn.adapter :net_http_persistent
  end
end

Expander Methods

↑ top

Public Instance Methods

add_expander(val) click to toggle source

Adds expanders and sets the page number back to 1. Multiple expanders should be comma separated. Returns search Results.

Examples

results = session.add_expander('thesaurus,fulltext')
# File lib/ebsco/eds/session.rb, line 769
def add_expander(val)
  add_actions "AddExpander(#{val})"
end
clear_expanders() click to toggle source

Removes all specified expanders and sets the page number back to 1. Returns search Results.

# File lib/ebsco/eds/session.rb, line 760
def clear_expanders
  add_actions 'ClearExpanders()'
end
remove_expander(val) click to toggle source

Removes a specified expander. Sets the page number to 1. Returns search Results.

Examples

results = session.remove_expander('fulltext')
# File lib/ebsco/eds/session.rb, line 778
def remove_expander(val)
  add_actions "RemoveExpander(#{val})"
end

Facet Methods

↑ top

Public Instance Methods

add_facet(facet_id, facet_val) click to toggle source

Adds a facet filter to the search request. Sets the page number back to 1. Returns search Results.

Examples

results = session.add_facet('Publisher', 'wiley-blackwell')
results = session.add_facet('SubjectEDS', 'water quality')
# File lib/ebsco/eds/session.rb, line 688
def add_facet(facet_id, facet_val)
  facet_val = eds_sanitize(facet_val)
  add_actions "AddFacetFilter(#{facet_id}:#{facet_val})"
end
clear_facets() click to toggle source

Removes all specified facet filters. Sets the page number back to 1. Returns search Results.

# File lib/ebsco/eds/session.rb, line 677
def clear_facets
  add_actions 'ClearFacetFilters()'
end
remove_facet(group_id) click to toggle source

Removes a specified facet filter id. Sets the page number back to 1. Returns search Results.

Examples

results = session.remove_facet(45)
# File lib/ebsco/eds/session.rb, line 698
def remove_facet(group_id)
  add_actions "RemoveFacetFilter(#{group_id})"
end
remove_facet_value(group_id, facet_id, facet_val) click to toggle source

Removes a specific facet filter value from a group. Sets the page number back to 1. Returns search Results.

Examples

results = session.remove_facet_value(2, 'DE', 'Psychology')
# File lib/ebsco/eds/session.rb, line 707
def remove_facet_value(group_id, facet_id, facet_val)
  add_actions "RemoveFacetFilterValue(#{group_id},#{facet_id}:#{facet_val})"
end

Limiter Methods

↑ top

Public Instance Methods

add_limiter(id, val) click to toggle source

Adds a limiter to the currently defined search and sets the page number back to 1. Returns search Results.

Examples

results = session.add_limiter('FT','y')
# File lib/ebsco/eds/session.rb, line 729
def add_limiter(id, val)
  add_actions "AddLimiter(#{id}:#{val})"
end
clear_limiters() click to toggle source

Clears all currently specified limiters and sets the page number back to 1. Returns search Results.

# File lib/ebsco/eds/session.rb, line 720
def clear_limiters
  add_actions 'ClearLimiters()'
end
remove_limiter(id) click to toggle source

Removes the specified limiter and sets the page number back to 1. Returns search Results.

Examples

results = session.remove_limiter('FT')
# File lib/ebsco/eds/session.rb, line 738
def remove_limiter(id)
  add_actions "RemoveLimiter(#{id})"
end
remove_limiter_value(id, val) click to toggle source

Removes a specified limiter value and sets the page number back to 1. Returns search Results.

Examples

results = session.remove_limiter_value('LA99','French')
# File lib/ebsco/eds/session.rb, line 747
def remove_limiter_value(id, val)
  add_actions "RemoveLimiterValue(#{id}:#{val})"
end

Pagination Methods

↑ top

Public Instance Methods

get_page(page = 1) click to toggle source

Get a specified page of results Returns search Results.

# File lib/ebsco/eds/session.rb, line 649
def get_page(page = 1)
  add_actions "GoToPage(#{page})"
end
move_page(num) click to toggle source

Increments the current results page number by the value specified. If the current page was 5 and the specified value was 2, the page number would be set to 7. Returns search Results.

# File lib/ebsco/eds/session.rb, line 657
def move_page(num)
  add_actions "MovePage(#{num})"
end
next_page() click to toggle source

Get the next page of results. Returns search Results.

# File lib/ebsco/eds/session.rb, line 634
def next_page
  page = @current_page + 1
  get_page(page)
end
prev_page() click to toggle source

Get the previous page of results. Returns search Results.

# File lib/ebsco/eds/session.rb, line 642
def prev_page
  get_page([1, @current_page - 1].sort.last)
end
reset_page() click to toggle source

Get the first page of results. Returns search Results.

# File lib/ebsco/eds/session.rb, line 664
def reset_page
  add_actions 'ResetPaging()'
end

Profile Settings Methods

↑ top

Public Instance Methods

dbid_in_profile(dbid) click to toggle source

Determine if a database ID is available in the profile. Returns Boolean.

# File lib/ebsco/eds/session.rb, line 1073
def dbid_in_profile(dbid)
  get_available_database_ids.include? dbid
end
get_available_database_ids() click to toggle source

Get a list of all available database IDs. Returns Array of IDs.

# File lib/ebsco/eds/session.rb, line 1066
def get_available_database_ids
  get_available_databases.map{|item| item[:id]}
end
publication_match_in_profile() click to toggle source

Determine if publication matching is available in the profile. Returns Boolean.

# File lib/ebsco/eds/session.rb, line 1080
def publication_match_in_profile
  @info.available_related_content_types.include? 'emp'
end
research_starters_match_in_profile() click to toggle source

Determine if research starters are available in the profile. Returns Boolean.

# File lib/ebsco/eds/session.rb, line 1087
def research_starters_match_in_profile
  @info.available_related_content_types.include? 'rs'
end

Publication Methods

↑ top

Public Instance Methods

add_publication(pub_id) click to toggle source

Specifies a publication to search within. Sets the pages number back to 1. Returns search Results.

Examples

results = session.add_publication('eric')
# File lib/ebsco/eds/session.rb, line 793
def add_publication(pub_id)
  add_actions "AddPublication(#{pub_id})"
end
remove_all_publications() click to toggle source

Removes all publications from the search. Sets the page number back to 1. Returns search Results.

# File lib/ebsco/eds/session.rb, line 807
def remove_all_publications
  add_actions 'RemovePublication()'
end
remove_publication(pub_id) click to toggle source

Removes a publication from the search. Sets the page number back to 1. Returns search Results.

# File lib/ebsco/eds/session.rb, line 800
def remove_publication(pub_id)
  add_actions "RemovePublication(#{pub_id})"
end

Search & Retrieve Methods

↑ top

Public Instance Methods

add_actions(actions) click to toggle source

Add actions to an existing search session Returns search Results.

Examples

results = session.add_actions('addfacetfilter(SubjectGeographic:massachusetts)')
# File lib/ebsco/eds/session.rb, line 550
def add_actions(actions)
  @search_options.add_actions(actions, @info)
  search()
end
add_query(query) click to toggle source

Add a query to the search request. When a query is added, it will be assigned an ordinal, which will be exposed in the search response message. It also removes any specified facet filters and sets the page number to 1. Returns search Results.

Examples

results = session.add_query('AND,California')
# File lib/ebsco/eds/session.rb, line 531
def add_query(query)
  add_actions "AddQuery(#{query})"
end
clear_queries() click to toggle source

Clears all queries and facet filters, and set the page number back to 1; limiters and expanders are not modified. Returns search Results.

# File lib/ebsco/eds/session.rb, line 521
def clear_queries
  add_actions 'ClearQueries()'
end
end() click to toggle source

Invalidates the session token. End Session should be called when you know a user has logged out.

# File lib/ebsco/eds/session.rb, line 504
def end
  # todo: catch when there is no valid session?
  do_request(:post, path: @config[:end_session_url], payload: {:SessionToken => @session_token})
  connection.headers['x-sessionToken'] = ''
  @session_token = ''
end
remove_query(query_id) click to toggle source

Removes query from the currently specified search. It also removes any specified facet filters and sets the page number to 1. Returns search Results.

Examples

results = session.remove_query(1)
# File lib/ebsco/eds/session.rb, line 541
def remove_query(query_id)
  add_actions "removequery(#{query_id})"
end
retrieve(dbid:, an:, highlight: nil, ebook: 'ebook-pdf') click to toggle source

Returns a Record based a particular result based on a database ID and accession number.

Attributes

  • :dbid - The database ID (required).

  • :an - The accession number (required).

  • highlight - Comma separated list of terms to highlight in the data records (optional).

  • ebook - Preferred format to return ebook content in. Either ebook-pdf (default) or ebook-pdf.

Examples

record = session.retrieve({dbid: 'asn', an: '108974507'})
# File lib/ebsco/eds/session.rb, line 325
def retrieve(dbid:, an:, highlight: nil, ebook: 'ebook-pdf')
  payload = { DbId: dbid, An: an, HighlightTerms: highlight, EbookPreferredFormat: ebook }
  retrieve_response = do_request(:post, path: @config[:retrieve_url], payload: payload)
  record = EBSCO::EDS::Record.new(retrieve_response, @config)
  record_citation_exports = get_citation_exports({dbid: dbid, an: an, format: @config[:citation_exports_formats]})
  unless record_citation_exports.nil?
    record.set_citation_exports(record_citation_exports)
  end
  record_citation_styles = get_citation_styles({dbid: dbid, an: an, format: @config[:citation_styles_formats]})
  unless record_citation_styles.nil?
    record.set_citation_styles(record_citation_styles)
  end
  record
end

Setter Methods

↑ top

Public Instance Methods

results_per_page(num) click to toggle source

Sets the page size on the search request. Returns search Results.

Examples

results = session.results_per_page(50)
# File lib/ebsco/eds/session.rb, line 597
def results_per_page(num)
  add_actions "SetResultsPerPage(#{num})"
end
set_highlight(val) click to toggle source

Sets whether or not to turn highlighting on or off (y|n). Returns search Results.

Examples

results = session.set_highlight('n')
# File lib/ebsco/eds/session.rb, line 588
def set_highlight(val)
  add_actions "SetHighlight(#{val})"
end
set_include_facets(val) click to toggle source

Specify to include facets in the results or not. Either 'y' or 'n'. Returns search Results.

Examples

results = session.set_include_facets('n')
# File lib/ebsco/eds/session.rb, line 621
def set_include_facets(val)
  add_actions "SetIncludeFacets(#{val})"
end
set_search_mode(mode) click to toggle source

Sets the search mode. The available search modes are returned from the info method. Returns search Results.

Examples

results = session.set_search_mode('bool')
# File lib/ebsco/eds/session.rb, line 570
def set_search_mode(mode)
  add_actions "SetSearchMode(#{mode})"
end
set_sort(val) click to toggle source

Sets the sort for the search. The available sorts for the specified databases can be obtained from the session’s info attribute. Sets the page number back to 1. Returns search Results.

Examples

results = session.set_sort('newest')
# File lib/ebsco/eds/session.rb, line 561
def set_sort(val)
  add_actions "SetSort(#{val})"
end
set_view(view) click to toggle source

Specifies the view parameter. The view representes the amount of data to return with the search. Returns search Results.

Examples

results = session.set_view('detailed')
# File lib/ebsco/eds/session.rb, line 579
def set_view(view)
  add_actions "SetView(#{view})"
end