Class: Gared::Primo
- Inherits:
-
Object
- Object
- Gared::Primo
- Defined in:
- lib/gared/primo.rb
Instance Method Summary collapse
-
#initialize(url, institution) ⇒ Primo
constructor
A new instance of Primo.
- #query_person(person) ⇒ Object
- #query_persons(q) ⇒ Object
- #query_publication(publication) ⇒ Object
- #query_publications(q) ⇒ Object
-
#query_publications_by_person(person, ctx = nil) ⇒ Object
return in-memory Publication instances with associated Holdings.
Constructor Details
#initialize(url, institution) ⇒ Primo
Returns a new instance of Primo.
6 7 8 |
# File 'lib/gared/primo.rb', line 6 def initialize(url, institution) = {url: url, institution: institution} end |
Instance Method Details
#query_person(person) ⇒ Object
13 14 |
# File 'lib/gared/primo.rb', line 13 def query_person(person) end |
#query_persons(q) ⇒ Object
10 11 |
# File 'lib/gared/primo.rb', line 10 def query_persons(q) end |
#query_publication(publication) ⇒ Object
19 20 |
# File 'lib/gared/primo.rb', line 19 def query_publication(publication) end |
#query_publications(q) ⇒ Object
16 17 |
# File 'lib/gared/primo.rb', line 16 def query_publications(q) end |
#query_publications_by_person(person, ctx = nil) ⇒ Object
return in-memory Publication instances with associated Holdings
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/gared/primo.rb', line 23 def query_publications_by_person(person, ctx = nil) ret = [] begin url = [: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 = [: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. = 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'] # TODO: determine whether a scanned object exists h = Holding.new h.source_id = p.source_id h.source_name = 'Primo:'+[:institution] p.add_holding(h) ret << p rescue Exception puts $! end end rescue Exception puts $! end return ret end |