Class: Qa::Authorities::AssignFast::GenericAuthority

Inherits:
Base
  • Object
show all
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

Attributes included from WebServiceBase

#raw_response

Instance Method Summary collapse

Methods included from WebServiceBase

#get_json, #response

Methods inherited from Base

#all, #find, #full_record

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)
  @subauthority = subauthority
end

Instance Attribute Details

#subauthorityObject (readonly)

Returns the value of attribute subauthority.



6
7
8
# File 'lib/qa/authorities/assign_fast/generic_authority.rb', line 6

def subauthority
  @subauthority
end

Instance Method Details

#build_query_url(q) ⇒ String

Build a FAST API url

Parameters:

  • the (String)

    query

Returns:

  • (String)

    the url



32
33
34
35
36
37
38
# File 'lib/qa/authorities/assign_fast/generic_authority.rb', line 32

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
  url = "http://fast.oclc.org/searchfast/fastsuggest?&query=#{escaped_query}&queryIndex=#{index}&queryReturn=#{return_data}&suggest=autoSubject&rows=#{num_rows}"
end

#search(q) ⇒ Object

Search the FAST api

Parameters:

  • the (String)

    query

Returns:

  • json results



17
18
19
20
21
22
23
24
25
26
# File 'lib/qa/authorities/assign_fast/generic_authority.rb', line 17

def search q
  url = build_query_url q
  begin
    raw_response = get_json(url)
  rescue JSON::ParserError => error
    Rails.logger.info "Could not parse response as JSON. Request url: #{url}"
    return []
  end
  parse_authority_response(raw_response)
end