class Gared::Primo
Public Class Methods
new(url, institution)
click to toggle source
# File lib/gared/primo.rb, line 6 def initialize(url, institution) @options = {url: url, institution: institution} end
Public Instance Methods
query_person(person)
click to toggle source
# File lib/gared/primo.rb, line 13 def query_person(person) end
query_persons(q)
click to toggle source
# File lib/gared/primo.rb, line 10 def query_persons(q) end
query_publication(publication)
click to toggle source
# File lib/gared/primo.rb, line 19 def query_publication(publication) end
query_publications(q)
click to toggle source
# File lib/gared/primo.rb, line 16 def query_publications(q) end
query_publications_by_person(person, ctx = nil)
click to toggle source
return in-memory Publication
instances with associated Holdings
# File lib/gared/primo.rb, line 23 def query_publications_by_person(person, ctx = nil) ret = [] begin url = @options[:url]+"?institution=#{@options[:institution]}&query=creator,contains,#{URI.escape(person)}&indx=1&bulkSize=50&query=facet_rtype,exact,books&json=true" json = JSON.parse(RestClient.get(url)) total = json['SEGMENTS']['JAGROOT']['RESULT']['DOCSET']['@TOTALHITS'].to_i start_at = 1 recs = json['SEGMENTS']['JAGROOT']['RESULT']['DOCSET']['DOC'] # stash the records while recs.length < total start_at += 50 url = @options[:url]+"?institution=#{@options[:institution]}&query=creator,contains,#{URI.escape(person)}&indx=#{start_at}&bulkSize=50&query=facet_rtype,exact,books&json=true" json = JSON.parse(RestClient.get(url)) recs += json['SEGMENTS']['JAGROOT']['RESULT']['DOCSET']['DOC'] sleep 1 # respect the server and avoid flood-blocking end recs.each do |r| begin deets = r['PrimoNMBib']['record']['display'] p = Publication.new(ctx) p.title = deets['title'] p.author_line = deets['creator'] p.language = deets['language'] p.notes = "#{deets['format']}\n#{deets['subject']}" p.publisher_line = deets['publisher'] p.pub_year = deets['creationdate'] p.source_id = r['PrimoNMBib']['record']['control']['sourcerecordid'] # collect additional URLS from record, for clients to be able to determine whether a scanned object exists additional_urls = [] deets.keys.each do |key| additional_urls << deets[key] if deets[key] =~ /https?:[^\s]/ end p.additional_urls = additional_urls if additional_urls.length > 0 h = Holding.new h.source_id = p.source_id h.source_name = 'Primo:'+@options[:institution] h.location = r['LIBRARIES']['LIBRARY'][0].nil? ? r['LIBRARIES']['LIBRARY']['callNumber'] : r['LIBRARIES']['LIBRARY'][0]['callNumber'] # there seem to be two cases, different between NLI and TAU, for example p.add_holding(h) ret << p rescue Exception puts $! end end rescue Exception puts $! end return ret end