Class: Qa::Authorities::Loc::GenericAuthority

Inherits:
Base
  • Object
show all
Includes:
WebServiceBase
Defined in:
lib/qa/authorities/loc/generic_authority.rb

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, #full_record

Constructor Details

#initialize(subauthority) ⇒ GenericAuthority

Returns a new instance of GenericAuthority.



4
5
6
# File 'lib/qa/authorities/loc/generic_authority.rb', line 4

def initialize(subauthority)
  @subauthority = subauthority
end

Instance Attribute Details

#subauthorityObject (readonly)

Returns the value of attribute subauthority.



3
4
5
# File 'lib/qa/authorities/loc/generic_authority.rb', line 3

def subauthority
  @subauthority
end

Instance Method Details

#build_query_url(q) ⇒ Object



15
16
17
18
19
# File 'lib/qa/authorities/loc/generic_authority.rb', line 15

def build_query_url(q)
  escaped_query = URI.escape(q)
  authority_fragment = Loc.get_url_for_authority(subauthority) + URI.escape(subauthority)
  "http://id.loc.gov/search/?q=#{escaped_query}&q=#{authority_fragment}&format=json"
end

#find(id) ⇒ Object



21
22
23
# File 'lib/qa/authorities/loc/generic_authority.rb', line 21

def find(id)
  get_json(find_url(id))
end

#find_url(id) ⇒ Object



25
26
27
# File 'lib/qa/authorities/loc/generic_authority.rb', line 25

def find_url(id)
  "http://id.loc.gov/authorities/#{@subauthority}/#{id}.json"
end

#search(q) ⇒ Object



10
11
12
13
# File 'lib/qa/authorities/loc/generic_authority.rb', line 10

def search(q)
  @raw_response = get_json(build_query_url(q))
  parse_authority_response
end