Class: Qa::Authorities::Oclcts

Inherits:
WebServiceBase show all
Defined in:
lib/qa/authorities/oclcts.rb

Constant Summary collapse

SRU_SERVER_CONFIG =
YAML.load_file(Rails.root.join("config", "oclcts-authorities.yml"))

Instance Attribute Summary

Attributes inherited from WebServiceBase

#raw_response

Attributes inherited from Base

#sub_authority

Instance Method Summary collapse

Methods inherited from WebServiceBase

#get_json, #request_options

Methods inherited from Base

#all, #full_record

Constructor Details

#initialize(*args) ⇒ Oclcts

Returns a new instance of Oclcts.



9
10
11
12
13
# File 'lib/qa/authorities/oclcts.rb', line 9

def initialize *args
  super
  @sub_authority ||= args.first
  raise "No sub-authority provided" if sub_authority.nil?
end

Instance Method Details

#find(id) ⇒ Object



28
29
30
31
# File 'lib/qa/authorities/oclcts.rb', line 28

def find id
  get_raw_response("id-lookup", id)
  parse_full_record(id)
end

#search(q) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/qa/authorities/oclcts.rb', line 19

def search q
  get_raw_response("prefix-query", q)
  r = Array.new
  raw_response.xpath('sru:searchRetrieveResponse/sru:records/sru:record/sru:recordData', 'sru' => 'http://www.loc.gov/zing/srw/').each do |record|
    r.append({"id" => record.xpath('Zthes/term/termId').first.content, "label" => record.xpath('Zthes/term/termName').first.content})
  end
  r
end

#sub_authoritiesObject



15
16
17
# File 'lib/qa/authorities/oclcts.rb', line 15

def sub_authorities
  SRU_SERVER_CONFIG["authorities"].map { |sub_authority| sub_authority[0] }
end