Class: Qa::Authorities::AssignFast::GenericAuthority
- Includes:
- WebServiceBase
- Defined in:
- lib/qa/authorities/assign_fast/generic_authority.rb
Overview
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
Instance Attribute Summary collapse
-
#subauthority ⇒ Object
readonly
Returns the value of attribute subauthority.
Attributes included from WebServiceBase
Instance Method Summary collapse
-
#build_query_url(q) ⇒ String
Build a FAST API url.
-
#initialize(subauthority) ⇒ GenericAuthority
constructor
A new instance of GenericAuthority.
-
#response(url) ⇒ Object
FAST requires spaces to be encoded as %20 and will not accept + which is Faraday’s default encoding.
-
#search(q) ⇒ Object
Search the FAST api.
Methods included from WebServiceBase
Methods inherited from Base
Constructor Details
#initialize(subauthority) ⇒ GenericAuthority
Returns a new instance of GenericAuthority.
7 8 9 |
# File 'lib/qa/authorities/assign_fast/generic_authority.rb', line 7 def initialize() @subauthority = end |
Instance Attribute Details
#subauthority ⇒ Object (readonly)
Returns the value of attribute subauthority.
6 7 8 |
# File 'lib/qa/authorities/assign_fast/generic_authority.rb', line 6 def @subauthority end |
Instance Method Details
#build_query_url(q) ⇒ String
Build a FAST API url
42 43 44 45 46 47 48 |
# File 'lib/qa/authorities/assign_fast/generic_authority.rb', line 42 def build_query_url(q) escaped_query = clean_query_string q index = AssignFast.() return_data = "#{index}%2Cidroot%2Cauth%2Ctype" num_rows = 20 # max allowed by the API "http://fast.oclc.org/searchfast/fastsuggest?&query=#{escaped_query}&queryIndex=#{index}&queryReturn=#{return_data}&suggest=autoSubject&rows=#{num_rows}" end |
#response(url) ⇒ Object
FAST requires spaces to be encoded as %20 and will not accept + which is Faraday’s default encoding
15 16 17 18 19 20 21 |
# File 'lib/qa/authorities/assign_fast/generic_authority.rb', line 15 def response(url) space_fix_encoder = AssignFast::SpaceFixEncoder.new Faraday.get(url) do |req| req..params_encoder = space_fix_encoder req.headers['Accept'] = 'application/json' end end |
#search(q) ⇒ Object
Search the FAST api
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/qa/authorities/assign_fast/generic_authority.rb', line 27 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 (raw_response) end |