Class: Gared::Primo
- Inherits:
-
Object
- Object
- Gared::Primo
- Defined in:
- lib/gared/primo.rb
Instance Method Summary collapse
-
#initialize(url, vid, scope, apikey) ⇒ 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.
- #uri_escape(s) ⇒ Object
Constructor Details
#initialize(url, vid, scope, apikey) ⇒ Primo
Returns a new instance of Primo.
6 7 8 |
# File 'lib/gared/primo.rb', line 6 def initialize(url, vid, scope, apikey) @options = {url: url, vid: vid, scope: scope, apikey: apikey} end |
Instance Method Details
#query_person(person) ⇒ Object
17 18 |
# File 'lib/gared/primo.rb', line 17 def query_person(person) end |
#query_persons(q) ⇒ Object
14 15 |
# File 'lib/gared/primo.rb', line 14 def query_persons(q) end |
#query_publication(publication) ⇒ Object
23 24 |
# File 'lib/gared/primo.rb', line 23 def query_publication(publication) end |
#query_publications(q) ⇒ Object
20 21 |
# File 'lib/gared/primo.rb', line 20 def query_publications(q) end |
#query_publications_by_person(person, ctx = nil) ⇒ Object
return in-memory Publication instances with associated Holdings
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/gared/primo.rb', line 27 def query_publications_by_person(person, ctx = nil) ret = [] begin base_url = "#{@options[:url]}?vid=#{@options[:vid]}&scope=#{@options[:scope]}&q=creator,contains,#{uri_escape(person)}&qInclude=facet_rtype,exact,books&apikey=#{@options[:apikey]}&limit=50" json = JSON.parse(RestClient.get(base_url)) total = json['info']['total'].to_i start_at = 0 recs = json['docs'] # stash the records while recs.length < total start_at += 50 url = base_url+"&offset=#{start_at}" json = JSON.parse(RestClient.get(url)) recs += json['docs'] sleep 0.5 # respect the server and avoid flood-blocking end recs.each do |r| begin deets = r['pnx']['display'] # the fields inside are now always an array! p = Publication.new(ctx) p.title = deets['title'].join('; ') p. = deets['creator'].join('; ') p. += deets['contributor'].join('; ') if deets['contributor'] p.language = deets['language'].join('; ') p.notes = deets['format'].join('; ') if r['pnx']['display'] && r['pnx']['display']['subject'] p.notes += r['pnx']['display']['subject'].join('; ') elsif r['pnx']['search'] && r['pnx']['search']['subject'] p.notes += r['pnx']['search']['subject'].join('; ') end p.publisher_line = deets['publisher'].join('; ') p.pub_year = deets['creationdate'].join('; ') p.source_id = r['pnx']['control']['sourcerecordid'].join('; ') ## collect additional URLS from record, for clients to be able to determine whether a scanned object exists # commented out for now, as it needs to be rewritten for the new Primo output structure #additional_urls = [] #deets.keys.each do |key| # if deets[key].class == Array # deets[key].each do |kkey| # additional_urls << kkey if kkey.class == String && kkey =~ /https?:[^\s]/ # end # elsif deets[key].class == String # additional_urls << deets[key] if deets[key] =~ /https?:[^\s]/ # end #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[:vid] begin h.location = r['pnx']['search']['callnumber'].join('; ') # Haifa University style rescue Exception # We're skipping things without a callnumber, as they are not resources within the library itself. puts $! end if h.location.nil? begin h.location = r['delivery']['bestlocation']['callNumber'] # Tel Aviv University style rescue Exception puts $! end end p.add_holding(h) ret << p rescue Exception puts $! end end rescue Exception puts $! end return ret end |
#uri_escape(s) ⇒ Object
9 10 11 12 |
# File 'lib/gared/primo.rb', line 9 def uri_escape(s) p = URI::Parser.new return p.escape(s) end |