class Qa::Authorities::AssignFast::GenericAuthority
A wrapper around the FAST api for use with questioning_authority API documentation: www.oclc.org/developer/develop/web-services/fast-api/assign-fast.en.html
Attributes
Public Class Methods
Source
# File lib/qa/authorities/assign_fast/generic_authority.rb, line 8 def initialize(subauthority) super() @subauthority = subauthority end
Calls superclass method
Public Instance Methods
Source
# File lib/qa/authorities/assign_fast/generic_authority.rb, line 45 def build_query_url(q) escaped_query = clean_query_string q index = AssignFast.index_for_authority(subauthority) return_data = "#{index}%2Cidroot%2Cauth%2Ctype" num_rows = 20 # max allowed by the API # sort=usage+desc is not documented by OCLC but seems necessary to get the sort # we formerly got without specifying, that is most useful in our use case. "#{assign_fast_url}?&query=#{escaped_query}&queryIndex=#{index}&queryReturn=#{return_data}&suggest=autoSubject&rows=#{num_rows}&sort=usage+desc" end
Build a FAST API url
@param [String] the query @return [String] the url
Source
# File lib/qa/authorities/assign_fast/generic_authority.rb, line 17 def response(url) space_fix_encoder = AssignFast::SpaceFixEncoder.new Faraday.get(url) do |req| req.options.params_encoder = space_fix_encoder req.headers['Accept'] = 'application/json' req.options.timeout = connection_timeout_in_seconds unless connection_timeout_in_seconds.nil? end end
FAST requires spaces to be encoded as %20 and will not accept + which is Faraday’s default encoding
Source
# File lib/qa/authorities/assign_fast/generic_authority.rb, line 30 def search(q) url = build_query_url q begin raw_response = json(url) rescue JSON::ParserError Rails.logger.info "Could not parse response as JSON. Request url: #{url}" return [] end parse_authority_response(raw_response) end
Search the FAST api
@param [String] the query @return json results
Private Instance Methods
Source
# File lib/qa/authorities/assign_fast/generic_authority.rb, line 60 def assign_fast_config Qa.config.assign_fast_authority_configs end
See github.com/samvera/questioning_authority/wiki/Connecting-to-OCLC-FAST for more info about config settings for this authority.
Source
# File lib/qa/authorities/assign_fast/generic_authority.rb, line 68 def assign_fast_url assign_fast_config.dig(:OCLC_ASSIGN_FAST, :search, :urls, :fastsuggest) || 'https://fast.oclc.org/searchfast/fastsuggest' end
Source
# File lib/qa/authorities/assign_fast/generic_authority.rb, line 75 def clean_query_string(q) ERB::Util.url_encode(q.gsub(/-|\(|\)|:/, "")) end
Removes characters from the query string that are not tolerated by the API
See oclc sample code at http://experimental.worldcat.org/fast/assignfast/js/assignFASTComplete.js
Source
# File lib/qa/authorities/assign_fast/generic_authority.rb, line 64 def connection_timeout_in_seconds assign_fast_config.dig(:OCLC_ASSIGN_FAST, :search, :connection, :timeout)&.to_i end